fix: set prev token in render_list_item and add block_text to ignore_blocks#456
Conversation
…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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #456 +/- ##
==========================================
+ Coverage 91.01% 91.04% +0.03%
==========================================
Files 34 34
Lines 3395 3407 +12
Branches 670 672 +2
==========================================
+ Hits 3090 3102 +12
Misses 184 184
Partials 121 121
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Hi @gaoflow thanks for the patch. Can you add a test for this case? |
|
Added in The fixture now covers a list item containing normal item text followed by two separate block quotes. That case exercises both pieces of the fix: no separator before the first quote after Local verification: |
|
Thanks. |
|



When a blockquote appears inside a list item, the RST renderer's block_quote method accesses token.prev to decide whether to emit a .. separator. However, render_list_item called renderer.render_token directly without tracking prev across child tokens — unlike RSTRenderer.iter_tokens which sets prev for top-level tokens.
This meant blockquote tokens inside list items never received a prev reference. In older versions this could cause a KeyError; in the current version it silently degrades the output with missing or incorrect .. separators between blocks inside list items.
Changes:
Fixes: KeyError('prev') when rendering markdown containing blockquotes inside list items with the RST renderer