Repository navigation
fix: follow the CommonMark fence rules when MarkdownHeaderSplitter skips code blocks - #13344
Merged
anakin87 merged 2 commits intoOct 21, 2026
Merged
Conversation
…ips code blocks The code block pattern only matched a closing fence identical to the opening one, required both fences at the start of the line, and matched nothing for a block that is never closed, so `#` lines in those blocks were split off as headers. Match a closing fence of the same character that is at least as long as the opening fence, allow up to three spaces of indentation, and let an unclosed block run to the end of the text. A backtick fence's info string may not contain backticks, so a line starting with inline code does not open a block that would then hide every later header. Fixes deepset-ai#12954
Contributor
|
@Vedant-Agarwal is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
anakin87
requested changes
Oct 20, 2026
anakin87
left a comment
Member
There was a problem hiding this comment.
Mypy error:
test/components/preprocessors/test_markdown_header_splitter.py:674: error: Generator has incompatible item type "str | None"; expected "str" [misc]
Contributor
Author
|
Thanks, fixed in a03c809. (AI-assisted) |
anakin87
self-requested a review
October 20, 2026 15:06
Contributor
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
4 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
Proposed Changes:
_code_block_patternonly accepted a closing fence identical to the opening one, required both fences to start at column 0, and matched nothing when a block was never closed. In all three cases the block wasn't recognised, so#lines inside it were split off as headers.The pattern now follows the CommonMark fence rules:
can close with````` ````, but a shorter run or the other character inside the block doesn't close it```foo```) doesn't open a block and hide every header after itChunk content is unchanged, only which
#lines count as headers.How did you test it?
test_commonmark_fence_rules, 12 parametrised cases: longer backtick and tilde closers (the issue repro), shorter run and other character not closing, a fence line with an info string not closing, unclosed block, indented opener/closer, four spaces not being a fence, inline code not being a fence, tilde info string with backticks, CRLF line endings, and a closer on the last line with no trailing newline.mainand all 12 pass with the fix. The equal-length cases that already worked still pass.test_markdown_header_splitter.py: 85 passed, including the tests from fix: drop the ATX closing sequence from MarkdownHeaderSplitter header metadata #13282.ruff checkandruff format --check(0.16.0) pass, and mypy reports nothing for the changed file.Notes for the reviewer
#13282 noted that the fence cases from this issue live in the separate
_code_block_pattern, so this PR only touches that pattern and its comment. The comment above the pattern explains each part of the regex.AI-assisted: implemented with Claude Code. I reviewed the changes and ran the tests above.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.