Skip to content

Return only the header line from to_markdown for empty sections - #44

Merged
Gal-Gilor merged 2 commits into
mainfrom
fix/to-markdown-empty-content
Oct 18, 2026
Merged

Gal-Gilor merged 2 commits into
mainfrom
fix/to-markdown-empty-content

Conversation

@Gal-Gilor

@Gal-Gilor Gal-Gilor commented Oct 18, 2026 •

Copy link
Copy Markdown
Owner

What changed

  • Section.to_markdown() returns only the header line when the section has no content. For "# A\n## B", the first section now returns "# A" instead of "# A\n\n". Sections with content and level-0 sections behave as before.
  • Added test_to_markdown_without_content in tests/test_splitter.py.
  • README, Data Models: one sentence saying the freezing is shallow and metadata.parents should be treated as read-only.
  • CHANGELOG: a 0.3.0 "Fixed" entry for this change.

Why

A section without content got the header followed by two stray newlines. it was present in the old MarkdownContent.to_markdown too.

Verification

  • The new test fails on main (AssertionError: assert '# A\n\n' == '# A') and passes with the fix.
  • uv sync --locked, uv run ruff check --no-fix . and uv run ruff format --check . pass.
  • uv run pytest -q --cov=markdown_chunkify --cov-report=term-missing: 95 passed, models.py at 100% coverage.
  • uv run python -m doctest markdown_chunkify/splitter.py passes.
  • Fresh Python 3.12 venv with pydantic==2.0.2: 95 passed.

Section.to_markdown() appended two newlines after the header even when
the section had no content. Return just the header line in that case.
Add a test, and note in the README that freezing is shallow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018jNL9rsodv5SMpDXVNMEia
Record the empty-section to_markdown fix under 0.3.0 Fixed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018jNL9rsodv5SMpDXVNMEia
@Gal-Gilor
Gal-Gilor merged commit d2c98f2 into main Oct 18, 2026
5 checks passed
@Gal-Gilor
Gal-Gilor deleted the fix/to-markdown-empty-content branch October 18, 2026 22:19
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.

2 participants