fix: preserve indentation and parse options with blank lines in nested mkdocstrings injection blocks#82
Conversation
WalkthroughThis PR exports 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@mdformat_mkdocs/_normalize_list.py`:
- Around line 458-466: The injection block handling in _normalize_list is still
letting mkdocstrings YAML sequences get normalized as Markdown lists, which
corrupts literal payloads. Update the new_contents construction path to treat
BlockIndent.kind == "code" from _parse_injection_block as literal content, not
list syntax, while keeping the existing indentation protection. Adjust the logic
that builds block_indents/injection_indents so code-style injection blocks
bypass the markdown list normalization path and preserve list-like YAML
unchanged.
In `@tests/format/test_format.py`:
- Line 44: The new injection cases in the format test suite are only covered by
plain equality checks, so add them to the existing syrupy snapshot coverage in
the test file that exercises the fixture corpus. Update the relevant snapshot
test around the format test harness to include the new cases, using the existing
snapshot-style assertions so indentation changes are reviewed as snapshots
instead of only direct comparisons.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: e514e204-6a18-4eb5-85a2-911aacee3ce7
📒 Files selected for processing (5)
mdformat_mkdocs/_normalize_list.pymdformat_mkdocs/mdit_plugins/__init__.pymdformat_mkdocs/mdit_plugins/_mkdocstrings_injection.pytests/format/fixtures/mkdocstrings_injection.mdtests/format/test_format.py
…ocks and add snapshot tests
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
mdformat_mkdocs/_normalize_list.py (1)
458-487: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick winUse
block_indentsfor semantic-break trimming too.Line 480 still feeds
code_indentsinto_parse_semantic_indent. Injection blocks only exist inblock_indents, so withuse_sem_break=Truenested:::blocks are still treated as normal continuation text and trimmed down to the 2-space semantic indent instead of preserving the 4-space child-block indent.Suggested fix
if use_sem_break: semantic_indents = map_lookback( _parse_semantic_indent, - [*zip(lines, code_indents, strict=True)], - _parse_semantic_indent(SemanticIndent.INITIAL, (lines[0], code_indents[0])), + [*zip(lines, block_indents, strict=True)], + _parse_semantic_indent( + SemanticIndent.INITIAL, (lines[0], block_indents[0]) + ), )As per coding guidelines,
mdformat_mkdocs/_normalize_list.pymust enforce 4-space indentation and handle semantic line breaks with 3-space alignment for numbered lists when semantic-break alignment is enabled.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@mdformat_mkdocs/_normalize_list.py` around lines 458 - 487, The semantic-break trimming path in _normalize_indents still uses code_indents when calling _parse_semantic_indent, so injection/child blocks are not preserved correctly. Update the use_sem_break branch in _normalize_indents to base semantic indentation on block_indents (or equivalent combined block state) instead of only code_indents, and keep _trim_semantic_indent aligned with the 4-space list indentation and 3-space numbered-list semantic-break behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@mdformat_mkdocs/_normalize_list.py`:
- Around line 458-487: The semantic-break trimming path in _normalize_indents
still uses code_indents when calling _parse_semantic_indent, so injection/child
blocks are not preserved correctly. Update the use_sem_break branch in
_normalize_indents to base semantic indentation on block_indents (or equivalent
combined block state) instead of only code_indents, and keep
_trim_semantic_indent aligned with the 4-space list indentation and 3-space
numbered-list semantic-break behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: e75b765e-f47e-432c-bf12-f18ea99f5f59
📒 Files selected for processing (6)
mdformat_mkdocs/__init__.pymdformat_mkdocs/_normalize_list.pymdformat_mkdocs/mdit_plugins/_material_deflist.pymdformat_mkdocs/mdit_plugins/_python_markdown_attr_list.pytests/format/__snapshots__/test_parsed_result.ambrtests/format/test_parsed_result.py
💤 Files with no reviewable changes (3)
- mdformat_mkdocs/init.py
- mdformat_mkdocs/mdit_plugins/_python_markdown_attr_list.py
- mdformat_mkdocs/mdit_plugins/_material_deflist.py
Fixing mkdocstring injections with empty lines in options or inside List.
Formatting Comparison
1. Nested Example (Inside List Item)
Input Markdown
Before
After
2. Plain Example
Input Markdown
Before
::: my_package._private_module options: heading_level: 2show_source: true
After