From b6708302856a1ddef4d439252c1e443d694893d7 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Fri, 26 Mar 2021 17:35:57 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20List/table=20parsing?= =?UTF-8?q?=20ambiguity?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- markdown_it/rules_block/table.py | 26 +++++++++++++++++++++++--- tests/test_port/fixtures/tables.md | 13 +++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/markdown_it/rules_block/table.py b/markdown_it/rules_block/table.py index 0158c08b..a64f6848 100644 --- a/markdown_it/rules_block/table.py +++ b/markdown_it/rules_block/table.py @@ -71,11 +71,31 @@ 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 - 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: + + # if first character is '-', then second character must not be a space + # (due to parsing ambiguity with list) + if first_ch == 0x2D: + # not "|" and not "-" and not ":" + if second_ch != 0x7C and second_ch != 0x2D and second_ch != 0x3A: + return False + # "|" or ":" + elif first_ch == 0x7C or first_ch == 0x3A: + # not "|" and not "-" and not ":" and not space + if ( + second_ch != 0x7C + and second_ch != 0x2D + and second_ch != 0x3A + and not isSpace(second_ch) + ): + return False + else: return False while pos < state.eMarks[nextLine]: 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

+ +. From f95d45da29e4afb3a137870f37499a9018be2ce3 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Sat, 27 Mar 2021 00:45:34 +0200 Subject: [PATCH 2/5] Make the port readable --- markdown_it/rules_block/table.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/markdown_it/rules_block/table.py b/markdown_it/rules_block/table.py index a64f6848..9413818e 100644 --- a/markdown_it/rules_block/table.py +++ b/markdown_it/rules_block/table.py @@ -83,17 +83,12 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool): # (due to parsing ambiguity with list) if first_ch == 0x2D: # not "|" and not "-" and not ":" - if second_ch != 0x7C and second_ch != 0x2D and second_ch != 0x3A: + if second_ch not in {0x7C, 0x2D, 0x3A}: return False # "|" or ":" - elif first_ch == 0x7C or first_ch == 0x3A: + elif first_ch in {0x7C, 0x3A}: # not "|" and not "-" and not ":" and not space - if ( - second_ch != 0x7C - and second_ch != 0x2D - and second_ch != 0x3A - and not isSpace(second_ch) - ): + if second_ch not in {0x7C, 0x2D, 0x3A} and not isSpace(second_ch): return False else: return False @@ -102,7 +97,7 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool): 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 From 0d1a3024a1b662ba8b49bd4b765f262b38e9b1bb Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Sat, 27 Mar 2021 03:31:12 +0200 Subject: [PATCH 3/5] Sync with upstream PR --- markdown_it/rules_block/table.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/markdown_it/rules_block/table.py b/markdown_it/rules_block/table.py index 9413818e..8c2c5927 100644 --- a/markdown_it/rules_block/table.py +++ b/markdown_it/rules_block/table.py @@ -73,24 +73,20 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool): return False first_ch = state.srcCharCode[pos] pos += 1 + if first_ch not in {0x7C, 0x2D, 0x3A}: # not in {"|", "-", ":"} + return False if pos >= state.eMarks[nextLine]: return False second_ch = state.srcCharCode[pos] pos += 1 + # 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: - # not "|" and not "-" and not ":" - if second_ch not in {0x7C, 0x2D, 0x3A}: - return False - # "|" or ":" - elif first_ch in {0x7C, 0x3A}: - # not "|" and not "-" and not ":" and not space - if second_ch not in {0x7C, 0x2D, 0x3A} and not isSpace(second_ch): - return False - else: + if first_ch == 0x2D and isSpace(second_ch): return False while pos < state.eMarks[nextLine]: From 1a623a743d52d4e28ad03a7349dd44394175dbf3 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Sat, 27 Mar 2021 13:04:00 +0200 Subject: [PATCH 4/5] Update a comment to sync with upstream --- markdown_it/token.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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) From f5ecc9d945c2493d93e8573dcd4ad732bfaf9664 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Sat, 27 Mar 2021 13:07:08 +0200 Subject: [PATCH 5/5] Update port.yaml --- markdown_it/port.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/markdown_it/port.yaml b/markdown_it/port.yaml index dd18647e..7309bd8e 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`