fix: fix markdown parser edge cases in page_index_md.py#249
Open
octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
Open
fix: fix markdown parser edge cases in page_index_md.py#249octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
octo-patch wants to merge 1 commit intoVectifyAI:mainfrom
Conversation
…yAI#245) Three robustness fixes for extract_nodes_from_markdown and md_to_tree: 1. ATX closing hashes: update header regex to strip trailing ## markers so "## My Section ##" yields title "My Section" instead of "My Section ##" 2. Tilde + mismatched fence lengths: replace the simple backtick-only toggle with proper fence tracking that records the opening fence character ('`' or '~') and length. A closing fence must use the same character and be at least as long as the opening fence, so: - ~~~python...~~~ correctly suppresses headers inside tilde blocks - ````...``` does NOT close a 4-backtick block (3 < 4) 3. Headerless documents: when no headers are found, md_to_tree now creates a single root node containing the full document text instead of returning an empty structure, preventing silent data loss. Co-Authored-By: Octopus <liyuan851277048@icloud.com>
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.
Fixes #245
Problem
The
extract_nodes_from_markdownfunction inpageindex/page_index_md.pyhas three categories of bugs that cause incorrect or missing content when parsing common Markdown patterns:## My Section ##yields title"My Section ##"instead of"My Section".~~~pythonblocks are not recognized as code fences, so any# commentinside a tilde block is falsely detected as a header. Similarly, a 3-backtick sequence incorrectly closes a 4-backtick fence.Solution
1. ATX closing hashes
Updated the header regex from
r'^(#{1,6})\s+(.+)$'tor'^(#{1,6})\s+(.+?)(?:\s+#+\s*)?$'to strip optional trailing hash sequences.2. Tilde fences + mismatched lengths
Replaced the simple backtick toggle with proper fence tracking:
r'^({3,}|~{3,})'to match both `` ``` `` and~~~` with 3+ characters.\`` or~`) and length; a closing fence must use the same character and be at least as long as the opener.3. Headerless documents
In
md_to_tree, afterextract_node_text_contentreturns an empty list, a single root node is created containing the full document text, preventing silent data loss.Testing
All three cases verified manually: