Repository: jackdewinter/pymarkdown

Issue:
Indent Issue with Md031 fixed
## Prerequisites

* [X] Are you running the latest version of this application?
* [X] Have you checked the [Frequently Asked Questions](https://pymarkdown.readthedocs.io/en/latest/faq) document?
* [X] Have you simplified the bug report to the essential details?
  * [X] Do you have a distinct command line to report?
  * [X] Can you clearly state the configuration for this bug report?
  * [X] Do you have a minimal document that highlights this bug?
  * [X] Are any required files (configuration or Markdown document) attached to the issue?
* [X] Did you perform a cursory search of other issues to look for related issues?

## Bug Report

### Bug Type

* [X] Fix/Rule not working as expected

### Description

Indent not correct, probably leading to extra > at end.

### Specifics

What operating system and version are you running into this behavior on?

Win11

What version are you seeing this behavior in? (Run `pip list` or `pipenv run pip list` and look for the entry beside `pymarkdownlnt`.)

latest, current

Are there any extra steps that need to be taken before executing the application?

No

What is the command line you invoke to get this behavior?

bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_block_with_thematics

Are you using a configuration file? Either on the command line or one of the implicit configuration files? If so, attach that file to this issue.

No

What Markdown document causes this behavior to manifest?  Attach that file to this issue.

```
> + > -----
>   > > block 1
>   > > block 2
>   > -----
>   > ```block
>   > A code block
>   > ```
>   > -----
> + another list
```

### Actual Behavior

Fixed to
```
> + > -----
>   > > block 1
>   > > block 2
>   > -----
>   >
>   >```block
>   > A code block
>   > ```
>   >
>   >-----
> + another list
>{space}
```

### Expected Behavior

Fixed document looks like:
```
> + > -----
>   > > block 1
>   > > block 2
>   > -----
>   >
>   > ```block
>   > A code block
>   > ```
>   >
>   > -----
> + another list
```

Discussion:
sourcery-ai[bot]: <!-- Generated by sourcery-ai[bot]: start review_guide -->

🧙 Sourcery is reviewing your pull request!

---

<details>
<summary>Tips</summary>

- Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request.
- Continue your discussion with Sourcery by replying directly to review comments.
- You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai):
    - Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
    - Change the review language;
- You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.

</details>

