diff --git a/lib/marked.js b/lib/marked.js index aa6deb21a6..b39e6e0d38 100644 --- a/lib/marked.js +++ b/lib/marked.js @@ -149,6 +149,7 @@ Lexer.prototype.token = function(src, top) { , bull , b , item + , gtr = this.options.gfm && this.options.gfmTodoRule , space , i , l; @@ -332,6 +333,14 @@ Lexer.prototype.token = function(src, top) { : 'list_item_start' }); + if (gtr && (b = gtr.exec(item))) { + this.tokens.push({ + type: 'text', + text: b[0] + }); + + item = item.substring(b[0].length); + } // Recurse. this.token(item, false); @@ -948,6 +957,17 @@ Parser.prototype.tok = function() { } case 'list_item_start': { var body = ''; + var gtr = this.options.gfm && this.options.gfmTodoRule; + var peek, + m; + + if (gtr && (peek = this.peek()) && peek.type === 'text') { + if ((m = gtr.exec(peek.text)) && m[0].length === peek.text.length) { + this.next(); + body += ' ' + } + } while (this.next().type !== 'list_item_end') { body += this.token.type === 'text' @@ -1127,6 +1147,7 @@ marked.setOptions = function(opt) { marked.defaults = { gfm: true, + gfmTodoRule: /^\[([- ovx*+%#@~?])\] +/, tables: true, breaks: false, pedantic: false, diff --git a/test/tests/gfm_todo_list.html b/test/tests/gfm_todo_list.html new file mode 100644 index 0000000000..c2096d3c88 --- /dev/null +++ b/test/tests/gfm_todo_list.html @@ -0,0 +1,5 @@ + diff --git a/test/tests/gfm_todo_list.text b/test/tests/gfm_todo_list.text new file mode 100644 index 0000000000..c3bb1a22bc --- /dev/null +++ b/test/tests/gfm_todo_list.text @@ -0,0 +1,3 @@ +* [ ] abc + [ ] bcd +* [x] cde