Repository navigation
Conversation
…erSplitter A line indented four or more columns is indented code in CommonMark, not a header, and AutoSplitter's own markdown check already allows at most three spaces before a header. MarkdownHeaderSplitter stripped every line before matching, so a comment such as " # then check the version" in an indented code block started a new h1 section and, with strip_headers on, was removed from the chunk text.
This branch has not been deployed
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.
MarkdownHeaderSplitterstrips each line before checking it for a header marker, so a line inside an indented code block that starts with#is read as a header. CommonMark allows at most three spaces of indentation before an ATX header; four or more make the line indented code.AutoSplitteralready follows that rule when it decides whether a document looks like Markdown (_looks_like_markdown,^\s{0,3}#{1,6}\s+\S).Example:
On main this gives three chunks: the comment line becomes a new
h1("then check the version") that replaces "Setup", the code block is split in two, and becausestrip_headersis on by default the comment line is removed from the chunk text. The "Usage" chunk then carriesh1: "then check the version".With this change a line indented four or more columns (tabs count to the next multiple of 4) is never treated as a header, so the example gives two chunks: "Setup" with the whole code block, and "Setup > Usage". Headers with up to three spaces of indentation still split as before.
I found this by reading the splitter and checking its output against markdown-it-py, not from a real document.
Compatibility
No change for saved workflows: no new fields or parameters. Output changes only for lines indented four or more columns that start with
#, which were split as headers before. One edge case: a header written inside a list item with four or more spaces of indentation is no longer split on (the splitter has no list-item tracking, so it can't tell that case from indented code).Verified
tests/unit/nodes/splitters/test_markdown_header_splitter.py:test_markdown_header_splitter_ignores_headers_inside_indented_code_blockfails on main and passes with the change;test_markdown_header_splitter_allows_up_to_three_spaces_before_a_headerpasses on both.pytest tests/unit/nodes/splitters/: 77 passed, 1 skipped (includes the AutoSplitter tests).flake8 --max-line-length 120,isort(black profile, 120),pyupgrade --py310-plusandbanditpass on the changed files. I didn't run the fullmake prepareor the whole suite.