Repository navigation
Make MarkdownSplitter an immutable class and remove the outline - #41
Merged
Merged
Conversation
MarkdownSplitter takes a keyword-only max_level in __init__, checks that it is between 1 and 6, and has split_text, split_file and get_document_outline methods that call the private module-level helpers with self.max_level. The module-level functions are removed, so the package has one API. The tests, the CI wheel check, the README and the changelog use the class. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FHW7nLqPiFJhQm6M1ARLi6
MarkdownSplitter is now a frozen, keyword-only dataclass with one field, max_level. split_text builds the sections in one pass with a stack of the enclosing sections, instead of building an outline and flattening it. Results are unchanged. Remove get_document_outline and OutlineNode. Sections with parent_id already describe the tree, so the library keeps one representation. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018jNL9rsodv5SMpDXVNMEia
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.
What changed
MarkdownSplitteris a frozen, keyword-only dataclass with one field,max_level(1-6, default 6).MarkdownSplitter(3)raisesTypeError, and settingmax_levelafter creation raisesFrozenInstanceError.split_textandsplit_fileare methods.split_textbuilds the sections in one pass with a stack of the enclosing sections.get_document_outline,OutlineNodeand_create_sections_from_outline. The package exportsMarkdownSplitter,SectionandSectionMetadata.splitter = MarkdownSplitter(). Removed the outline-only tests; the section tests cover the same behavior.Why
parent_id, instead of both sections and an outline.Verification
main: 508 distinct inputs (every text main's test run passed to the splitter, every string literal in main'stests/test_splitter.pyandconftest.py, README.md and CHANGELOG.md, the README examples, and 194 generated documents with preamble, BOM, CRLF, front matter and code fences). Each was compared with the default and withmax_level1-6, 3556 comparisons in all.[s.model_dump() for s in ...]was equal in every case.ruff checkandruff format --checkpass. 94 tests pass,splitter.pycoverage is 98%, the same asmain.