-
Notifications
You must be signed in to change notification settings - Fork 3.5k
loose lists #1304
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
loose lists #1304
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -191,6 +191,9 @@ Lexer.prototype.token = function(src, top) { | |
| bull, | ||
| b, | ||
| item, | ||
| listStart, | ||
| listItems, | ||
| t, | ||
| space, | ||
| i, | ||
| tag, | ||
|
|
@@ -316,15 +319,19 @@ Lexer.prototype.token = function(src, top) { | |
| bull = cap[2]; | ||
| isordered = bull.length > 1; | ||
|
|
||
| this.tokens.push({ | ||
| listStart = { | ||
| type: 'list_start', | ||
| ordered: isordered, | ||
| start: isordered ? +bull : '' | ||
| }); | ||
| start: isordered ? +bull : '', | ||
| loose: false | ||
| }; | ||
|
|
||
| this.tokens.push(listStart); | ||
|
|
||
| // Get each top-level item. | ||
| cap = cap[0].match(this.rules.item); | ||
|
|
||
| listItems = []; | ||
| next = false; | ||
| l = cap.length; | ||
| i = 0; | ||
|
|
@@ -365,6 +372,10 @@ Lexer.prototype.token = function(src, top) { | |
| if (!loose) loose = next; | ||
| } | ||
|
|
||
| if (loose) { | ||
| listStart.loose = true; | ||
| } | ||
|
|
||
| // Check for task list items | ||
| istask = /^\[[ xX]\] /.test(item); | ||
| ischecked = undefined; | ||
|
|
@@ -373,13 +384,15 @@ Lexer.prototype.token = function(src, top) { | |
| item = item.replace(/^\[[ xX]\] +/, ''); | ||
| } | ||
|
|
||
| this.tokens.push({ | ||
| type: loose | ||
| ? 'loose_item_start' | ||
| : 'list_item_start', | ||
| t = { | ||
| type: 'list_item_start', | ||
| task: istask, | ||
| checked: ischecked | ||
| }); | ||
| checked: ischecked, | ||
| loose: loose | ||
| }; | ||
|
|
||
| listItems.push(t); | ||
| this.tokens.push(t); | ||
|
|
||
| // Recurse. | ||
| this.token(item, false); | ||
|
|
@@ -389,6 +402,14 @@ Lexer.prototype.token = function(src, top) { | |
| }); | ||
| } | ||
|
|
||
| if (listStart.loose) { | ||
| l = listItems.length; | ||
| i = 0; | ||
| for (; i < l; i++) { | ||
| listItems[i].loose = true; | ||
| } | ||
| } | ||
|
|
||
| this.tokens.push({ | ||
| type: 'list_end' | ||
| }); | ||
|
|
@@ -1217,28 +1238,20 @@ Parser.prototype.tok = function() { | |
| } | ||
| case 'list_item_start': { | ||
| body = ''; | ||
| var loose = this.token.loose; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why you create a new var here instead of using
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. because
|
||
|
|
||
| if (this.token.task) { | ||
| body += this.renderer.checkbox(this.token.checked); | ||
| } | ||
|
|
||
| while (this.next().type !== 'list_item_end') { | ||
| body += this.token.type === 'text' | ||
| body += !loose && this.token.type === 'text' | ||
| ? this.parseText() | ||
| : this.tok(); | ||
| } | ||
|
|
||
| return this.renderer.listitem(body); | ||
| } | ||
| case 'loose_item_start': { | ||
| body = ''; | ||
|
|
||
| while (this.next().type !== 'list_item_end') { | ||
| body += this.tok(); | ||
| } | ||
|
|
||
| return this.renderer.listitem(body); | ||
| } | ||
| case 'html': { | ||
| // TODO parse inline content if parameter markdown=1 | ||
| return this.renderer.html(this.token.text); | ||
|
|
||
This file was deleted.
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this
ifstatement be removed in favor oflistStart.loose = looseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no because if
looseis false andlistStart.looseis true I don't want it to changelistStart.looseto false.listStart.looseis true if any oflistStartitems are loose