diff --git a/lib/renderer.js b/lib/renderer.js index f455195..b3877bb 100644 --- a/lib/renderer.js +++ b/lib/renderer.js @@ -17,6 +17,16 @@ function Renderer() { require('util').inherits(Renderer, kramedRenderer); +// Support To-Do List +Renderer.prototype.listitem = function(text) { + if (/^\s*\[[x ]\]\s*/.test(text)) { + text = text.replace(/^\s*\[ \]\s*/, ' ').replace(/^\s*\[x\]\s*/, ' '); + return '
  • ' + text + '
  • \n'; + } else { + return '
  • ' + text + '
  • \n'; + } + }; + // Add id attribute to headings Renderer.prototype.heading = function(text, level) { var id = anchorId(stripHTML(text)); diff --git a/test/index.js b/test/index.js index 1bf3551..fbb6901 100644 --- a/test/index.js +++ b/test/index.js @@ -59,3 +59,28 @@ describe('Kramed renderer', function() { result.should.eql('

    中文

    '); }); }); + + it('to-do list testing', function() { + var body = [ + '- [ ] test unchecked', + '- [x] test checked', + '- normal list [x] [ ]', + '', + 'normal text [x] [ ]', + '', + '[x] [ ] normal text' + ].join('\n'); + + var result = r({text: body}); + + result.should.eql([ + '', + '

    normal text [x] [ ]

    ', + '

    [x] [ ] normal text

    ' + ].join('\n') + '\n'); + }); +