Skip to content

Commit ed48ece

Browse files
authored
🐛 FIX: List/table parsing ambiguity (#149)
A list should take precedence in case of ambiguity Implements: markdown-it/markdown-it@cd5296f
1 parent 9ecda04 commit ed48ece

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

markdown_it/port.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
- package: markdown-it/markdown-it
22
version: 12.0.4
3-
commit: 7b8969ce5cb2edc54f2c1aa39a85a3a08076337d
4-
date: Dec 20, 2020
3+
commit: cd5296f1e7de2b978526178631859c18bb9d9928
4+
date: Mar 27, 2021
55
notes:
66
- Rename variables that use python built-in names, e.g.
77
- `max` -> `maximum`

markdown_it/rules_block/table.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,29 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool):
7171
pos = state.bMarks[nextLine] + state.tShift[nextLine]
7272
if pos >= state.eMarks[nextLine]:
7373
return False
74+
first_ch = state.srcCharCode[pos]
75+
pos += 1
76+
if first_ch not in {0x7C, 0x2D, 0x3A}: # not in {"|", "-", ":"}
77+
return False
7478

75-
ch = state.srcCharCode[pos]
79+
if pos >= state.eMarks[nextLine]:
80+
return False
81+
second_ch = state.srcCharCode[pos]
7682
pos += 1
77-
# /* | */ /* - */ /* : */
78-
if ch != 0x7C and ch != 0x2D and ch != 0x3A:
83+
# not in {"|", "-", ":"} and not space
84+
if second_ch not in {0x7C, 0x2D, 0x3A} and not isSpace(second_ch):
85+
return False
86+
87+
# if first character is '-', then second character must not be a space
88+
# (due to parsing ambiguity with list)
89+
if first_ch == 0x2D and isSpace(second_ch):
7990
return False
8091

8192
while pos < state.eMarks[nextLine]:
8293
ch = state.srcCharCode[pos]
8394

8495
# /* | */ /* - */ /* : */
85-
if ch != 0x7C and ch != 0x2D and ch != 0x3A and not isSpace(ch):
96+
if ch not in {0x7C, 0x2D, 0x3A} and not isSpace(ch):
8697
return False
8798

8899
pos += 1

markdown_it/token.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ class Token:
5252
content: str = attr.ib(default="")
5353
# '*' or '_' for emphasis, fence string for fence, etc.
5454
markup: str = attr.ib(default="")
55-
# fence info string
55+
# Additional information:
56+
# - Info string for "fence" tokens
57+
# - The value "auto" for autolink "link_open" and "link_close" tokens
5658
info: str = attr.ib(default="")
5759
# A place for plugins to store any arbitrary data
5860
meta: dict = attr.ib(factory=dict)

tests/test_port/fixtures/tables.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -881,3 +881,16 @@ GFM 4.10 Tables (extension), Example 205
881881
</thead>
882882
</table>
883883
.
884+
885+
A list takes precedence in case of ambiguity
886+
.
887+
a | b
888+
- | -
889+
1 | 2
890+
.
891+
<p>a | b</p>
892+
<ul>
893+
<li>| -
894+
1 | 2</li>
895+
</ul>
896+
.

0 commit comments

Comments
 (0)