fix(context): keep formatted and linked text in section titles - #175
Open
JayOfTheKeyboard wants to merge 1 commit into
Open
JayOfTheKeyboard wants to merge 1 commit into
JayOfTheKeyboard wants to merge 1 commit into
Conversation
getHeadingText read only a heading's direct text and inlineCode children, so text inside emphasis, strong and links was dropped. A heading that was entirely a link or bold got an empty title and fell through to "Introduction". Read inline text recursively, and drop permalink anchors (a # link whose text is only ¶, §, # or a zero-width space) inside <h2>, which would otherwise now end up in the title.
🦋 Changeset detectedLatest commit: 496088a The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
JayOfTheKeyboard
added a commit
to JayOfTheKeyboard/JayOfTheKeyboard
that referenced
this pull request
Sep 30, 2026
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.
Problem
getHeadingTextbuilds a section's title from the heading's directtextandinlineCodechildren only. Text inside a link,**strong**or*emphasis*is one level deeper, so it is dropped. When the whole heading is a link or bold, the title comes out empty, and the empty string falls through to the "content before the first h2" branch, so the section is filed as "Introduction".sectionTitlehas the highest weight in search (bm25(chunks_fts, 5.0, 10.0, 1.0)), so the lost words are the ones that count most.HTML docs are hit hardest, because turndown turns Sphinx's cross-references into links inside headings. Python 3.14 (
python-3.14-docs-html, the registry's source), before and after:int,float,complexNumeric Types — , ,Numeric Types — int, float, complexstrText Sequence Type —Text Sequence Type — strsitemoduleConstants added by the moduleConstants added by the site moduleOrderedDictobjectsobjectsOrderedDict objectsIntroductionWhy are Python strings immutable?The FAQ and several guides wrap every heading in a back-link to the page's contents (
<a class="toc-backref">), so the whole title is link text.Counts from parsing every page:
The Markdown cases: tRPC's
## Using [superjson](...)and## Using [devalue](...)are both titled "Using ", and Drizzle's FAQ## **Should I usegenerateorpush?**is filed as "Introduction".Fix
getHeadingTextreads inline text recursively (getInlineText):textandinlineCodevalues, and the children of any node that has them. Nodes without text (html,image,break) are still skipped, as before.<a class="headerlink" href="#...">¶</a>in every heading, rustdoc uses§, VuePress#and Docusaurus a zero-width space. The old code only dropped them by accident, as link text. A turndown rule now drops an<a href="#...">inside an<h2>whose text is only one of those symbols. The<h2>is the heading that becomes the section title. The rule matches on text, not class names, so it covers generators outside the registry too. It is a rule rather thanturndown.remove(), because turndown's link rule matches<a>beforeremove()is consulted.The rule is limited to
<h2>on purpose. The permalinks in<h3>and below are part of section content, and they count towardisTableOfContents's link ratio. Dropping them everywhere let the intro section of 35 Python pages, Sphinx's navigation bar included, pass that filter for the first time. That is a separate question, so this PR leaves the content alone: every section body is identical to main, apart from one line inusing/cmdline.htmlwhere an## ...¶heading already sat inside a body and now reads without the anchor.Not changed
<h3>and below stay in content, as before. Dropping them would change which sections the table-of-contents filter keeps, as described above. Happy to follow up if you want that.using/cmdline.html, "1.2. Environment variables" gets no section of its own. Its<h2>ends up inside the last part of "1.1. Command line". I have not looked into why. It is separate from this change.Test
Two tests. Both fail on
fc503b7and pass with the fix:build.test.ts: a link, a fully bold heading with inline code, and emphasis giveUsing superjson,Should I use generate or push?andThe strict option. On main:Using,Introduction,The option.html.test.ts: Sphinx markup (atoc-backrefquestion, a<code>cross-reference,¶permalinks), a rustdoc§anchor and a Docusaurus zero-width anchor nested in a<span>giveWhy are Python strings immutable?,Constants added by the site module,TraitsandSetup. An<h3>permalink stays in the content. On main the first two areIntroductionandConstants added by the module.I broke each part of the fix in turn, and each time a test went red:
inlineCodenot read<h3>permalink disappears from content)<h2>parent only, instead ofclosest("h2")Setupkeeps its zero-width space)§not treated as a permalinkTraits§)Setupkeeps its zero-width space)Validation
tsc -p tsconfig.build.jsonandbiome ci --error-on-warningsare clean..changeset/keep-heading-formatting.md(patch).