Skip to content

Commit 465641d

Browse files
committed
fix nested list items
1 parent ee15eef commit 465641d

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,16 @@ _.extend(Renderer.prototype, rawRenderer.prototype, {
6868
return line
6969
})
7070
var type = ordered ? '#' : '*'
71-
return _.map(arr, function(line) {
72-
return type + ' ' + line
71+
return '\n' + _.map(arr, function(line) {
72+
var bullet = type
73+
if (!/^[*#]+ /.test(line)) {
74+
// When already the line starteds with '# ' or '* ', it means
75+
// that the line is a nested list. '* * ' should be squashed to
76+
// '** ' in the case.
77+
bullet += ' '
78+
}
79+
return bullet + line;
7380
}).join('\n') + '\n\n'
74-
7581
}
7682
, listitem: function(body, ordered) {
7783
return body + '\n'

test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var pairs = [
55
['# h1', 'h1. h1\n\n']
66
, ['head1\n===', 'h1. head1\n\n']
77
, ['### h3', 'h3. h3\n\n']
8+
, ['- item\n - nested', '\n* item\n** nested\n\n']
89
]
910

1011
pairs.forEach(function(arr, i) {

0 commit comments

Comments
 (0)