Skip to content

fix: ignore headings inside HTML comment blocks in MarkdownHeaderSplitter - #14052

Draft
wkd09 wants to merge 1 commit into
deepset-ai:mainfrom
wkd09:fix/14051-markdown-comment-headings
Draft

wkd09 wants to merge 1 commit into
deepset-ai:mainfrom
wkd09:fix/14051-markdown-comment-headings

Conversation

@wkd09

@wkd09 wkd09 commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Fixes #14051.

Proposed Changes

A commented-out heading in a Markdown help page could give the following paragraph the wrong header metadata. In the issue example, filtering by 🍕 Pizza delivery missed the delivery time because it was indexed under Old delivery policy.

Skip heading candidates inside line-start HTML comment blocks while preserving the original text. Scan comments and fenced code blocks in source order so a marker inside one cannot open the other.

How did you test it?

  • Reproduced MarkdownHeaderSplitter splits a section at a heading inside an HTML comment #14051 with both values of keep_headers. After the fix, the delivery time is in the pizza section and filtering for the old policy returns no documents.
  • Ran pytest -q test/components/preprocessors/test_markdown_header_splitter.py locally. All 133 tests passed, including coverage for unclosed comments, code fences, and secondary split offsets.

Notes for the reviewer

The implementation and tests were generated with Codex.

Checklist

  • Followed the contributing guidelines and code of conduct.
  • The issue includes the reproduction and proposed fix.
  • Added unit tests and updated the component docstring.
  • Used a conventional commit title.
  • Updated the component documentation.
  • Added a release note.
  • Ran the pre-commit hooks on the changed files.

@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

@wkd09 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 the type:documentation Improvements on the docs label Dec 2, 2026
@github-actions

github-actions Bot commented Dec 2, 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/components/validators
  json_schema.py
Project Total  

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

@Utkarsh-upadhyay9 Utkarsh-upadhyay9 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I ran the test file on this branch (133 passed) and compared a few extra inputs against markdown-it-py in CommonMark mode:

  • a real heading right after a closed comment, text after --> on the closing line, a tab-indented <!-- (an indented code block), and <!-- opened inside a list item (- <!-- followed by an unindented # B) all split the same way CommonMark parses them ✔
  • para <!--\n# B\n--> still splits at # B. CommonMark agrees, because an ATX heading interrupts the paragraph before the inline comment can span the lines ✔

One related gap, outside the scope of this PR: other HTML blocks hide headings the same way. In CommonMark, # A\n<div>\n# B\n</div> is a single html_block, so # B isn't a heading, but the splitter still starts a new section there. Those block types (6/7) end at a blank line instead of a closer, so they'd need different handling from the comment regex. That's probably better as a separate issue.

The comment handling looks good to me.

This branch has not been deployed

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

Labels

type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MarkdownHeaderSplitter splits a section at a heading inside an HTML comment

2 participants