Browse Source

Fix table/list parsing ambiguity

pull/767/head
Taneli Hukkinen 4 years ago
parent
commit
cf8de25218
  1. 20
      lib/rules_block/table.js
  2. 13
      test/fixtures/markdown-it/tables.txt

20
lib/rules_block/table.js

@ -52,7 +52,7 @@ function escapedSplit(str) {
module.exports = function table(state, startLine, endLine, silent) { module.exports = function table(state, startLine, endLine, silent) {
var ch, lineText, pos, i, l, nextLine, columns, columnCount, token, var ch, lineText, pos, i, l, nextLine, columns, columnCount, token,
aligns, t, tableLines, tbodyLines, oldParentType, terminate, aligns, t, tableLines, tbodyLines, oldParentType, terminate,
terminatorRules; terminatorRules, firstCh, secondCh;
// should have at least two lines // should have at least two lines
if (startLine + 2 > endLine) { return false; } if (startLine + 2 > endLine) { return false; }
@ -71,8 +71,22 @@ module.exports = function table(state, startLine, endLine, silent) {
pos = state.bMarks[nextLine] + state.tShift[nextLine]; pos = state.bMarks[nextLine] + state.tShift[nextLine];
if (pos >= state.eMarks[nextLine]) { return false; } if (pos >= state.eMarks[nextLine]) { return false; }
ch = state.src.charCodeAt(pos++); firstCh = state.src.charCodeAt(pos++);
if (ch !== 0x7C/* | */ && ch !== 0x2D/* - */ && ch !== 0x3A/* : */) { return false; }
if (pos >= state.eMarks[nextLine]) { return false; }
secondCh = state.src.charCodeAt(pos++);
// if first character is '-', then second character must not be a space
// (due to parsing ambiguity with list)
if (firstCh === 0x2D/* - */) {
if (secondCh !== 0x7C/* | */ && secondCh !== 0x2D/* - */ && secondCh !== 0x3A/* : */) { return false; }
} else if (firstCh === 0x7C/* | */ || firstCh === 0x3A/* : */) {
if (secondCh !== 0x7C/* | */ && secondCh !== 0x2D/* - */ && secondCh !== 0x3A/* : */ && !isSpace(secondCh)) {
return false;
}
} else {
return false;
}
while (pos < state.eMarks[nextLine]) { while (pos < state.eMarks[nextLine]) {
ch = state.src.charCodeAt(pos); ch = state.src.charCodeAt(pos);

13
test/fixtures/markdown-it/tables.txt

@ -793,3 +793,16 @@ GFM 4.10 Tables (extension), Example 205
</thead> </thead>
</table> </table>
. .
A list takes precedence in case of ambiguity
.
a | b
- | -
1 | 2
.
<p>a | b</p>
<ul>
<li>| -
1 | 2</li>
</ul>
.

Loading…
Cancel
Save