Skip to content

fix: drop the ATX closing sequence from MarkdownHeaderSplitter header metadata - #13282

Merged
anakin87 merged 2 commits into
deepset-ai:mainfrom
TemitopeKadri:fix/markdown-header-closing-sequence
Oct 16, 2026
Merged

anakin87 merged 2 commits into
deepset-ai:mainfrom
TemitopeKadri:fix/markdown-header-closing-sequence

Conversation

@TemitopeKadri

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

MarkdownHeaderSplitter took the header text from match.group(2).strip(), so the optional closing sequence of an ATX header (## Install ##) ended up in the header and parent_headers metadata.

This PR strips that closing sequence when the header text is extracted. Following the CommonMark rule, it is removed only when it is the whole header text or follows whitespace. So ## C#, ## Install #1 and ## Install \# keep their text. The chunk content is untouched and still reconstructs the input byte-exactly. Only the metadata changes.

How did you test it?

  • Added test_closing_sequence_is_not_part_of_header_metadata. It covers trailing ##, a long closing sequence with trailing spaces, a tab separator and an empty ## ## header, plus three cases that must not be stripped (C#, #1, escaped \#). It also checks parent_headers and that the joined chunk content equals the input.
  • hatch run test:unit test/components/preprocessors/test_markdown_header_splitter.py: 70 passed. The new cases fail on main.
  • hatch run fmt-check and hatch run test:types pass.

Notes for the reviewer

The fenced-code-block cases in #12954 come from the separate _code_block_pattern, so this PR doesn't touch them.

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

🤖 Generated with Claude Code

@TemitopeKadri
TemitopeKadri requested a review from a team as a code owner October 15, 2026 20:26
@TemitopeKadri
TemitopeKadri requested review from anakin87 and removed request for a team October 15, 2026 20:26
@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

@TemitopeKadri is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Oct 15, 2026
@github-actions

github-actions Bot commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/preprocessors
  markdown_header_splitter.py
  haystack/core/pipeline
  pipeline.py
Project Total  

This report was generated by python-coverage-comment-action

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

I pushed a minor refinement

@anakin87
anakin87 enabled auto-merge (squash) October 16, 2026 08:19
@anakin87
anakin87 merged commit 9b93dee into deepset-ai:main Oct 16, 2026
22 of 23 checks passed
@TemitopeKadri

Copy link
Copy Markdown
Contributor Author

Thanks for the quick review and merge, @anakin87, and for tightening the regex. Good catch on the Windows line endings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MarkdownHeaderSplitter keeps the closing # sequence of ATX headers in header metadata

2 participants