diff --git a/index.js b/index.js index d19a388..6af4765 100644 --- a/index.js +++ b/index.js @@ -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' diff --git a/test.js b/test.js index 876f921..9da9696 100644 --- a/test.js +++ b/test.js @@ -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) {