Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 FIX: List/table parsing ambiguity #149

Merged
merged 6 commits into from Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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>
.