diff --git a/lib/renderer.js b/lib/renderer.js
index 0e184fc..9f66646 100644
--- a/lib/renderer.js
+++ b/lib/renderer.js
@@ -17,6 +17,16 @@ function Renderer() {
require('util').inherits(Renderer, MarkedRenderer);
+// 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 transformOption = this.options.modifyAnchors;
diff --git a/test/index.js b/test/index.js
index 48932dd..55a916e 100644
--- a/test/index.js
+++ b/test/index.js
@@ -59,6 +59,30 @@ describe('Marked 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');
+ });
+
describe('modifyAnchors option tests', function() {
var body = [
'- [Example](#example)',