From 8f9eea13c17cbb6b642f2ee3c0d98cb25e0674a0 Mon Sep 17 00:00:00 2001 From: jackdewinter Date: Mon, 18 Nov 2024 20:51:46 -0800 Subject: [PATCH] issue 1263 (#1264) * https://github.com/jackdewinter/pymarkdown/issues/1263 --- newdocs/src/changelog.md | 3 + publish/coverage.json | 8 +- publish/test-results.json | 2 +- .../block_quotes/block_quote_count_helper.py | 16 +- .../container_block_leaf_processor.py | 10 +- ...eference_definition_continuation_helper.py | 4 +- .../list_blocks/list_block_pre_list_helper.py | 2 +- .../tokens/block_quote_markdown_token.py | 3 +- .../transform_containers.py | 11 +- test/test_markdown_extra.py | 214 +++++++++++++++++- 10 files changed, 243 insertions(+), 30 deletions(-) diff --git a/newdocs/src/changelog.md b/newdocs/src/changelog.md index 734228f84..fd0706885 100644 --- a/newdocs/src/changelog.md +++ b/newdocs/src/changelog.md @@ -14,6 +14,9 @@ - [Issue 1259](https://github.com/jackdewinter/pymarkdown/issues/1259) - Fixed asserts and bad parsing from cases where containers are added and then a "raw" blank line removes all containers +- [Issue 1263](https://github.com/jackdewinter/pymarkdown/issues/1263) + - Fixed issue where a new unordered list between two block quotes + was not being recognized properly. ### Changed diff --git a/publish/coverage.json b/publish/coverage.json index 3caf6b5c8..1ec9fe1cd 100644 --- a/publish/coverage.json +++ b/publish/coverage.json @@ -2,12 +2,12 @@ "projectName": "pymarkdown", "reportSource": "pytest", "branchLevel": { - "totalMeasured": 5463, - "totalCovered": 5463 + "totalMeasured": 5465, + "totalCovered": 5465 }, "lineLevel": { - "totalMeasured": 21304, - "totalCovered": 21304 + "totalMeasured": 21307, + "totalCovered": 21307 } } diff --git a/publish/test-results.json b/publish/test-results.json index ebafd8ad9..839b01d88 100644 --- a/publish/test-results.json +++ b/publish/test-results.json @@ -1620,7 +1620,7 @@ }, { "name": "test.test_markdown_extra", - "totalTests": 257, + "totalTests": 261, "failedTests": 0, "errorTests": 0, "skippedTests": 5, diff --git a/pymarkdown/block_quotes/block_quote_count_helper.py b/pymarkdown/block_quotes/block_quote_count_helper.py index 77568df7a..973106d42 100644 --- a/pymarkdown/block_quotes/block_quote_count_helper.py +++ b/pymarkdown/block_quotes/block_quote_count_helper.py @@ -389,8 +389,20 @@ def __is_special_double_block_case( BlockQuoteCountHelper.__block_quote_character, start_index ) POGGER.debug("+1>>next_bq_index:$:", next_bq_index) - if next_bq_index != -1 and (next_bq_index - start_index) <= 3: - continue_processing, start_index = True, next_bq_index + index_delta = next_bq_index - start_index + if next_bq_index != -1 and index_delta <= 3: + final_index, _ = ParserHelper.collect_while_spaces( + adjusted_line, start_index + ) + if final_index == next_bq_index: + continue_processing, start_index = True, next_bq_index + else: + cast( + BlockQuoteMarkdownToken, + parser_state.token_stack[ + final_stack_index + ].matching_markdown_token, + ).weird_kludge_seven = True return continue_processing, start_index @staticmethod diff --git a/pymarkdown/container_blocks/container_block_leaf_processor.py b/pymarkdown/container_blocks/container_block_leaf_processor.py index 7078c8ed6..da12282ce 100644 --- a/pymarkdown/container_blocks/container_block_leaf_processor.py +++ b/pymarkdown/container_blocks/container_block_leaf_processor.py @@ -580,11 +580,11 @@ def __adjust_for_list_container_after_block_quote_special_special( BlockQuoteMarkdownToken, parser_state.token_stack[bq_index].matching_markdown_token, ) - last_leading_space = xx_block_quote_token.remove_last_bleading_space() - assert ( - last_leading_space[0] == "\n" - ), "Removed leading space must start with \\n." - last_leading_space = last_leading_space[1:] + _ = xx_block_quote_token.remove_last_bleading_space() + # assert ( + # last_leading_space[0] == "\n" + # ), "Removed leading space must start with \\n." + # last_leading_space = last_leading_space[1:] POGGER.debug( "__adjust_for_list_container_after_block_quote_special_special>>block_token>>$", diff --git a/pymarkdown/links/link_reference_definition_continuation_helper.py b/pymarkdown/links/link_reference_definition_continuation_helper.py index 599d60c68..fbb448431 100644 --- a/pymarkdown/links/link_reference_definition_continuation_helper.py +++ b/pymarkdown/links/link_reference_definition_continuation_helper.py @@ -392,8 +392,8 @@ def __xx_multiple_fix_leading_spaces( for _ in link_def_token.continuation_lines: last_leading_space = block_quote_token.remove_last_bleading_space() POGGER.debug("last_leading_space>:$:<", last_leading_space) - if last_leading_space[0] == "\n": - last_leading_space = last_leading_space[1:] + # if last_leading_space[0] == "\n": + # last_leading_space = last_leading_space[1:] leading_spaces.append(last_leading_space) assert len(split_tabs_list) == len( leading_spaces diff --git a/pymarkdown/list_blocks/list_block_pre_list_helper.py b/pymarkdown/list_blocks/list_block_pre_list_helper.py index 7db74144c..755675e6c 100644 --- a/pymarkdown/list_blocks/list_block_pre_list_helper.py +++ b/pymarkdown/list_blocks/list_block_pre_list_helper.py @@ -351,7 +351,7 @@ def __handle_list_nesting_all_conditionals( current_last_block_token, ) current_last_block_token.add_bleading_spaces( - removed_leading_spaces, skip_adding_newline=True + removed_leading_spaces, skip_adding_newline=False ) POGGER.debug( "__handle_list_nesting_all_conditionals>>block_token>>$", diff --git a/pymarkdown/tokens/block_quote_markdown_token.py b/pymarkdown/tokens/block_quote_markdown_token.py index fd6397b94..6c7da7d51 100644 --- a/pymarkdown/tokens/block_quote_markdown_token.py +++ b/pymarkdown/tokens/block_quote_markdown_token.py @@ -52,6 +52,7 @@ def __init__( self.weird_kludge_four: Optional[Tuple[int, int, int, str]] = None self.weird_kludge_five = False self.weird_kludge_six = False + self.weird_kludge_seven = False # pylint: disable=protected-access @staticmethod @@ -135,7 +136,7 @@ def remove_last_bleading_space(self) -> str: self.__leading_spaces = "" self.weird_kludge_five = False else: - extracted_text = self.__leading_spaces[last_separator_index:] + extracted_text = self.__leading_spaces[last_separator_index + 1 :] self.__leading_spaces = self.__leading_spaces[:last_separator_index] self.leading_text_index -= 1 self.__compose_extra_data_field() diff --git a/pymarkdown/transform_markdown/transform_containers.py b/pymarkdown/transform_markdown/transform_containers.py index 2994b6c6f..afac927cd 100644 --- a/pymarkdown/transform_markdown/transform_containers.py +++ b/pymarkdown/transform_markdown/transform_containers.py @@ -1034,7 +1034,11 @@ def __adjust_state_for_element_inner_block_quote( ).weird_kludge_three and container_token_indices[current_block_quote_token_index] == 1 ): - container_token_indices[previous_block_quote_token_index] += 1 + previous_block_quote_token = cast( + BlockQuoteMarkdownToken, token_stack[previous_block_quote_token_index] + ) + if not previous_block_quote_token.weird_kludge_seven: + container_token_indices[previous_block_quote_token_index] += 1 elif ( previous_block_quote_token_index >= 0 and container_token_indices[current_block_quote_token_index] == 1 @@ -1398,7 +1402,6 @@ def __adjust_for_list_end_part_2( POGGER.debug( f"inner_token_index={inner_token_index} < len(split)={len(split_leading_spaces)}" ) - # following assert was if to return assert inner_token_index < len(split_leading_spaces) POGGER.debug( f" adj-->container_line>:{ParserHelper.make_value_visible(container_line)}:<" @@ -1994,9 +1997,7 @@ def __adjust( ) split_leading_spaces = leading_spaces.split(ParserHelper.newline_character) inner_token_index = container_token_indices[nested_list_start_index] - assert inner_token_index < len( - split_leading_spaces - ), "Index must be within the string." + assert inner_token_index < len(split_leading_spaces) POGGER.debug( f"inner_index->{str(container_token_indices[nested_list_start_index])}" ) diff --git a/test/test_markdown_extra.py b/test/test_markdown_extra.py index 96196b28b..afcfcf4b2 100644 --- a/test/test_markdown_extra.py +++ b/test/test_markdown_extra.py @@ -11410,7 +11410,6 @@ def test_extra_051caa(): @pytest.mark.gfm -@pytest.mark.skip def test_extra_051cbx(): """ TBD @@ -11431,12 +11430,19 @@ def test_extra_051cbx(): "[end-ulist:::True]", "[end-block-quote:::True]", "[BLANK(2,1):]", - "[block-quote(3,1)::> ]", - "[block-quote(3,5)::> > \n> + > \n]", - "[para(3,7):\n]", - "[text(3,7):fred2\nbarney::\n]", + "[block-quote(3,1)::> \n> ]", + "[block-quote(3,5)::> > ]", + "[para(3,7):]", + "[text(3,7):fred2:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[ulist(4,3):+::4:]", + "[block-quote(4,5)::> \n]", + "[para(4,7):]", + "[text(4,7):barney:]", "[end-para:::True]", "[end-block-quote:::True]", + "[end-ulist:::True]", "[end-block-quote:::True]", "[BLANK(5,1):]", ] @@ -11466,7 +11472,6 @@ def test_extra_051cbx(): @pytest.mark.gfm -@pytest.mark.skip def test_extra_051cba(): """ TBD @@ -11477,6 +11482,71 @@ def test_extra_051cba(): > > fred2 > + > barney +""" + expected_tokens = [ + "[block-quote(1,1)::> ]", + "[ulist(1,3):+::4:]", + "[block-quote(1,5)::> \n]", + "[para(1,7):]", + "[text(1,7):abc:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-ulist:::True]", + "[end-block-quote:::True]", + "[BLANK(2,1):]", + "[block-quote(3,1)::> \n> ]", + "[block-quote(3,5)::> > ]", + "[para(3,7):]", + "[text(3,7):fred2:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[ulist(4,3):+::4:]", + "[block-quote(4,5)::> \n]", + "[para(4,7):]", + "[text(4,7):barney:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-ulist:::True]", + "[end-block-quote:::True]", + "[BLANK(5,1):]", + ] + expected_gfm = """
+ +
+
+
+

fred2

+
+ +
""" + + # Act & Assert + act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=False) + + +@pytest.mark.gfm +def test_extra_051cbb(): + """ + TBD + """ + + # Arrange + source_markdown = """> + > abc + +> > fred2 +> + > barney """ expected_tokens = [ "[block-quote(1,1)::> ]", @@ -11490,11 +11560,18 @@ def test_extra_051cba(): "[end-block-quote:::True]", "[BLANK(2,1):]", "[block-quote(3,1)::> ]", - "[block-quote(3,5)::> > \n> + > \n]", - "[para(3,7):\n]", - "[text(3,7):fred2\nbarney::\n]", + "[block-quote(3,3)::> > ]", + "[para(3,5):]", + "[text(3,5):fred2:]", "[end-para:::True]", "[end-block-quote:::True]", + "[ulist(4,3):+::4:]", + "[block-quote(4,5)::> \n]", + "[para(4,7):]", + "[text(4,7):barney:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-ulist:::True]", "[end-block-quote:::True]", "[BLANK(5,1):]", ] @@ -11524,6 +11601,125 @@ def test_extra_051cba(): act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=False) +@pytest.mark.gfm +def test_extra_051cbc(): + """ + TBD + """ + + # Arrange + source_markdown = """> > fred2 +> + > barney +""" + expected_tokens = [ + "[block-quote(1,1)::> ]", + "[block-quote(1,3)::> > ]", + "[para(1,5):]", + "[text(1,5):fred2:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[ulist(2,3):+::4:]", + "[block-quote(2,5)::> \n]", + "[para(2,7):]", + "[text(2,7):barney:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-ulist:::True]", + "[end-block-quote:::True]", + "[BLANK(3,1):]", + ] + expected_gfm = """
+
+

fred2

+
+ +
""" + + # Act & Assert + act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=False) + + +@pytest.mark.gfm +def test_extra_051cbd(): + """ + TBD + """ + + # Arrange + source_markdown = """> > fred2 +> > barney +""" + expected_tokens = [ + "[block-quote(1,1)::]", + "[block-quote(1,3)::> > \n> > \n]", + "[para(1,5):\n]", + "[text(1,5):fred2\nbarney::\n]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-block-quote:::True]", + "[BLANK(3,1):]", + ] + expected_gfm = """
+
+

fred2 +barney

+
+
""" + + # Act & Assert + act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=False) + + +@pytest.mark.gfm +def test_extra_051cbe(): + """ + TBD + """ + + # Arrange + source_markdown = """> > fred2 +> + > barney +""" + expected_tokens = [ + "[block-quote(1,1)::> \n> ]", + "[block-quote(1,5)::> > ]", + "[para(1,7):]", + "[text(1,7):fred2:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[ulist(2,3):+::4:]", + "[block-quote(2,5)::> \n]", + "[para(2,7):]", + "[text(2,7):barney:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-ulist:::True]", + "[end-block-quote:::True]", + "[BLANK(3,1):]", + ] + expected_gfm = """
+
+

fred2

+
+ +
""" + + # Act & Assert + act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=False) + + @pytest.mark.gfm def test_extra_051ccx(): """