From 9d3f1bb66b32fe8cec2cf3c4dde0ac141400435b Mon Sep 17 00:00:00 2001 From: Jack De Winter Date: Mon, 5 Jul 2021 11:44:20 -0700 Subject: [PATCH] https://github.com/jackdewinter/pymarkdown/issues/13 : Further added variations on 237 and 238 with and without enough space to qualify. --- issues.md | 3 +- pymarkdown/container_block_processor.py | 66 ++++++++++++++++---- test/test_markdown_block_quotes.py | 8 ++- test/test_markdown_list_blocks.py | 80 +++++++++++++++++++++++++ 4 files changed, 143 insertions(+), 14 deletions(-) diff --git a/issues.md b/issues.md index ffa1ff49b..9fbf77a09 100644 --- a/issues.md +++ b/issues.md @@ -46,12 +46,11 @@ - same as these, but with an extra level of list or block if time 270, 271, 237, 238 -- with enough space -- with not enough space - with list item - start with blank - list starts after bq starts - varying spaces between bqs +- no space between bq and following list ## Priority 3 - Like To Solve in next 3 m diff --git a/pymarkdown/container_block_processor.py b/pymarkdown/container_block_processor.py index dd452762e..4927c213a 100644 --- a/pymarkdown/container_block_processor.py +++ b/pymarkdown/container_block_processor.py @@ -130,6 +130,8 @@ def parse_line_for_container_blocks( container_level_tokens.extend(leaf_tokens) return container_level_tokens, line_to_parse, None + POGGER.debug("this_bq_count>>$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) # POGGER.debug(">>avoid_block_starts>>$", avoid_block_starts) # POGGER.debug(">>did_process>>$", did_process) @@ -161,6 +163,8 @@ def parse_line_for_container_blocks( ">>requeuing lines after looking for ordered list start. returning." ) return None, None, requeue_line_info + POGGER.debug("this_bq_count>>$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) ( did_process, @@ -190,6 +194,8 @@ def parse_line_for_container_blocks( ">>requeuing lines after looking for unordered list start. returning." ) return None, None, requeue_line_info + POGGER.debug("this_bq_count>>$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) # POGGER.debug("last_block_quote_index>>$", last_block_quote_index) # POGGER.debug("indices>>$", end_container_indices) @@ -210,6 +216,8 @@ def parse_line_for_container_blocks( new_position_marker = PositionMarker( position_marker.line_number, start_index, line_to_parse ) + POGGER.debug("this_bq_count>>$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) ( line_to_parse, leaf_tokens, @@ -228,6 +236,8 @@ def parse_line_for_container_blocks( avoid_block_starts, ) # POGGER.debug_with_visible_whitespace("text>>$>>", line_to_parse) + POGGER.debug("this_bq_count>>$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) # POGGER.debug("olist->container_level_tokens->$", container_level_tokens) # POGGER.debug("removed_chars_at_start>>>$", removed_chars_at_start) @@ -237,10 +247,10 @@ def parse_line_for_container_blocks( POGGER.debug(">>>>>>>>$<<<<<<<<<<", line_to_parse) return container_level_tokens, line_to_parse, None - # POGGER.debug_with_visible_whitespace( - # ">>__process_list_in_progress>>$>>", - # line_to_parse, - # ) + POGGER.debug_with_visible_whitespace( + ">>__process_list_in_progress>>$>>", + line_to_parse, + ) ( did_process, line_to_parse, @@ -254,9 +264,12 @@ def parse_line_for_container_blocks( container_level_tokens, extracted_whitespace, ) - # POGGER.debug_with_visible_whitespace( - # ">>__process_list_in_progress>>$>>", line_to_parse - # ) + POGGER.debug_with_visible_whitespace( + ">>__process_list_in_progress>>$>>", line_to_parse + ) + POGGER.debug("container_start_bq_count>>$", container_start_bq_count) + POGGER.debug("this_bq_count>>$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) ContainerBlockProcessor.__process_lazy_lines( parser_state, leaf_tokens, @@ -264,9 +277,10 @@ def parse_line_for_container_blocks( stack_bq_count, line_to_parse, container_level_tokens, + container_start_bq_count, ) - # POGGER.debug_with_visible_whitespace("text>>$>>", line_to_parse) - # POGGER.debug("container_level_tokens>>$>>", container_level_tokens) + POGGER.debug_with_visible_whitespace("text>>$>>", line_to_parse) + POGGER.debug("container_level_tokens>>$>>", container_level_tokens) # TODO refactor to make indent unnecessary? calculated_indent = len(parser_state.original_line_to_parse) - len( @@ -352,6 +366,9 @@ def __get_block_start_index( stack_bq_count, container_start_bq_count, ) + POGGER.debug("container_start_bq_count>>:$", container_start_bq_count) + POGGER.debug("this_bq_count>>:$", this_bq_count) + POGGER.debug("stack_bq_count>>$", stack_bq_count) POGGER.debug("text>>:$:>>", line_to_parse) POGGER.debug(">>container_level_tokens>>$", container_level_tokens) return ( @@ -633,6 +650,7 @@ def __handle_nested_container_blocks( end_container_indices.block_index, ) delta = 0 + already_adjusted = False if ( end_container_indices.block_index != -1 and not nested_container_starts.ulist_index @@ -701,6 +719,7 @@ def __handle_nested_container_blocks( adjusted_indent_level, indent_level, ) + indent_was_adjusted = indent_level != adjusted_indent_level if indent_level > adjusted_indent_level: delta = indent_level - adjusted_indent_level indent_level = ( @@ -730,13 +749,36 @@ def __handle_nested_container_blocks( POGGER.debug("adj_line_to_parse>>$<<", adj_line_to_parse) adj_line_to_parse = adj_line_to_parse[delta:] POGGER.debug("adj_line_to_parse>>$<<", adj_line_to_parse) + elif ( + not nested_container_starts.block_index + and adj_line_to_parse + and adj_line_to_parse[0] == " " + and indent_was_adjusted + and parser_state.nested_list_start + ): + + POGGER.debug("adj_line_to_parse>:$:<", adj_line_to_parse) + POGGER.debug( + "parser_state.nested_list_start>:$:<", + parser_state.nested_list_start.matching_markdown_token, + ) + POGGER.debug("BOOM") + assert adj_line_to_parse.startswith( + parser_state.nested_list_start.matching_markdown_token.extracted_whitespace + ) + adj_line_to_parse = adj_line_to_parse[ + len( + parser_state.nested_list_start.matching_markdown_token.extracted_whitespace + ) : + ] + already_adjusted = True POGGER.debug( "check next container_start>mid>>stack_bq_count>>$<already adjusted<<$<<", adj_line_to_parse, @@ -938,6 +980,7 @@ def __process_lazy_lines( stack_bq_count, line_to_parse, container_level_tokens, + container_start_bq_count, ): POGGER.debug("LINE-lazy>$", line_to_parse) @@ -949,6 +992,9 @@ def __process_lazy_lines( line_to_parse, 0 ) remaining_line = line_to_parse[after_ws_index:] + POGGER.debug("container_start_bq_count>>:$", container_start_bq_count) + POGGER.debug("__process_lazy_lines>>this_bq_count>$<", this_bq_count) + POGGER.debug("__process_lazy_lines>>stack_bq_count>$<", stack_bq_count) POGGER.debug("__process_lazy_lines>>mod->ltp>$<", remaining_line) POGGER.debug("__process_lazy_lines>>mod->ews>$<", ex_whitespace) diff --git a/test/test_markdown_block_quotes.py b/test/test_markdown_block_quotes.py index aca1b8648..ef228b009 100644 --- a/test/test_markdown_block_quotes.py +++ b/test/test_markdown_block_quotes.py @@ -738,7 +738,7 @@ def test_block_quotes_213d(): """ # Act & Assert - act_and_assert(source_markdown, expected_gfm, expected_tokens) + act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=True) @pytest.mark.gfm @@ -2445,7 +2445,11 @@ def test_block_quotes_extra_02ae(): # Act & Assert act_and_assert( - source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True + source_markdown, + expected_gfm, + expected_tokens, + disable_consistency_checks=True, + show_debug=True, ) diff --git a/test/test_markdown_list_blocks.py b/test/test_markdown_list_blocks.py index 5423c57c6..556da3801 100644 --- a/test/test_markdown_list_blocks.py +++ b/test/test_markdown_list_blocks.py @@ -440,6 +440,44 @@ def test_list_blocks_237d(): act_and_assert(source_markdown, expected_gfm, expected_tokens) +@pytest.mark.gfm +def test_list_blocks_237e(): + """ + Test case 237: 237 with not enough on final + """ + + # Arrange + source_markdown = """ > > 1. one +>> +>> two""" + expected_tokens = [ + "[block-quote(1,4): :]", + "[block-quote(1,6): : > > \n>>\n>> ]", + "[olist(1,8):.:1:11: ]", + "[para(1,12):]", + "[text(1,12):one:]", + "[end-para:::True]", + "[end-olist:::False]", + "[BLANK(2,3):]", + "[para(3,7): ]", + "[text(3,7):two:]", + "[end-para:::True]", + "[end-block-quote:::True]", + "[end-block-quote:::True]", + ] + expected_gfm = """
+
+
    +
  1. one
  2. +
