Skip to content

Commit 0799e19

Browse files
authored
fix: set prev token in render_list_item and add block_text to ignore_blocks (#456)
* fix: set prev token in render_list_item and add block_text to ignore_blocks The RSTRenderer.block_quote method accesses token.prev to decide whether to emit a .. separator before the blockquote. When a blockquote appears inside a list item, render_list_item called renderer.render_token directly without tracking prev, so blockquote tokens never received a prev reference. This caused a KeyError in older versions and silently degraded output in the current version (missing or incorrect .. separators). - Track prev in render_list_item, mirroring how RSTRenderer.iter_tokens already does for top-level tokens. - Add block_text (the list-internal paragraph token type) to the ignore_blocks tuple so a blockquote following list-internal text does not get a spurious .. separator. * Test RST list item blockquote separation
1 parent 10c918d commit 0799e19

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/mistune/renderers/_list.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,14 @@ def render_list_item(
3434

3535
leading = cast(str, parent["leading"]) + marker
3636
text = ""
37+
prev = None
3738
for tok in item["children"]:
3839
if tok["type"] == "list":
3940
tok["parent"] = parent
4041
elif tok["type"] == "blank_line":
4142
continue
43+
tok["prev"] = prev
44+
prev = tok
4245
text += renderer.render_token(tok, state)
4346

4447
lines = text.splitlines()

src/mistune/renderers/rst.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def block_quote(self, token: Dict[str, Any], state: BlockState) -> str:
130130
prev = token.get("prev")
131131
ignore_blocks = (
132132
"paragraph",
133+
"block_text",
133134
"thematic_break",
134135
"linebreak",
135136
"heading",

tests/fixtures/renderer_rst.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,19 @@ hello
256256
- item
257257
quote
258258
````````````````````````````````
259+
260+
```````````````````````````````` example
261+
- item
262+
263+
> first
264+
265+
> second
266+
.
267+
- item
268+
269+
first
270+
271+
..
272+
273+
second
274+
````````````````````````````````

0 commit comments

Comments
 (0)