Skip to content

Commit

Permalink
馃悰 FIX: List/table parsing ambiguity (#149)
Browse files Browse the repository at this point in the history
A list should take precedence in case of ambiguity

Implements: markdown-it/markdown-it@cd5296f
  • Loading branch information
hukkinj1 committed Mar 31, 2021
1 parent 9ecda04 commit ed48ece
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
4 changes: 2 additions & 2 deletions markdown_it/port.yaml
@@ -1,7 +1,7 @@
- package: markdown-it/markdown-it
version: 12.0.4
commit: 7b8969ce5cb2edc54f2c1aa39a85a3a08076337d
date: Dec 20, 2020
commit: cd5296f1e7de2b978526178631859c18bb9d9928
date: Mar 27, 2021
notes:
- Rename variables that use python built-in names, e.g.
- `max` -> `maximum`
Expand Down
19 changes: 15 additions & 4 deletions markdown_it/rules_block/table.py
Expand Up @@ -71,18 +71,29 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool):
pos = state.bMarks[nextLine] + state.tShift[nextLine]
if pos >= state.eMarks[nextLine]:
return False
first_ch = state.srcCharCode[pos]
pos += 1
if first_ch not in {0x7C, 0x2D, 0x3A}: # not in {"|", "-", ":"}
return False

ch = state.srcCharCode[pos]
if pos >= state.eMarks[nextLine]:
return False
second_ch = state.srcCharCode[pos]
pos += 1
# /* | */ /* - */ /* : */
if ch != 0x7C and ch != 0x2D and ch != 0x3A:
# not in {"|", "-", ":"} and not space
if second_ch not in {0x7C, 0x2D, 0x3A} and not isSpace(second_ch):
return False

# if first character is '-', then second character must not be a space
# (due to parsing ambiguity with list)
if first_ch == 0x2D and isSpace(second_ch):
return False

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

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

pos += 1
Expand Down
4 changes: 3 additions & 1 deletion markdown_it/token.py
Expand Up @@ -52,7 +52,9 @@ class Token:
content: str = attr.ib(default="")
# '*' or '_' for emphasis, fence string for fence, etc.
markup: str = attr.ib(default="")
# fence info string
# Additional information:
# - Info string for "fence" tokens
# - The value "auto" for autolink "link_open" and "link_close" tokens
info: str = attr.ib(default="")
# A place for plugins to store any arbitrary data
meta: dict = attr.ib(factory=dict)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_port/fixtures/tables.md
Expand Up @@ -881,3 +881,16 @@ GFM 4.10 Tables (extension), Example 205
</thead>
</table>
.

A list takes precedence in case of ambiguity
.
a | b
- | -
1 | 2
.
<p>a | b</p>
<ul>
<li>| -
1 | 2</li>
</ul>
.

0 comments on commit ed48ece

Please sign in to comment.