Repository: jackdewinter/pymarkdown

Issue:
HTML: Generated code has item inside of list, not as indented code block.
Found by https://github.com/jackdewinter/pymarkdown/issues/261 :

```
expected_string(110)>><blockquote>
<blockquote>
<ul>
<li></li>
</ul>
</blockquote>
<pre><code>      item
</code></pre>
</blockquote><<

actual_string  (78)>><blockquote>
<blockquote>
<ul>
<li>item</li>
</ul>
</blockquote>
</blockquote><<
```

Tests:
- test_nested_three_block_max_block_max_unordered_max_empty_no_bq2
- test_nested_three_block_max_block_max_ordered_max_empty_no_bq2
- test_nested_three_block_max_ordered_max_block_max_empty_no_bq2
- test_nested_three_block_max_unordered_max_block_max_empty_no_bq2

Discussion:

Patch:
diff --git a/changelog.md b/changelog.md
index 93f4b5cd..9446dc5f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -41,6 +41,8 @@
   - parser: indent being processed twice
 - [Fixed - Issue 252](https://github.com/jackdewinter/pymarkdown/issues/252)
   - parser: in rare cases, was adding leading spaces to both list and paragraph within
+- [Fixed - Issue 262](https://github.com/jackdewinter/pymarkdown/issues/262)
+  - parser: when checking for block quote decrease, did not have empty scenarios checked for
 - [Fixed - Issue 263](https://github.com/jackdewinter/pymarkdown/issues/263)
   - parser: with empty list items, was creating 2 blank line tokens, plus extra list indent
 
diff --git a/publish/coverage.json b/publish/coverage.json
index e8f5a03d..b3189ca7 100644
--- a/publish/coverage.json
+++ b/publish/coverage.json
@@ -2,12 +2,12 @@
     "projectName": "pymarkdown",
     "reportSource": "pytest",
     "branchLevel": {
-        "totalMeasured": 3016,
-        "totalCovered": 3016
+        "totalMeasured": 3014,
+        "totalCovered": 3014
     },
     "lineLevel": {
-        "totalMeasured": 10526,
-        "totalCovered": 10526
+        "totalMeasured": 10522,
+        "totalCovered": 10522
     }
 }
 
diff --git a/pymarkdown/block_quote_processor.py b/pymarkdown/block_quote_processor.py
index 10829a91..9d6e6e24 100644
--- a/pymarkdown/block_quote_processor.py
+++ b/pymarkdown/block_quote_processor.py
@@ -1004,10 +1004,9 @@ class BlockQuoteProcessor:
         special_case = False
         if parser_state.block_copy and found_bq_stack_token:
             POGGER.debug("parser_state.block_copy>>search")
-            original_token = BlockQuoteProcessor.__find_original_token(
+            if original_token := BlockQuoteProcessor.__find_original_token(
                 parser_state, found_bq_stack_token
-            )
-            if original_token:
+            ):
                 POGGER.debug("original_token>>$", original_token)
                 POGGER.debug(
                     "original_token.leading_spaces>>:$:<<",
@@ -1299,11 +1298,10 @@ class BlockQuoteProcessor:
         last_bq_index,
     ):
         POGGER.debug("eligible")
-        remaining_text = parser_state.original_line_to_parse[
-            : -len(position_marker.text_to_parse)
-        ]
         stack_hard_limit, extra_consumed_whitespace = None, None
-        if remaining_text:
+        if remaining_text := parser_state.original_line_to_parse[
+            : -len(position_marker.text_to_parse)
+        ]:
             POGGER.debug("eligible - remaining_text:$:", remaining_text)
 
             # use up already extracted text/ws
@@ -1534,6 +1532,8 @@ class BlockQuoteProcessor:
             stack_decrease_needed = (
                 top_token_on_stack.is_indented_code_block
                 or top_token_on_stack.is_html_block
+                or top_token_on_stack.is_list
+                or top_token_on_stack.is_block_quote
             )
             POGGER.debug(
                 "__ensure_stack_at_level>>decrease to new level=$",
diff --git a/pymarkdown/container_block_processor.py b/pymarkdown/container_block_processor.py
index a5d5153c..54c23dec 100644
--- a/pymarkdown/container_block_processor.py
+++ b/pymarkdown/container_block_processor.py
@@ -2960,7 +2960,6 @@ class ContainerBlockProcessor:
         last_block_index,
         last_list_index,
         was_paragraph_continuation,
-        text_removed_by_container,
     ):
         real_stack_count = parser_state.count_of_block_quotes_on_stack()
         POGGER.debug("current_count>>:$:<", block_quote_data.current_count)
@@ -2993,13 +2992,6 @@ class ContainerBlockProcessor:
                 block_quote_data.current_count,
                 block_quote_data.stack_count - stack_delta,
             )
-
-            if new_last_block_index := parser_state.find_last_block_quote_on_stack():
-                parser_state.token_stack[
-                    new_last_block_index
-                ].matching_markdown_token.add_leading_spaces(
-                    text_removed_by_container, skip_adding_newline=False
-                )
         else:
             POGGER.debug("not special_block_quote_reduction")
             close_tokens = []
@@ -3070,7 +3062,6 @@ class ContainerBlockProcessor:
             last_block_index,
             last_list_index,
             was_paragraph_continuation,
-            text_removed_by_container,
         )
         if requeue_line_info:
             POGGER.debug("requeuing after __handle_special_block_quote_reduction")


