Skip to content

Conversation

@KyleKing
Copy link
Owner

@KyleKing KyleKing commented Nov 20, 2025

Previously, nested lists within definition bodies were using 2-space increments instead of the expected 4-space increments. This was caused by the normalize_list function skipping processing for any list with level > 1, which incorrectly excluded lists inside definition bodies.

The fix accounts for definition body context by checking context.env["indent_width"] to determine the expected level for top-level lists in the current context. Each definition body adds 2 to the token level and 4 to indent_width, so we calculate the expected top-level and only skip nested lists relative to that level.

This ensures that:

  • Lists in definition bodies maintain 4-space indentation
  • Nested lists within those lists also use 4-space increments
  • The behavior is consistent with mdformat-mkdocs' 4-space convention

Fixes #63
Related to #58 (partial fix)


Note

Ensure nested lists within definition bodies use 4-space increments by determining top-level via context indent width; update expectations and add regression test.

  • Formatter:
    • Update normalize_list to compute expected top-level from context.env["indent_width"] (def bodies add 2 levels / 4 spaces) and only skip lists deeper than that, ensuring 4-space increments for lists inside definition bodies.
  • Tests:
    • Adjust DEF_LIST_WITH_NESTED_WRAP_EXPECTED in tests/format/test_wrap.py to match corrected indentation.
    • Add test_definition_list_nested_indentation to validate 4-space increments for nested lists in definition bodies (including 4/8/12-space checks).

Written by Cursor Bugbot for commit 03c0567. This will update automatically on new commits. Configure here.

…odies

Previously, nested lists within definition bodies were using 2-space
increments instead of the expected 4-space increments. This was caused
by the normalize_list function skipping processing for any list with
level > 1, which incorrectly excluded lists inside definition bodies.

The fix accounts for definition body context by checking
context.env["indent_width"] to determine the expected level for
top-level lists in the current context. Each definition body adds 2 to
the token level and 4 to indent_width, so we calculate the expected
top-level and only skip nested lists relative to that level.

This ensures that:
- Lists in definition bodies maintain 4-space indentation
- Nested lists within those lists also use 4-space increments
- The behavior is consistent with mdformat-mkdocs' 4-space convention

Fixes #63
Related to #58 (partial fix)
@KyleKing KyleKing self-assigned this Nov 20, 2025
@KyleKing KyleKing changed the title Fix indentation for nested mkdocs elements fix(#63): indentation in nested mkdocs elements Nov 20, 2025
@KyleKing KyleKing merged commit 9da42ff into main Nov 21, 2025
9 checks passed
@KyleKing KyleKing deleted the claude/fix-mkdocs-indentation-01BHLCkm9vPDamtzxM1nz3us branch November 21, 2025 03:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix support for nested lists inside

3 participants