fix(markdown): keep text before the first heading as a Preface node by jayhemnani9910 · Pull Request #610 · VectifyAI/PageIndex · GitHub
Skip to content

fix(markdown): keep text before the first heading as a Preface node - #610

Open
jayhemnani9910 wants to merge 1 commit into
VectifyAI:mainfrom
jayhemnani9910:fix/md-keep-preface
Open

jayhemnani9910 wants to merge 1 commit into
VectifyAI:mainfrom
jayhemnani9910:fix/md-keep-preface

Conversation

@jayhemnani9910

Copy link
Copy Markdown

Fixes #609

extract_node_text_content gives each node the text from its heading to the next one, so anything above the first heading belongs to no node and is dropped. That covers a README's intro, a document whose title is a setext heading, and a file with no headings at all, which ends up with zero nodes.

This keeps that text as a Preface node, as both PDF paths do (add_preface_if_needed, flash _add_preface). The node takes the level of the first heading so the rest of the tree keeps its shape. A leading YAML front matter block is not included.

before: [Install, Usage]                      # intro and its facts missing
after:  [Preface (the intro text), Install, Usage]
no headings, before: []   after: [Preface (whole file)]

Tests: four cases in tests/test_page_index_md.py (preamble, no headings, front matter, file starting with a heading). The first two fail on main.

pytest tests   main: 814 passed, 145 skipped   branch: 818 passed, 145 skipped

extract_node_text_content gives each node the text from its heading to
the next one, so anything above the first heading belonged to no node
and was dropped from the tree. A README's intro, a document whose title
is not an ATX heading, and a file with no headings at all (zero nodes)
lost that text from the index.

Keep it as a Preface node, as both PDF paths already do, at the level
of the first heading so the tree shape is unchanged. A leading YAML
front matter block is not part of it.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown indexing drops text before the first heading, and setext headings

1 participant