From ed48ece1c48eee03672cf72b2310de3802d58c0f Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Wed, 31 Mar 2021 08:02:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20List/table=20parsing=20am?= =?UTF-8?q?biguity=20(#149)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A list should take precedence in case of ambiguity Implements: https://github.com/markdown-it/markdown-it/commit/cd5296f1e7de2b978526178631859c18bb9d9928 --- markdown_it/port.yaml | 4 ++-- markdown_it/rules_block/table.py | 19 +++++++++++++++---- markdown_it/token.py | 4 +++- tests/test_port/fixtures/tables.md | 13 +++++++++++++ 4 files changed, 33 insertions(+), 7 deletions(-) diff --git a/markdown_it/port.yaml b/markdown_it/port.yaml index b0a63e61..565f0143 100644 --- a/markdown_it/port.yaml +++ b/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` diff --git a/markdown_it/rules_block/table.py b/markdown_it/rules_block/table.py index 0158c08b..8c2c5927 100644 --- a/markdown_it/rules_block/table.py +++ b/markdown_it/rules_block/table.py @@ -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 diff --git a/markdown_it/token.py b/markdown_it/token.py index bcbf30cd..36646e07 100644 --- a/markdown_it/token.py +++ b/markdown_it/token.py @@ -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) diff --git a/tests/test_port/fixtures/tables.md b/tests/test_port/fixtures/tables.md index 7539ffb5..cf83708b 100644 --- a/tests/test_port/fixtures/tables.md +++ b/tests/test_port/fixtures/tables.md @@ -881,3 +881,16 @@ GFM 4.10 Tables (extension), Example 205 . + +A list takes precedence in case of ambiguity +. +a | b +- | - +1 | 2 +. +

a | b

+ +.