Skip to content

Commit

Permalink
fix nested list items
Browse files Browse the repository at this point in the history
  • Loading branch information
rhysd committed Feb 27, 2018
1 parent ee15eef commit fcdb7f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
12 changes: 9 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,16 @@ _.extend(Renderer.prototype, rawRenderer.prototype, {
return line
})
var type = ordered ? '#' : '*'
return _.map(arr, function(line) {
return type + ' ' + line
return '\n' + _.map(arr, function(line) {
var bullet = type
if (!/^[*#]+ /.test(line)) {
// When the line starts with '# ' or '* ', it means that it is
// a nested list. '* * ' should be squashed to '** ' in the
// case.
bullet += ' '
}
return bullet + line;
}).join('\n') + '\n\n'

}
, listitem: function(body, ordered) {
return body + '\n'
Expand Down
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var pairs = [
['# h1', 'h1. h1\n\n']
, ['head1\n===', 'h1. head1\n\n']
, ['### h3', 'h3. h3\n\n']
, ['- item\n - nested', '\n* item\n** nested\n\n']
]

pairs.forEach(function(arr, i) {
Expand Down

0 comments on commit fcdb7f8

Please sign in to comment.