diff --git a/lib/marked.js b/lib/marked.js index 2b40cfaf41..a88b7d2dbe 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -195,7 +195,9 @@ Lexer.prototype.token = function(src, top) { i, tag, l, - isordered; + isordered, + istask, + ischecked; while (src) { // newline @@ -363,10 +365,20 @@ Lexer.prototype.token = function(src, top) { if (!loose) loose = next; } + // Check for task list items + istask = /^\[[ xX]\] /.test(item); + ischecked = undefined; + if (istask) { + ischecked = item[1] !== ' '; + item = item.replace(/^\[[ xX]\] +/, ''); + } + this.tokens.push({ type: loose ? 'loose_item_start' - : 'list_item_start' + : 'list_item_start', + task: istask, + checked: ischecked }); // Recurse. @@ -927,6 +939,14 @@ Renderer.prototype.listitem = function(text) { return '
  • ' + text + '
  • \n'; }; +Renderer.prototype.checkbox = function(checked) { + return ' '; +} + Renderer.prototype.paragraph = function(text) { return '

    ' + text + '

    \n'; }; @@ -1198,6 +1218,10 @@ Parser.prototype.tok = function() { case 'list_item_start': { body = ''; + if (this.token.task) { + body += this.renderer.checkbox(this.token.checked); + } + while (this.next().type !== 'list_item_end') { body += this.token.type === 'text' ? this.parseText() diff --git a/test/specs/gfm/gfm-spec.js b/test/specs/gfm/gfm-spec.js index bf768bda8c..a8b43a2e2b 100644 --- a/test/specs/gfm/gfm-spec.js +++ b/test/specs/gfm/gfm-spec.js @@ -15,7 +15,7 @@ Messenger.prototype.test = function(spec, section, ignore) { var shouldFail = ~ignore.indexOf(spec.example); it('should ' + (shouldFail ? 'fail' : 'pass') + ' example ' + spec.example, function() { var expected = spec.html; - var actual = marked(spec.markdown, { headerIds: false, xhtml: true }); + var actual = marked(spec.markdown, { headerIds: false, xhtml: false }); since(messenger.message(spec, expected, actual)).expect( htmlDiffer.isEqual(expected, actual) ).toEqual(!shouldFail); @@ -42,7 +42,7 @@ describe('GFM 0.28 Tables', function() { describe('GFM 0.28 Task list items', function() { var section = 'Task list items'; - var shouldPassButFails = [272, 273]; + var shouldPassButFails = []; var willNotBeAttemptedByCoreTeam = [];