<!-- Generated by sourcery-ai[bot]: end review_guide -->
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/jackdewinter/pymarkdown/pull/1210?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
Attention: Patch coverage is `93.87755%` with `3 lines` in your changes missing coverage. Please review.
> Project coverage is 99.90%. Comparing base [(`11d4ff7`)](https://app.codecov.io/gh/jackdewinter/pymarkdown/commit/11d4ff7c378ea444513ac694ef503bc0940f3a15?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) to head [(`a02c013`)](https://app.codecov.io/gh/jackdewinter/pymarkdown/commit/a02c0131f52a6da0a94b1a80e60765db545d3d31?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).

| [Files with missing lines](https://app.codecov.io/gh/jackdewinter/pymarkdown/pull/1210?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) | Patch % | Lines |
|---|---|---|
| [pymarkdown/plugins/rule\_md\_031.py](https://app.codecov.io/gh/jackdewinter/pymarkdown/pull/1210?src=pr&el=tree&filepath=pymarkdown%2Fplugins%2Frule_md_031.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None#diff-cHltYXJrZG93bi9wbHVnaW5zL3J1bGVfbWRfMDMxLnB5) | 88.88% | [2 Missing and 1 partial :warning: ](https://app.codecov.io/gh/jackdewinter/pymarkdown/pull/1210?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) |

<details><summary>Additional details and impacted files</summary>


```diff
@@           Coverage Diff           @@
##             main    #1210   +/-   ##
=======================================
  Coverage   99.90%   99.90%           
=======================================
  Files         190      190           
  Lines       20843    20876   +33     
  Branches     2666     2674    +8     
=======================================
+ Hits        20823    20856   +33     
  Misses         13       13           
  Partials        7        7           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/jackdewinter/pymarkdown/pull/1210?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None).


Patch:
diff --git a/publish/coverage.json b/publish/coverage.json
index 4fe1e5f7..2accc051 100644
--- a/publish/coverage.json
+++ b/publish/coverage.json
@@ -2,12 +2,12 @@
     "projectName": "pymarkdown",
     "reportSource": "pytest",
     "branchLevel": {
-        "totalMeasured": 5333,
-        "totalCovered": 5326
+        "totalMeasured": 5349,
+        "totalCovered": 5342
     },
     "lineLevel": {
-        "totalMeasured": 20843,
-        "totalCovered": 20830
+        "totalMeasured": 20876,
+        "totalCovered": 20863
     }
 }
 
diff --git a/pymarkdown/block_quotes/block_quote_non_fenced_helper.py b/pymarkdown/block_quotes/block_quote_non_fenced_helper.py
index 869ae0c3..ca1cf00a 100644
--- a/pymarkdown/block_quotes/block_quote_non_fenced_helper.py
+++ b/pymarkdown/block_quotes/block_quote_non_fenced_helper.py
@@ -574,6 +574,10 @@ class BlockQuoteNonFencedHelper:
             adjusted_removed_text,
         )
 
+        if not block_quote_token.weird_kludge_five:
+            BlockQuoteNonFencedHelper.__do_block_quote_leading_spaces_adjustments_adjust_bleading_kludge(
+                parser_state, block_quote_token, stack_index, adjusted_removed_text
+            )
         POGGER.debug(
             "__do_block_quote_leading_spaces_adjustments_adjust_bleading>>block_token>>$",
             block_quote_token,
@@ -613,6 +617,42 @@ class BlockQuoteNonFencedHelper:
 
     # pylint: enable=too-many-arguments
 
+    @staticmethod
+    def __do_block_quote_leading_spaces_adjustments_adjust_bleading_kludge(
+        parser_state: ParserState,
+        block_quote_token: BlockQuoteMarkdownToken,
+        stack_index: int,
+        adjusted_removed_text: str,
+    ) -> None:
+
+        assert block_quote_token.leading_text_index == 0
+        search_index = stack_index - 1
+        while (
+            search_index > 0
+            and not parser_state.token_stack[search_index].is_block_quote
+        ):
+            search_index -= 1
+        if search_index and search_index + 1 == stack_index:
+            search_token = parser_state.token_stack[
+                search_index
+            ].matching_markdown_token
+            assert search_token is not None
+            if search_token.line_number != block_quote_token.line_number:
+                found_token = parser_state.token_stack[
+                    search_index
+                ].matching_markdown_token
+                assert found_token is not None
+                bq_token = cast(BlockQuoteMarkdownToken, found_token)
+                assert bq_token.bleading_spaces is not None
+                split_spaces = bq_token.bleading_spaces.split("\n")
+                if len(split_spaces) > 1:
+                    last_split_space = split_spaces[-1]
+                    if (
+                        adjusted_removed_text != last_split_space
+                        and adjusted_removed_text.startswith(last_split_space)
+                    ):
+                        block_quote_token.weird_kludge_six = True
+
     @staticmethod
     def __check_for_kludge(
         parser_state: ParserState,
diff --git a/pymarkdown/block_quotes/block_quote_processor.py b/pymarkdown/block_quotes/block_quote_processor.py
index cdd8b968..02ec1223 100644
--- a/pymarkdown/block_quotes/block_quote_processor.py
+++ b/pymarkdown/block_quotes/block_quote_processor.py
@@ -703,7 +703,9 @@ class BlockQuoteProcessor:
         assert character_after_block_quote == " ", "below covered in disabled test"
         # if character_after_block_quote == " ":
         last_block_quote_index += 1
-        # character_after_block_quote = parser_state.original_line_to_parse[last_block_quote_index]
+        #     character_after_block_quote = parser_state.original_line_to_parse[
+        #         last_block_quote_index
+        #     ]
 
         text_removed_by_container = parser_state.original_line_to_parse[
             :last_block_quote_index
diff --git a/pymarkdown/plugins/rule_md_031.py b/pymarkdown/plugins/rule_md_031.py
index b8c19468..60271c70 100644
--- a/pymarkdown/plugins/rule_md_031.py
+++ b/pymarkdown/plugins/rule_md_031.py
@@ -31,6 +31,7 @@ class ClosedContainerAdjustments:
 
     adjustment: int = 0
     count: int = 0
+    count2: int = 0
 
 
 @dataclass(frozen=True)
@@ -159,9 +160,14 @@ class RuleMd031(RulePlugin):
             token_line_number = setext_token.original_line_number
         else:
             token_line_number = token.line_number
+
         leading_space_insert_index = (
             token_line_number - block_quote_token.line_number
-        ) - self.__closed_container_adjustments[-1].adjustment
+        ) - (
+            self.__closed_container_adjustments[-1].adjustment
+            - self.__closed_container_adjustments[-1].count2
+        )
+
         former_item_leading_space = split_leading_space[
             leading_space_insert_index
         ].rstrip()
@@ -205,7 +211,7 @@ class RuleMd031(RulePlugin):
             container_index -= 1
         if container_index >= 0:
 
-            block_quote_index, index, ss = self.__xxxx(
+            block_quote_index, index, ss = self.__fix_spacing_list_prefix(
                 token, container_index, initial_index
             )
 
@@ -225,45 +231,53 @@ class RuleMd031(RulePlugin):
             and not self.__removed_container_token_stack.is_block_quote_start
             # and container_index
         ):
-            removed_list_token = cast(
-                ListStartMarkdownToken, self.__removed_container_token_stack
+            self.__fix_spacing_list_remove_list(context)
+        else:
+            self.__fix_spacing_list_not_remove_list(
+                initial_index, container_index, token
             )
-            assert removed_list_token.leading_spaces is not None
-            split_spaces = removed_list_token.leading_spaces.split("\n")
+
+    def __fix_spacing_list_remove_list(self, context: PluginScanContext) -> None:
+        removed_list_token = cast(
+            ListStartMarkdownToken, self.__removed_container_token_stack
+        )
+        assert removed_list_token.leading_spaces is not None
+        split_spaces = removed_list_token.leading_spaces.split("\n")
+        split_spaces_length = len(split_spaces)
+        if split_spaces_length > 1:
+            split_spaces.insert(split_spaces_length - 1, "")
+        else:
             split_spaces.append("")
-            self.register_fix_token_request(
-                context,
-                self.__removed_container_token_stack,
-                "next_token",
-                "leading_spaces",
-                "\n".join(split_spaces),
-            )
-            # xx = len(self.__closed_container_adjustments) - 1
-            # while xx >= 0 and not self.__container_token_stack[xx].is_list_start:
-            #     xx -= 1
-            # assert xx >= 0
-            # if xx > 0:
-            #     self.__closed_container_adjustments[xx].adjustment += 1
+        assert self.__removed_container_token_stack is not None
+        self.register_fix_token_request(
+            context,
+            self.__removed_container_token_stack,
+            "next_token",
+            "leading_spaces",
+            "\n".join(split_spaces),
+        )
+
+    def __fix_spacing_list_not_remove_list(
+        self, initial_index: int, container_index: int, token: MarkdownToken
+    ) -> None:
+        if self.__closed_container_adjustments[-1].adjustment:
+            adjust = 2 if container_index >= 0 else 1
         else:
-            if self.__closed_container_adjustments[-1].adjustment:
-                adjust = 1
-            else:
-                adjust = self.__calculate_adjust(initial_index, container_index)
-            if token.is_setext_heading:
-                setext_token = cast(SetextHeadingMarkdownToken, token)
-                token_line_number = setext_token.original_line_number
-            else:
-                token_line_number = token.line_number
-            index = (
-                token_line_number
-                - self.__container_token_stack[initial_index].line_number
-            )
-            index -= self.__closed_container_adjustments[-1].adjustment
-            self.__container_adjustments[initial_index].append(
-                PendingContainerAdjustment(index - adjust, "")
-            )
+            adjust = self.__calculate_adjust(initial_index, container_index)
+        if token.is_setext_heading:
+            setext_token = cast(SetextHeadingMarkdownToken, token)
+            token_line_number = setext_token.original_line_number
+        else:
+            token_line_number = token.line_number
+        index = (
+            token_line_number - self.__container_token_stack[initial_index].line_number
+        )
+        index -= self.__closed_container_adjustments[-1].adjustment
+        self.__container_adjustments[initial_index].append(
+            PendingContainerAdjustment(index - adjust, "")
+        )
 
-    def __xxxx(
+    def __fix_spacing_list_prefix(
         self,
         token: MarkdownToken,
         container_index: int,
@@ -522,6 +536,13 @@ class RuleMd031(RulePlugin):
                     stack_index
                 ].adjustment += line_number_delta
                 self.__closed_container_adjustments[stack_index].count += 1
+                if (
+                    self.__container_token_stack[-1].is_block_quote_start
+                    and cast(
+                        BlockQuoteMarkdownToken, self.__container_token_stack[-1]
+                    ).weird_kludge_six
+                ):
+                    self.__closed_container_adjustments[stack_index].count2 += 1
                 break
 
     def __process_pending_container_end_list(self, token: MarkdownToken) -> None:
diff --git a/pymarkdown/tokens/block_quote_markdown_token.py b/pymarkdown/tokens/block_quote_markdown_token.py
index e29bf405..fd6397b9 100644
--- a/pymarkdown/tokens/block_quote_markdown_token.py
+++ b/pymarkdown/tokens/block_quote_markdown_token.py
@@ -51,6 +51,7 @@ class BlockQuoteMarkdownToken(ContainerMarkdownToken):
         self.weird_kludge_three: bool = False
         self.weird_kludge_four: Optional[Tuple[int, int, int, str]] = None
         self.weird_kludge_five = False
+        self.weird_kludge_six = False
 
     # pylint: disable=protected-access
     @staticmethod


Test patch:
diff --git a/publish/test-results.json b/publish/test-results.json
index 688b4aa3..b13ac416 100644
--- a/publish/test-results.json
+++ b/publish/test-results.json
@@ -1300,10 +1300,10 @@
         },
         {
             "name": "test.rules.test_md027",
-            "totalTests": 115,
+            "totalTests": 117,
             "failedTests": 0,
             "errorTests": 0,
-            "skippedTests": 0,
+            "skippedTests": 1,
             "elapsedTimeInMilliseconds": 0
         },
         {
@@ -1364,10 +1364,10 @@
         },
         {
             "name": "test.rules.test_md031",
-            "totalTests": 286,
+            "totalTests": 288,
             "failedTests": 0,
             "errorTests": 0,
-            "skippedTests": 22,
+            "skippedTests": 9,
             "elapsedTimeInMilliseconds": 0
         },
         {
@@ -1620,7 +1620,7 @@
         },
         {
             "name": "test.test_markdown_extra",
-            "totalTests": 322,
+            "totalTests": 325,
             "failedTests": 0,
             "errorTests": 0,
             "skippedTests": 1,
diff --git a/test/rules/test_md027.py b/test/rules/test_md027.py
index 6ea83e14..8a032908 100644
--- a/test/rules/test_md027.py
+++ b/test/rules/test_md027.py
@@ -5,6 +5,7 @@ Module to provide tests related to the MD027 rule.
 import os
 from test.rules.utils import (
     calculate_fix_tests,
+    calculate_scan_tests,
     execute_fix_test,
     execute_query_configuration_test,
     execute_scan_test,
@@ -726,6 +727,43 @@ scanTests = [
         # use_debug=True,
         scan_expected_output="",
     ),
+    pluginRuleTest(
+        "md031_orig_bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_block_with_thematics",
+        source_file_contents="""> + > -----
+>   > > block 1
+>   > > block 2
+>   > -----
+>   > ```block
+>   > A code block
+>   > ```
+>   > -----
+> + another list
+""",
+        disable_rules="",
+        scan_expected_return_code=1,
+        # use_debug=True,
+        scan_expected_output="""{temp_source_path}:5:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
+{temp_source_path}:7:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)""",
+    ),
+    pluginRuleTest(  # https://github.com/jackdewinter/pymarkdown/issues/1209
+        "md031_final_bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_block_with_thematics",
+        source_file_contents="""> + > -----
+>   > > block 1
+>   > > block 2
+>   > -----
+>   >
+>   > ```block
+>   > A code block
+>   > ```
+>   >
+>   > -----
+> + another list""",
+        disable_rules="md047,md032",
+        scan_expected_return_code=0,
+        # use_debug=True,
+        mark_scan_as_skipped=True,
+        scan_expected_output="""""",
+    ),
     pluginRuleTest(
         "bad_fenced_block_in_list_in_block_quote_in_list_with_previous_block",
         source_file_contents="""1. > + ----
@@ -848,7 +886,9 @@ scanTests = [
 ]
 
 
-@pytest.mark.parametrize("test", scanTests, ids=id_test_plug_rule_fn)
+@pytest.mark.parametrize(
+    "test", calculate_scan_tests(scanTests), ids=id_test_plug_rule_fn
+)
 def test_md027_scan(test: pluginRuleTest) -> None:
     """
     Execute a parameterized scan test for plugin md001.
diff --git a/test/rules/test_md031.py b/test/rules/test_md031.py
index 475b9ffd..66948a67 100644
--- a/test/rules/test_md031.py
+++ b/test/rules/test_md031.py
@@ -17,6 +17,8 @@ from test.rules.utils import (
 
 import pytest
 
+temp_disable_fixes = True
+
 source_path = os.path.join("test", "resources", "rules", "md031") + os.sep
 
 configTests = [
@@ -1710,7 +1712,7 @@ A code block
 """,
         disable_rules="md032",
         use_debug=True,
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""> > + --------
 > >   > block 1
 > >   > block 2
@@ -1766,7 +1768,6 @@ A code block
 {temp_source_path}:7:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032,md035",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> > + ______
 > >   + list 1
 > >     list 2
@@ -1796,7 +1797,6 @@ A code block
 {temp_source_path}:8:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032,md035",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> > + ______
 > >   + list 1
 > >     list 2
@@ -2120,7 +2120,7 @@ A code block
 """,
         disable_rules="md032,md027",
         use_debug=True,
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""1. > + ----
    >   > block 1
    >   > block 2
@@ -2232,7 +2232,6 @@ A code block
 {temp_source_path}:7:8: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""1. > + ----
    >   + list 1
    >     list 2
@@ -2262,7 +2261,6 @@ A code block
 {temp_source_path}:8:8: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""1. > + ----
    >   + list 1
    >     list 2
@@ -2471,7 +2469,6 @@ A code block
 {temp_source_path}:4:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + list
 >
 >   ```block
@@ -2527,7 +2524,7 @@ A code block
 """,
         disable_rules="md032,md027",
         use_debug=True,
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""> + list 1
 >   > block 2
 >   > block 3
@@ -2678,7 +2675,6 @@ A code block
 {temp_source_path}:6:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + list 1
 >   + list 2
 >     list 3
@@ -2707,7 +2703,7 @@ A code block
 {temp_source_path}:7:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
+        # mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""> + list 1
 >   + list 2
 >     list 3
@@ -2779,7 +2775,7 @@ A code block
 > + another list
 """,
     ),
-    pluginRuleTest(  # test_extra_046e test_extra_046e1
+    pluginRuleTest(  # test_extra_046e0 test_extra_046e1
         "bad_fenced_block_in_list_in_block_quote_with_previous_inner_list_with_thematics_sub3",
         source_file_contents="""> + list 1
 >   + list 2
@@ -2796,8 +2792,6 @@ A code block
 {temp_source_path}:7:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        use_fix_debug=False,
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + list 1
 >   + list 2
 >   + list 3
@@ -2807,7 +2801,7 @@ A code block
 >   A code block
 >   ```
 >
->   ------
+>   _____
 > + another list
 """,
     ),
@@ -2827,7 +2821,6 @@ A code block
 {temp_source_path}:6:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + list 1
 >   + list 2
 >   list 3
@@ -2857,7 +2850,6 @@ A code block
 {temp_source_path}:7:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + list 1
 >   + list 2
 >   list 3
@@ -2917,8 +2909,8 @@ A code block
 > + another list
 """,
     ),
-    pluginRuleTest(  # test_extra_044mcz1 test_extra_046ca  BAR-B https://github.com/jackdewinter/pymarkdown/issues/1163
-        "bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_block",
+    pluginRuleTest(  # test_extra_044mcz1 test_extra_046ca
+        "bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_blockx",
         source_file_contents="""> + > -----
 >   > > block 1
 >   > > block 2
@@ -2933,8 +2925,6 @@ A code block
 {temp_source_path}:6:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        use_debug=True,
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + > -----
 >   > > block 1
 >   > > block 2
@@ -2947,7 +2937,44 @@ A code block
 > + another list
 """,
     ),
-    pluginRuleTest(  # test_extra_044mcv0 test_extra_044mcv1   also check with md027 enabled https://github.com/jackdewinter/pymarkdown/issues/1162
+    pluginRuleTest(  # test_extra_047d0
+        "bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_blocks",
+        source_file_contents="""> + > -----
+>   > > block 1
+>   > > block 2
+>   > -----
+>   > > block 1
+>   > > block 2
+>   > ```block
+>   > A code block
+>   > ```
+>   > -----
+> + another list
+""",
+        scan_expected_return_code=1,
+        scan_expected_output="""{temp_source_path}:7:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
+{temp_source_path}:9:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
+""",
+        disable_rules="md032",
+        # use_debug=True,
+        use_fix_debug=False,
+        mark_fix_as_skipped=temp_disable_fixes,
+        fix_expected_file_contents="""> + > -----
+>   > > block 1
+>   > > block 2
+>   > -----
+>   > > block 1
+>   > > block 2
+>   >
+>   > ```block
+>   > A code block
+>   > ```
+>   >
+>   > -----
+> + another list
+""",
+    ),
+    pluginRuleTest(  # test_extra_044mcv0 test_extra_044mcv1
         "bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_block_with_thematics",
         source_file_contents="""> + > -----
 >   > > block 1
@@ -2963,8 +2990,9 @@ A code block
         scan_expected_output="""{temp_source_path}:5:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 {temp_source_path}:7:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
-        disable_rules="md032",
-        mark_fix_as_skipped=True,
+        disable_rules="md032,md027",
+        # use_fix_debug=True,
+        # mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""> + > -----
 >   > > block 1
 >   > > block 2
@@ -3102,8 +3130,9 @@ A code block
 {temp_source_path}:6:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032,md027",
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         use_debug=True,
+        use_fix_debug=True,
         fix_expected_file_contents="""> + + -----
 >     > block 1
 >     > block 2
@@ -3164,7 +3193,6 @@ A code block
 {temp_source_path}:7:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         fix_expected_file_contents="""> + + -----
 >     + list 1
 >       list 2
@@ -3196,7 +3224,6 @@ A code block
 {temp_source_path}:8:7: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
         use_fix_debug=False,
         fix_expected_file_contents="""> + + -----
 >     + list 1
@@ -3351,8 +3378,9 @@ A code block
 {temp_source_path}:6:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        use_fix_debug=False,
-        mark_fix_as_skipped=True,
+        # use_fix_debug=True,
+        use_debug=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""+ + list 1
 + + + list 2.1
       list 2.2
@@ -3380,7 +3408,7 @@ A code block
 {temp_source_path}:7:5: MD031: Fenced code blocks should be surrounded by blank lines (blanks-around-fences)
 """,
         disable_rules="md032",
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""+ + list 1
 + + + list 2.1
       list 2.2
@@ -3409,8 +3437,7 @@ A code block
 """,
         disable_rules="md032",
         use_debug=True,
-        use_fix_debug=True,
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""+ + list 1
 + + + list 2.1
     list 2.2
@@ -3439,7 +3466,7 @@ A code block
 """,
         disable_rules="md032",
         use_debug=True,
-        mark_fix_as_skipped=True,
+        mark_fix_as_skipped=temp_disable_fixes,
         fix_expected_file_contents="""+ + list 1
 + + + list 2.1
     list 2.2
diff --git a/test/rules/utils.py b/test/rules/utils.py
index 35a7577b..7885cf88 100644
--- a/test/rules/utils.py
+++ b/test/rules/utils.py
@@ -49,6 +49,7 @@ class pluginRuleTest:
     fix_expected_error: str = ""
     add_plugin_path: str = ""
     is_mix_test: bool = True
+    mark_scan_as_skipped: bool = False
     mark_fix_as_skipped: bool = False
 
 
@@ -159,6 +160,13 @@ def execute_scan_test(test: pluginRuleTest, host_rule_id: str):
             assert_if_lists_different(disabled_rules, found_rules)
 
 
+def calculate_scan_tests(scanTests: List[pluginRuleTest]) -> List[pluginRuleTest]:
+    return [
+        (pytest.param(i, marks=pytest.mark.skip) if i.mark_scan_as_skipped else i)
+        for i in scanTests
+    ]
+
+
 def calculate_fix_tests(scanTests: List[pluginRuleTest]) -> List[pluginRuleTest]:
     return [
         (pytest.param(i, marks=pytest.mark.skip) if i.mark_fix_as_skipped else i)
diff --git a/test/test_markdown_extra.py b/test/test_markdown_extra.py
index 6d8a6404..7a042a4d 100644
--- a/test/test_markdown_extra.py
+++ b/test/test_markdown_extra.py
@@ -13238,7 +13238,7 @@ list 2</li>
 </blockquote>"""
 
     # Act & Assert
-    act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=True)
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
 
 
 @pytest.mark.gfm
@@ -13514,7 +13514,7 @@ list 2</li>
 </blockquote>"""
 
     # Act & Assert
-    act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=False)
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
 
 
 @pytest.mark.gfm
@@ -13712,7 +13712,7 @@ list 3</li>
 
 
 @pytest.mark.gfm
-def test_extra_046e():
+def test_extra_046e0():
     """
     TBD
     bad_fenced_block_in_list_in_block_quote_with_previous_inner_list_with_thematics_sub3
@@ -14203,7 +14203,7 @@ def test_extra_046g2():
 </blockquote>"""
 
     # Act & Assert
-    act_and_assert(source_markdown, expected_gfm, expected_tokens, show_debug=True)
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
 
 
 @pytest.mark.gfm
@@ -16259,6 +16259,221 @@ couple of lines</li>
     act_and_assert(source_markdown, expected_gfm, expected_tokens)
 
 
+@pytest.mark.gfm
+def test_extra_047d0():
+    """
+    TBD
+    bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_blocks
+    """
+
+    # Arrange
+    source_markdown = """> + > -----
+>   > > block 1
+>   > > block 2
+>   > -----
+>   > > block 1
+>   > > block 2
+>   > ```block
+>   > A code block
+>   > ```
+>   > -----
+> + another list
+"""
+    expected_tokens = [
+        "[block-quote(1,1)::> \n> ]",
+        "[ulist(1,3):+::4::\n\n\n\n\n\n\n\n\n]",
+        "[block-quote(1,5)::> \n>   > \n>   > \n>   > \n>   > \n>   > ]",
+        "[tbreak(1,7):-::-----]",
+        "[block-quote(2,7)::>   > > \n>   > > \n>   > ]",
+        "[para(2,9):\n]",
+        "[text(2,9):block 1\nblock 2::\n]",
+        "[end-para:::False]",
+        "[end-block-quote::>   > :True]",
+        "[tbreak(4,7):-::-----]",
+        "[block-quote(5,7)::>   > > \n>   > > \n>   > ]",
+        "[para(5,9):\n]",
+        "[text(5,9):block 1\nblock 2::\n]",
+        "[end-para:::False]",
+        "[end-block-quote::>   > :True]",
+        "[fcode-block(7,7):`:3:block:::::]",
+        "[text(8,7):A code block:]",
+        "[end-fcode-block:::3:False]",
+        "[tbreak(10,7):-::-----]",
+        "[end-block-quote:::True]",
+        "[li(11,3):4::]",
+        "[para(11,5):]",
+        "[text(11,5):another list:]",
+        "[end-para:::True]",
+        "[BLANK(12,1):]",
+        "[end-ulist:::True]",
+        "[end-block-quote:::True]",
+    ]
+    expected_gfm = """<blockquote>
+<ul>
+<li>
+<blockquote>
+<hr />
+<blockquote>
+<p>block 1
+block 2</p>
+</blockquote>
+<hr />
+<blockquote>
+<p>block 1
+block 2</p>
+</blockquote>
+<pre><code class="language-block">A code block
+</code></pre>
+<hr />
+</blockquote>
+</li>
+<li>another list</li>
+</ul>
+</blockquote>"""
+
+    # Act & Assert
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
+
+
+@pytest.mark.gfm
+def test_extra_047d1():
+    """
+    TBD
+    bad_fenced_block_in_block_quote_in_list_in_block_quote_with_previous_blocks
+    """
+
+    # Arrange
+    source_markdown = """> + > -----
+>   > > block 1
+>   > > block 2
+>   > -----
+>   > > block 1
+>   > > block 2
+>   >
+>   > ```block
+>   > A code block
+>   > ```
+>   >
+>   > -----
+> + another list
+"""
+    expected_tokens = [
+        "[block-quote(1,1)::> \n> ]",
+        "[ulist(1,3):+::4::\n\n\n\n\n\n\n\n\n\n\n]",
+        "[block-quote(1,5)::> \n>   > \n>   > \n>   > \n>   > \n>   >\n>   > ]",
+        "[tbreak(1,7):-::-----]",
+        "[block-quote(2,7)::>   > > \n>   > > \n>   > ]",
+        "[para(2,9):\n]",
+        "[text(2,9):block 1\nblock 2::\n]",
+        "[end-para:::False]",
+        "[end-block-quote::>   > :True]",
+        "[tbreak(4,7):-::-----]",
+        "[block-quote(5,7)::>   > > \n>   > > \n>   >\n>   > ]",
+        "[para(5,9):\n]",
+        "[text(5,9):block 1\nblock 2::\n]",
+        "[end-para:::True]",
+        "[BLANK(7,6):]",
+        "[end-block-quote:::True]",
+        "[fcode-block(8,7):`:3:block:::::]",
+        "[text(9,7):A code block:]",
+        "[end-fcode-block:::3:False]",
+        "[BLANK(11,6):]",
+        "[tbreak(12,7):-::-----]",
+        "[end-block-quote:::True]",
+        "[li(13,3):4::]",
+        "[para(13,5):]",
+        "[text(13,5):another list:]",
+        "[end-para:::True]",
+        "[BLANK(14,1):]",
+        "[end-ulist:::True]",
+        "[end-block-quote:::True]",
+    ]
+    expected_gfm = """<blockquote>
+<ul>
+<li>
+<blockquote>
+<hr />
+<blockquote>
+<p>block 1
+block 2</p>
+</blockquote>
+<hr />
+<blockquote>
+<p>block 1
+block 2</p>
+</blockquote>
+<pre><code class="language-block">A code block
+</code></pre>
+<hr />
+</blockquote>
+</li>
+<li>another list</li>
+</ul>
+</blockquote>"""
+
+    # Act & Assert
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
+
+
+@pytest.mark.gfm
+def test_extra_047e0():
+    """
+    TBD
+    bad_fenced_block_in_list_in_block_quote_in_block_quote_with_previous_block_with_thematics
+    """
+
+    # Arrange
+    source_markdown = """> > + --------
+> >   > block 1
+> >   > block 2
+> >   --------
+> >   ```block
+> >   A code block
+> >   ```
+> >   --------
+"""
+    expected_tokens = [
+        "[block-quote(1,1)::]",
+        "[block-quote(1,3)::> > \n> > \n> > \n> > \n> > \n> > ]",
+        "[ulist(1,5):+::6::\n\n  \u00fe\n  \n  \n  \n  \n]",
+        "[tbreak(1,7):-::--------]",
+        "[block-quote(2,7)::> \n> >   > \n> > ]",
+        "[para(2,9):\n]",
+        "[text(2,9):block 1\nblock 2::\n]",
+        "[end-para:::False]",
+        "[end-block-quote::> > :True]",
+        "[tbreak(4,7):-::--------]",
+        "[fcode-block(5,7):`:3:block:::::]",
+        "[text(6,1):A code block:]",
+        "[end-fcode-block:::3:False]",
+        "[tbreak(8,7):-::--------]",
+        "[BLANK(9,1):]",
+        "[end-ulist:::True]",
+        "[end-block-quote:::True]",
+        "[end-block-quote:::True]",
+    ]
+    expected_gfm = """<blockquote>
+<blockquote>
+<ul>
+<li>
+<hr />
+<blockquote>
+<p>block 1
+block 2</p>
+</blockquote>
+<hr />
+<pre><code class="language-block">A code block
+</code></pre>
+<hr />
+</li>
+</ul>
+</blockquote>
+</blockquote>"""
+
+    # Act & Assert
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
+
+
 @pytest.mark.gfm
 def test_extra_999():
     """