Skip to content

fix(core): handle malformed Markdown heading levels - #177

Merged
vedaant00 merged 1 commit into
mldsveda:mainfrom
Aming9303:fix/176-heading-level
Aug 27, 2026
Merged

fix(core): handle malformed Markdown heading levels#177
vedaant00 merged 1 commit into
mldsveda:mainfrom
Aming9303:fix/176-heading-level

Conversation

@Aming9303

Copy link
Copy Markdown

Summary

  • parse heading levels defensively instead of raising on malformed user data
  • preserve valid h1-h6 headings and clamp numeric levels to Markdown's h1-h6 range
  • fall back to h2 for missing, empty, None, and non-heading values
  • add regression coverage for valid, malformed, and out-of-range levels

Verification

  • pytest tests/test_core/test_models.py -q (39 passed, 5 skipped)
  • pytest tests -q (546 passed, 9 skipped, 19 deselected)
  • ruff check src tests
  • ruff format --check src tests

Fixes #176

@vedaant00

Copy link
Copy Markdown
Collaborator

Reviewed and it's correct @Aming9303: title/empty/None default to h2, h9/h0 clamp to h1-h6, and valid levels are unchanged. 7 tests pass, green, no conflicts. Merging, thanks and welcome.

@vedaant00
vedaant00 merged commit c475d2b into mldsveda:main Aug 27, 2026
6 checks passed
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.

to_markdown() crashes on a heading whose level isn't h1-h6

2 participants