-
-
Notifications
You must be signed in to change notification settings - Fork 358
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse: fix parsing of non-empty blank lines
Closes GH-473. Closes GH-474. Reviewed-by: Victor Felder <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
- Loading branch information
Showing
7 changed files
with
94 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
'use strict' | ||
|
||
// A line containing no characters, or a line containing only spaces (U+0020) or tabs (U+0009), is called a blank line. | ||
// See https://spec.commonmark.org/0.29/#blank-line | ||
var reBlankLine = /^[\u0020\t]*(\n|$)/ | ||
|
||
// NOTE: Though blank lines play a special role in lists to determine whether the list is tight or loose (https://spec.commonmark.org/0.29/#blank-lines), | ||
// it's done by the list tokenizer and this blank-line tokenizer does not have to be responsible for that. | ||
// Therefore, configs such as `blankLine.notInList` do not have to be set here. | ||
module.exports = blankLine | ||
|
||
function blankLine(eat, value, silent) { | ||
var match | ||
var subvalue = '' | ||
var index = 0 | ||
var length = value.length | ||
|
||
while (index < length) { | ||
match = reBlankLine.exec(value.slice(index)) | ||
if (match == null) { | ||
break | ||
} | ||
|
||
index += match[0].length | ||
subvalue += match[0] | ||
} | ||
|
||
if (subvalue === '') { | ||
return | ||
} | ||
|
||
/* istanbul ignore if - never used (yet) */ | ||
if (silent) { | ||
return true | ||
} | ||
|
||
eat(subvalue) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
|
||
The previous line, which contains 2 spaces, should be considered to be empty. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
{ | ||
"type": "root", | ||
"children": [ | ||
{ | ||
"type": "paragraph", | ||
"children": [ | ||
{ | ||
"type": "text", | ||
"value": "The previous line, which contains 2 spaces, should be considered to be empty.", | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 1, | ||
"offset": 3 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 78, | ||
"offset": 80 | ||
}, | ||
"indent": [] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 2, | ||
"column": 1, | ||
"offset": 3 | ||
}, | ||
"end": { | ||
"line": 2, | ||
"column": 78, | ||
"offset": 80 | ||
}, | ||
"indent": [] | ||
} | ||
} | ||
], | ||
"position": { | ||
"start": { | ||
"line": 1, | ||
"column": 1, | ||
"offset": 0 | ||
}, | ||
"end": { | ||
"line": 3, | ||
"column": 1, | ||
"offset": 81 | ||
} | ||
} | ||
} |