Test patch:
diff --git a/publish/test-results.json b/publish/test-results.json
index 47770cf9..a089ec25 100644
--- a/publish/test-results.json
+++ b/publish/test-results.json
@@ -471,7 +471,7 @@
             "totalTests": 190,
             "failedTests": 0,
             "errorTests": 0,
-            "skippedTests": 2,
+            "skippedTests": 0,
             "elapsedTimeInMilliseconds": 0
         },
         {
@@ -479,7 +479,7 @@
             "totalTests": 101,
             "failedTests": 0,
             "errorTests": 0,
-            "skippedTests": 2,
+            "skippedTests": 1,
             "elapsedTimeInMilliseconds": 0
         },
         {
@@ -487,7 +487,7 @@
             "totalTests": 101,
             "failedTests": 0,
             "errorTests": 0,
-            "skippedTests": 2,
+            "skippedTests": 1,
             "elapsedTimeInMilliseconds": 0
         },
         {
diff --git a/test/test_markdown_nested_three_block_block.py b/test/test_markdown_nested_three_block_block.py
index 480a9513..5886ad92 100644
--- a/test/test_markdown_nested_three_block_block.py
+++ b/test/test_markdown_nested_three_block_block.py
@@ -3192,7 +3192,7 @@ def test_nested_three_block_nl_block_nl_block_no_bq5():
     expected_tokens = [
         "[block-quote(1,1)::>\n  > ]",
         "[BLANK(1,2):]",
-        "[block-quote(2,1)::> >\n  > ]",
+        "[block-quote(2,1)::> >]",
         "[BLANK(2,4):]",
         "[end-block-quote:::True]",
         "[para(3,7):  ]",
@@ -3237,7 +3237,7 @@ def test_nested_three_block_nl_block_nl_block_no_bq6():
     expected_tokens = [
         "[block-quote(1,1)::>\n> ]",
         "[BLANK(1,2):]",
-        "[block-quote(2,1)::> >\n> ]",
+        "[block-quote(2,1)::> >]",
         "[BLANK(2,4):]",
         "[end-block-quote:::True]",
         "[icode-block(3,7):    :]",
@@ -4658,7 +4658,6 @@ item</li>
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_nested_three_block_max_block_max_unordered_max_empty_no_bq2():
     """
     Verify that a nesting of block quote, block quote, unordered list, and
@@ -4671,15 +4670,15 @@ def test_nested_three_block_max_block_max_unordered_max_empty_no_bq2():
     source_markdown = """   >    >    +
    >           item"""
     expected_tokens = [
-        "[block-quote(1,4):   :   > ]",
-        "[block-quote(1,9)::   >    > \n   > ]",
-        "[ulist(1,14):+::15:   :          ]",
+        "[block-quote(1,4):   :   > \n   > ]",
+        "[block-quote(1,9)::   >    > ]",
+        "[ulist(1,14):+::15:   ]",
         "[BLANK(1,15):]",
-        "[para(2,16):]",
-        "[text(2,16):item:]",
-        "[end-para:::True]",
         "[end-ulist:::True]",
         "[end-block-quote:::True]",
+        "[icode-block(2,10):    :]",
+        "[text(2,10):item:      ]",
+        "[end-icode-block:::True]",
         "[end-block-quote:::True]",
     ]
     expected_gfm = """<blockquote>
@@ -4693,7 +4692,7 @@ def test_nested_three_block_max_block_max_unordered_max_empty_no_bq2():
 </blockquote>"""
 
     # 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
@@ -5298,7 +5297,6 @@ item</li>
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_nested_three_block_max_block_max_ordered_max_empty_no_bq2():
     """
     Verify that a nesting of block quote, block quote, ordered list, with
@@ -5310,15 +5308,15 @@ def test_nested_three_block_max_block_max_ordered_max_empty_no_bq2():
     source_markdown = """   >    >    1.
    >            item"""
     expected_tokens = [
-        "[block-quote(1,4):   :   > ]",
-        "[block-quote(1,9)::   >    > \n   > ]",
-        "[olist(1,14):.:1:16:   :           ]",
+        "[block-quote(1,4):   :   > \n   > ]",
+        "[block-quote(1,9)::   >    > ]",
+        "[olist(1,14):.:1:16:   ]",
         "[BLANK(1,16):]",
-        "[para(2,17):]",
-        "[text(2,17):item:]",
-        "[end-para:::True]",
         "[end-olist:::True]",
         "[end-block-quote:::True]",
+        "[icode-block(2,10):    :]",
+        "[text(2,10):item:       ]",
+        "[end-icode-block:::True]",
         "[end-block-quote:::True]",
     ]
     expected_gfm = """<blockquote>
@@ -5946,7 +5944,7 @@ def test_nested_three_block_max_block_max_block_max_empty_no_bq2():
     expected_tokens = [
         "[block-quote(1,4):   :   > \n   > ]",
         "[block-quote(1,9)::   >    > ]",
-        "[block-quote(1,14)::   >    >    >\n   > ]",
+        "[block-quote(1,14)::   >    >    >]",
         "[BLANK(1,15):]",
         "[end-block-quote:::True]",
         "[end-block-quote:::True]",
@@ -6088,7 +6086,7 @@ def test_nested_three_block_max_block_max_block_max_empty_no_bq4():
     expected_tokens = [
         "[block-quote(1,4):   :   > ]",
         "[block-quote(1,9)::   >    > \n   >    > ]",
-        "[block-quote(1,14)::   >    >    >\n   >    > ]",
+        "[block-quote(1,14)::   >    >    >]",
         "[BLANK(1,15):]",
         "[end-block-quote:::True]",
         "[icode-block(2,15):    :]",
@@ -6230,7 +6228,7 @@ def test_nested_three_block_max_block_max_block_max_empty_no_bq6():
     expected_tokens = [
         "[block-quote(1,4):   :   > \n   > ]",
         "[block-quote(1,9)::   >    > ]",
-        "[block-quote(1,14)::   >    >    >\n   > ]",
+        "[block-quote(1,14)::   >    >    >]",
         "[BLANK(1,15):]",
         "[end-block-quote:::True]",
         "[end-block-quote:::True]",
diff --git a/test/test_markdown_nested_three_block_ordered.py b/test/test_markdown_nested_three_block_ordered.py
index 7cbcf5ed..77fd5a0b 100644
--- a/test/test_markdown_nested_three_block_ordered.py
+++ b/test/test_markdown_nested_three_block_ordered.py
@@ -3376,7 +3376,6 @@ item</p>
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_nested_three_block_max_ordered_max_block_max_empty_no_bq2():
     """
     Verify that a nesting of block quote, ordered list, block quote, with
@@ -3388,15 +3387,14 @@ def test_nested_three_block_max_ordered_max_block_max_empty_no_bq2():
     source_markdown = """   >    1.    >
    >            item"""
     expected_tokens = [
-        "[block-quote(1,4):   :   > ]",
-        "[olist(1,9):.:1:14:   :\n]",
-        "[block-quote(1,15)::>\n   > ]",
-        "[BLANK(1,16):]",
+        "[block-quote(1,4):   :   > \n   > ]",
+        "[olist(1,9):.:1:14:   :         ]",
+        "[block-quote(1,15)::>]",
         "[BLANK(1,16):]",
-        "[icode-block(2,10):    :]",
-        "[text(2,10):item:       ]",
-        "[end-icode-block:::True]",
         "[end-block-quote:::True]",
+        "[para(2,17):  ]",
+        "[text(2,17):item:]",
+        "[end-para:::True]",
         "[end-olist:::True]",
         "[end-block-quote:::True]",
     ]
diff --git a/test/test_markdown_nested_three_block_unordered.py b/test/test_markdown_nested_three_block_unordered.py
index 95dbaafd..20c748d3 100644
--- a/test/test_markdown_nested_three_block_unordered.py
+++ b/test/test_markdown_nested_three_block_unordered.py
@@ -3376,7 +3376,6 @@ item</p>
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_nested_three_block_max_unordered_max_block_max_empty_no_bq2():
     """
     Verify that a nesting of block quote, unordered list, block quote, with
@@ -3388,15 +3387,14 @@ def test_nested_three_block_max_unordered_max_block_max_empty_no_bq2():
     source_markdown = """   >    +    >
    >           item"""
     expected_tokens = [
-        "[block-quote(1,4):   :   > ]",
-        "[ulist(1,9):+::13:   :\n]",
-        "[block-quote(1,14)::>\n   > ]",
-        "[BLANK(1,15):]",
+        "[block-quote(1,4):   :   > \n   > ]",
+        "[ulist(1,9):+::13:   :        ]",
+        "[block-quote(1,14)::>]",
         "[BLANK(1,15):]",
-        "[icode-block(2,10):    :]",
-        "[text(2,10):item:      ]",
-        "[end-icode-block:::True]",
         "[end-block-quote:::True]",
+        "[para(2,16):  ]",
+        "[text(2,16):item:]",
+        "[end-para:::True]",
         "[end-ulist:::True]",
         "[end-block-quote:::True]",
     ]