+

two

+
+
""" + + # Act & Assert + act_and_assert(source_markdown, expected_gfm, expected_tokens) + + @pytest.mark.gfm def test_list_blocks_238(): """ @@ -478,6 +516,48 @@ def test_list_blocks_238(): act_and_assert(source_markdown, expected_gfm, expected_tokens) +@pytest.mark.gfm +def test_list_blocks_238a(): + """ + Test case 238: variant + """ + + # Arrange + source_markdown = """>>- one +>> + > > two""" + expected_tokens = [ + "[block-quote(1,1)::]", + "[block-quote(1,2)::>>\n>>\n > > ]", + "[ulist(1,3):-::4: ]", + "[para(1,5):]", + "[text(1,5):one:]", + "[end-para:::True]", + "[BLANK(2,3):]", + "[para(3,10):]", + "[text(3,10):two:]", + "[end-para:::True]", + "[end-ulist:::True]", + "[end-block-quote:::True]", + "[end-block-quote:::True]", + ] + expected_gfm = """
+
+
    +
  • +

    one

    +

    two

    +
  • +
+
+
""" + + # Act & Assert + act_and_assert( + source_markdown, expected_gfm, expected_tokens, disable_consistency_checks=True + ) + + @pytest.mark.gfm def test_list_blocks_239(): """