Repository: jackdewinter/pymarkdown

Issue:
Indent issue (test_extra_046l1)
## 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] Rehydration

### Description

problem with indent:
note: bad_fenced_block_in_list_in_block_quote_bare is blocked by this

### 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, main

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?

test_extra_046l1

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.

```
> + list
>
>   ```block
>   A code block
>   ```
>
> + another list```

### Actual Behavior

```
> + list
>
>   ```block
>   A code block
>   ```
>
> +  another list

```

### Expected Behavior

[Describe the behavior that you believe should occur instead of the Actual Behavior. Include any specifics on why that behavior is more correct.]


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/1196?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 99.92%. Comparing base [(`66bd165`)](https://app.codecov.io/gh/jackdewinter/pymarkdown/commit/66bd1659bdd4d155bb50711e59b53d90cc3d55ce?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=None) to head [(`03569a1`)](https://app.codecov.io/gh/jackdewinter/pymarkdown/commit/03569a1f27fea7f69ab8e7ce074b53d09288b196?dropdown=coverage&el=desc&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    #1196   +/-   ##
=======================================
  Coverage   99.92%   99.92%           
=======================================
  Files         190      190           
  Lines       20736    20742    +6     
  Branches     2648     2649    +1     
=======================================
+ Hits        20721    20727    +6     
  Misses         10       10           
  Partials        5        5           
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/jackdewinter/pymarkdown/pull/1196?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/Pipfile b/Pipfile
index f1502307..defa2e5a 100644
--- a/Pipfile
+++ b/Pipfile
@@ -30,7 +30,7 @@ pytest-html = "==4.1.1"
 pytest-xdist = "==3.6.1"
 setuptools = "==70.0.0"
 snakeviz = "==2.2.0"
-sourcery = "==1.12.0"
+sourcery = "==1.22.0"
 types-pyyaml = "*"
 
 [packages]
diff --git a/Pipfile.lock b/Pipfile.lock
index 92629900..396d6f1a 100644
--- a/Pipfile.lock
+++ b/Pipfile.lock
@@ -1,7 +1,7 @@
 {
     "_meta": {
         "hash": {
-            "sha256": "0aea4f287fe45553dd0cd77ae2956c2765b0e93e35ffdd2c70d6b115c7d129f5"
+            "sha256": "472a8d36dfd69c208eb6d3add00d44f63831d6072cae46479566b1ce9b77e6b3"
         },
         "pipfile-spec": 6,
         "requires": {
@@ -1349,12 +1349,12 @@
         },
         "sourcery": {
             "hashes": [
-                "sha256:2cd894548564a3ec2723fb6cc681f29c497c213cba6dcf20bdd9bd54105868df",
-                "sha256:819686fffdc102d0b5522f9eacda698374f66b6bf21f7422ff74148601e0b7bf",
-                "sha256:b3cea663a84b2c3007a05d72a2d13ff5d813cc695a5515c58dd16b6849ce9488"
+                "sha256:18f7d962d9820a8124aa928afb406d92565c2503ee86bac46e23bdd75b58272b",
+                "sha256:ac5d5db1eff47735a9b2328d5ae0bc444a84c96ffbc8a01f9ebe81f48b7bfaf8",
+                "sha256:c45d0e293a6b4f42b77c2dc9cd9184a0b76373a3234171956bd13f05aaed4298"
             ],
             "index": "pypi",
-            "version": "==1.12.0"
+            "version": "==1.22.0"
         },
         "stevedore": {
             "hashes": [
@@ -1438,11 +1438,11 @@
         },
         "virtualenv": {
             "hashes": [
-                "sha256:4c43a2a236279d9ea36a0d76f98d84bd6ca94ac4e0f4a3b9d46d05e10fea542a",
-                "sha256:8cc4a31139e796e9a7de2cd5cf2489de1217193116a8fd42328f1bd65f434589"
+                "sha256:48f2695d9809277003f30776d155615ffc11328e6a0a8c1f0ec80188d7874a55",
+                "sha256:c17f4e0f3e6036e9f26700446f85c76ab11df65ff6d8a9cbfad9f71aabfcf23c"
             ],
             "markers": "python_version >= '3.7'",
-            "version": "==20.26.3"
+            "version": "==20.26.4"
         },
         "watchdog": {
             "hashes": [
diff --git a/newdocs/src/changelog.md b/newdocs/src/changelog.md
index 9bfe4233..2885edc8 100644
--- a/newdocs/src/changelog.md
+++ b/newdocs/src/changelog.md
@@ -15,7 +15,21 @@
 - [Issue 1173](https://github.com/jackdewinter/pymarkdown/issues/1173)
 - [Issue 1175](https://github.com/jackdewinter/pymarkdown/issues/1175)
 - [Issue 1176](https://github.com/jackdewinter/pymarkdown/issues/1176)
-    - fixed issue with extra leading space item being added
+    - fixed parser issue with extra leading space item being added
+- [Issue 1164](https://github.com/jackdewinter/pymarkdown/issues/1164)
+- [Issue 1165](https://github.com/jackdewinter/pymarkdown/issues/1165)
+- [Issue 1171](https://github.com/jackdewinter/pymarkdown/issues/1171)
+- [Issue 1174](https://github.com/jackdewinter/pymarkdown/issues/1174)
+- [Issue 1177](https://github.com/jackdewinter/pymarkdown/issues/1177)
+- [Issue 1178](https://github.com/jackdewinter/pymarkdown/issues/1178)
+- [Issue 1180](https://github.com/jackdewinter/pymarkdown/issues/1180)
+- [Issue 1181](https://github.com/jackdewinter/pymarkdown/issues/1181)
+    - fixed rehydrator issue with extra leading space item being added
+- [Issue 1172](https://github.com/jackdewinter/pymarkdown/issues/1172)
+- [Issue 1173](https://github.com/jackdewinter/pymarkdown/issues/1173)
+- [Issue 1179](https://github.com/jackdewinter/pymarkdown/issues/1179)
+    - fixed rehydrator issue with reyhdrating after bqs with remove token being
+      blank line
 
 <!--- pyml disable-next-line no-duplicate-heading-->
 ### Changed
diff --git a/publish/coverage.json b/publish/coverage.json
index fa66e24f..c83aa07f 100644
--- a/publish/coverage.json
+++ b/publish/coverage.json
@@ -2,12 +2,12 @@
     "projectName": "pymarkdown",
     "reportSource": "pytest",
     "branchLevel": {
-        "totalMeasured": 5297,
-        "totalCovered": 5292
+        "totalMeasured": 5299,
+        "totalCovered": 5294
     },
     "lineLevel": {
-        "totalMeasured": 20736,
-        "totalCovered": 20726
+        "totalMeasured": 20742,
+        "totalCovered": 20732
     }
 }
 
diff --git a/pymarkdown/transform_markdown/transform_block_quote.py b/pymarkdown/transform_markdown/transform_block_quote.py
index d9d617ac..d73b8790 100644
--- a/pymarkdown/transform_markdown/transform_block_quote.py
+++ b/pymarkdown/transform_markdown/transform_block_quote.py
@@ -144,15 +144,9 @@ class TransformBlockQuote:
         return token_stack_index
 
     @staticmethod
-    def rehydrate_block_quote_end(
-        context: MarkdownTransformContext,
+    def __rehydrate_block_quote_end_calc(
         current_token: MarkdownToken,
-        actual_tokens: List[MarkdownToken],
-        token_index: int,
-    ) -> str:
-        POGGER.debug(">>__rehydrate_block_quote_end")
-        _ = current_token
-
+    ) -> Tuple[BlockQuoteMarkdownToken, Optional[str], int, List[str]]:
         current_end_token = cast(EndMarkdownToken, current_token)
         current_start_token = cast(
             BlockQuoteMarkdownToken, current_end_token.start_markdown_token
@@ -166,6 +160,7 @@ class TransformBlockQuote:
             f"current_end_token_extra>:{ParserHelper.make_value_visible(current_end_token_extra)}:<"
         )
         start_leading_index = current_start_token.leading_text_index
+
         assert (
             current_start_token.bleading_spaces is not None
         ), "Bleading spaces should be defined by now."
@@ -178,6 +173,31 @@ class TransformBlockQuote:
         POGGER.debug(
             f"split_start_leading>>:{ParserHelper.make_value_visible(split_start_leading)}:<"
         )
+
+        return (
+            current_start_token,
+            current_end_token_extra,
+            start_leading_index,
+            split_start_leading,
+        )
+
+    @staticmethod
+    def rehydrate_block_quote_end(
+        context: MarkdownTransformContext,
+        current_token: MarkdownToken,
+        actual_tokens: List[MarkdownToken],
+        token_index: int,
+    ) -> str:
+        POGGER.debug(">>__rehydrate_block_quote_end")
+        _ = current_token
+
+        (
+            current_start_token,
+            current_end_token_extra,
+            start_leading_index,
+            split_start_leading,
+        ) = TransformBlockQuote.__rehydrate_block_quote_end_calc(current_token)
+
         adjusted_end_string = (
             current_end_token_extra
             if start_leading_index + 1 < len(split_start_leading)
@@ -202,8 +222,9 @@ class TransformBlockQuote:
             indent_adjust = (
                 actual_tokens[search_index].line_number
                 - current_start_token.line_number
-                - 0
             )
+            if actual_tokens[token_index - 1].is_blank_line:
+                indent_adjust -= 1
 
             for indent_index in range(len(context.container_token_indents) - 1, -1, -1):
                 if context.container_token_stack[indent_index].is_block_quote_start:
diff --git a/pymarkdown/transform_markdown/transform_new_list_item.py b/pymarkdown/transform_markdown/transform_new_list_item.py
index 0c0cd6b7..1d72c9bd 100644
--- a/pymarkdown/transform_markdown/transform_new_list_item.py
+++ b/pymarkdown/transform_markdown/transform_new_list_item.py
@@ -254,10 +254,7 @@ class TransformNewListItem:
             split_leading_spaces = found_block_quote_token.bleading_spaces.split(
                 ParserHelper.newline_character
             )
-            leading_space = (
-                split_leading_spaces[line_number_delta - 1]
-                or split_leading_spaces[line_number_delta]
-            )
+            leading_space = split_leading_spaces[line_number_delta]
 
             POGGER.debug(f"rnli->leading_space>:{leading_space}:")
             adjustment_since_newline = len(leading_space)


Test patch:
diff --git a/publish/test-results.json b/publish/test-results.json
index 77913ecb..24c974b1 100644
--- a/publish/test-results.json
+++ b/publish/test-results.json
@@ -1620,10 +1620,10 @@
         },
         {
             "name": "test.test_markdown_extra",
-            "totalTests": 310,
+            "totalTests": 311,
             "failedTests": 0,
             "errorTests": 0,
-            "skippedTests": 4,
+            "skippedTests": 1,
             "elapsedTimeInMilliseconds": 0
         },
         {
diff --git a/test/rules/test_md031.py b/test/rules/test_md031.py
index a9de5db1..09c33ada 100644
--- a/test/rules/test_md031.py
+++ b/test/rules/test_md031.py
@@ -2650,7 +2650,7 @@ A code block
 > + another list
 """,
     ),
-    pluginRuleTest(  # test_extra_046f0 test_extra_046f1  https://github.com/jackdewinter/pymarkdown/issues/1173
+    pluginRuleTest(  # test_extra_046f0 test_extra_046f1
         "bad_fenced_block_in_list_in_block_quote_with_previous_inner_list",
         source_file_contents="""> + list 1
 >   + list 2
@@ -3069,7 +3069,7 @@ A code block
 > + another list
 """,
     ),
-    pluginRuleTest(  # test_extra_044mcz0x test_extra_044mcz0a https://github.com/jackdewinter/pymarkdown/issues/1179
+    pluginRuleTest(  # test_extra_044mcz0x test_extra_044mcz0a
         "bad_fenced_block_in_list_in_list_in_block_quote_with_previous_block",
         source_file_contents="""> + + -----
 >     > block 1
diff --git a/test/test_markdown_extra.py b/test/test_markdown_extra.py
index 5e9a2c27..8f029288 100644
--- a/test/test_markdown_extra.py
+++ b/test/test_markdown_extra.py
@@ -12189,12 +12189,10 @@ block 2</p>
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_extra_044mcz0a():
     """
     TBD
     bad_fenced_block_in_list_in_list_in_block_quote_with_previous_block
-    https://github.com/jackdewinter/pymarkdown/issues/1179
     """
 
     # Arrange
@@ -13658,12 +13656,10 @@ list 3</li>
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_extra_046f1():
     """
     TBD
     bad_fenced_block_in_list_in_block_quote_with_previous_inner_list
-    https://github.com/jackdewinter/pymarkdown/issues/1173
     """
 
     # Arrange
@@ -13841,6 +13837,66 @@ block 3</p>
     act_and_assert(source_markdown, expected_gfm, expected_tokens)
 
 
+@pytest.mark.gfm
+def test_extra_046g2():
+    """
+    TBD
+    """
+
+    # Arrange
+    source_markdown = """> + list 1
+>   > block 2
+>
+>   ```block
+>   A code block
+>   ```
+>
+> + another list
+"""
+    expected_tokens = [
+        "[block-quote(1,1)::> \n> \n> \n> \n> \n>\n> ]",
+        "[ulist(1,3):+::4::\n\n  \n  \n  \n\n]",
+        "[para(1,5):]",
+        "[text(1,5):list 1:]",
+        "[end-para:::True]",
+        "[block-quote(2,5)::> \n>]",
+        "[para(2,7):]",
+        "[text(2,7):block 2:]",
+        "[end-para:::True]",
+        "[BLANK(3,2):]",
+        "[end-block-quote:::True]",
+        "[fcode-block(4,5):`:3:block:::::]",
+        "[text(5,1):A code block:]",
+        "[end-fcode-block:::3:False]",
+        "[BLANK(7,2):]",
+        "[li(8,3):4::]",
+        "[para(8,5):]",
+        "[text(8,5):another list:]",
+        "[end-para:::True]",
+        "[BLANK(9,1):]",
+        "[end-ulist:::True]",
+        "[end-block-quote:::True]",
+    ]
+    expected_gfm = """<blockquote>
+<ul>
+<li>
+<p>list 1</p>
+<blockquote>
+<p>block 2</p>
+</blockquote>
+<pre><code class="language-block">A code block
+</code></pre>
+</li>
+<li>
+<p>another list</p>
+</li>
+</ul>
+</blockquote>"""
+
+    # Act & Assert
+    act_and_assert(source_markdown, expected_gfm, expected_tokens)
+
+
 @pytest.mark.gfm
 def test_extra_046h0():
     """
@@ -14271,12 +14327,10 @@ def test_extra_046l0():
 
 
 @pytest.mark.gfm
-@pytest.mark.skip
 def test_extra_046l1():
     """
     TBD
     bad_fenced_block_in_list_in_block_quote_bare
-    https://github.com/jackdewinter/pymarkdown/issues/1172
     """
 
     # Arrange
@@ -14321,7 +14375,7 @@ def test_extra_046l1():
 </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