From fa1d3e3c338533e042c327e14d050c7a3a9a7a05 Mon Sep 17 00:00:00 2001 From: Taneli Hukkinen Date: Thu, 14 Jan 2021 18:51:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20port=20markdown-it=20v11.?= =?UTF-8?q?0.1=20(#109)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit updates the port to be up-to-date with markdown-it v11.0.1 (2020-09-14), applying two fixes: - Fix blockquote lazy newlines, [[#696](https://github.com/markdown-it/markdown-it/issues/696)]. - Fix missed mappings for table rows, [[#705](https://github.com/markdown-it/markdown-it/issues/705)]. --- markdown_it/main.py | 2 +- markdown_it/port.yaml | 4 +- markdown_it/rules_block/blockquote.py | 22 +++----- markdown_it/rules_block/table.py | 2 + markdown_it/rules_inline/balance_pairs.py | 2 +- tests/test_port/fixtures/commonmark_extras.md | 50 +++++++++++++++++++ 6 files changed, 62 insertions(+), 20 deletions(-) diff --git a/markdown_it/main.py b/markdown_it/main.py index 67c5c31c..58403aa4 100644 --- a/markdown_it/main.py +++ b/markdown_it/main.py @@ -225,7 +225,7 @@ def parse(self, src: str, env: Optional[AttrDict] = None) -> List[Token]: :param src: source string :param env: environment sandbox - Parse input string and returns list of block tokens (special token type + Parse input string and return list of block tokens (special token type "inline" will contain list of inline tokens). `env` is used to pass data between "distributed" rules and return additional diff --git a/markdown_it/port.yaml b/markdown_it/port.yaml index 84ec2f87..57338aea 100644 --- a/markdown_it/port.yaml +++ b/markdown_it/port.yaml @@ -1,6 +1,6 @@ - package: markdown-it/markdown-it - commit: f798bea9623277bbf89b9621cf7fb283c693fcab - date: Mar 12, 2020 + commit: 331ae117e09115366db12b517ca526b1b7fee1e8 + date: Sep 14, 2020 notes: - Rename variables that use python built-in names, e.g. - `max` -> `maximum` diff --git a/markdown_it/rules_block/blockquote.py b/markdown_it/rules_block/blockquote.py index 98fcdc1d..c3e2d5c2 100644 --- a/markdown_it/rules_block/blockquote.py +++ b/markdown_it/rules_block/blockquote.py @@ -32,12 +32,8 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool): if silent: return True - # skip spaces after ">" and re-calculate offset - initial = offset = ( - state.sCount[startLine] - + pos - - (state.bMarks[startLine] + state.tShift[startLine]) - ) + # set offset past spaces and ">" + initial = offset = state.sCount[startLine] + 1 try: second_char_code: Optional[int] = state.srcCharCode[pos] @@ -109,7 +105,6 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool): oldParentType = state.parentType state.parentType = "blockquote" - wasOutdented = False # Search the end of the block # @@ -142,8 +137,7 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool): # > current blockquote # 2. checking this line # ``` - if state.sCount[nextLine] < state.blkIndent: - wasOutdented = True + isOutdented = state.sCount[nextLine] < state.blkIndent pos = state.bMarks[nextLine] + state.tShift[nextLine] max = state.eMarks[nextLine] @@ -152,17 +146,13 @@ def blockquote(state: StateBlock, startLine: int, endLine: int, silent: bool): # Case 1: line is not inside the blockquote, and this line is empty. break - evaluatesTrue = state.srcCharCode[pos] == 0x3E and not wasOutdented # /* > */ + evaluatesTrue = state.srcCharCode[pos] == 0x3E and not isOutdented # /* > */ pos += 1 if evaluatesTrue: # This line is inside the blockquote. - # skip spaces after ">" and re-calculate offset - initial = offset = ( - state.sCount[nextLine] - + pos - - (state.bMarks[nextLine] + state.tShift[nextLine]) - ) + # set offset past spaces and ">" + initial = offset = state.sCount[nextLine] + 1 # skip one optional space after '>' if state.srcCharCode[pos] == 0x20: # /* space */ diff --git a/markdown_it/rules_block/table.py b/markdown_it/rules_block/table.py index 2152df71..0a8251bb 100644 --- a/markdown_it/rules_block/table.py +++ b/markdown_it/rules_block/table.py @@ -183,10 +183,12 @@ def table(state: StateBlock, startLine: int, endLine: int, silent: bool): token = state.push("tr_open", "tr", 1) for i in range(columnCount): token = state.push("td_open", "td", 1) + token.map = [nextLine, nextLine + 1] if aligns[i]: token.attrs = [["style", "text-align:" + aligns[i]]] token = state.push("inline", "", 0) + token.map = [nextLine, nextLine + 1] try: token.content = columns[i].strip() if columns[i] else "" except IndexError: diff --git a/markdown_it/rules_inline/balance_pairs.py b/markdown_it/rules_inline/balance_pairs.py index deff41e6..4198492b 100644 --- a/markdown_it/rules_inline/balance_pairs.py +++ b/markdown_it/rules_inline/balance_pairs.py @@ -42,7 +42,7 @@ def processDelimiters(state: StateInline, delimiters, *args): if newMinOpenerIdx == -1: newMinOpenerIdx = openerIdx - if opener.open and opener.end < 0 and opener.level == closer.level: + if opener.open and opener.end < 0: isOddMatch = False diff --git a/tests/test_port/fixtures/commonmark_extras.md b/tests/test_port/fixtures/commonmark_extras.md index 7bdd0b59..c7a48012 100644 --- a/tests/test_port/fixtures/commonmark_extras.md +++ b/tests/test_port/fixtures/commonmark_extras.md @@ -522,3 +522,53 @@ Coverage, entities with code > 10FFFF. Made this way for compatibility with comm

&#x1100000;

. + +Issue #696. Blockquotes should remember their level. +. +>>> foo +bar +>>> baz +. +
+
+
+

foo +bar +baz

+
+
+
+. + +Issue #696. Blockquotes should stop when outdented from a list. +. +1. >>> foo + bar +baz + >>> foo + >>> bar + >>> baz +. +
    +
  1. +
    +
    +
    +

    foo +bar +baz +foo

    +
    +
    +
    +
  2. +
+
+
+
+

bar +baz

+
+
+
+.