fix/site: Fix broken tables of contents - #1859
Open
marcleblanc2 wants to merge 1 commit into
Open
Conversation
The headings computed field removed fenced code blocks with the non-greedy regex /```[\s\S]*?```/g. Any inline triple-backtick run in prose (e.g. `"true``` on batch-spec-yaml-reference.mdx line 376) was taken as a fence opener, flipping every later fence pairing. YAML `# comment` lines inside fences then leaked into the TOC as headings with anchors that don't exist, while real headings were dropped. Walk the body line by line instead: a fence opens on a line starting with 3+ backticks or tildes and closes on a line of the same character at least as long, matching how the MDX renderer treats fences. On /batch-changes/batch-spec-yaml-reference this removes 12 bogus TOC entries and restores 13 real ones. No other page's headings change. Amp-Thread-ID: https://ampcode.com/threads/T-01a07599-bfc6-773f-abc1-7e0cd96db912 Co-authored-by: Amp <amp@ampcode.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
The right-hand TOC (
headingscomputed field incontentlayer.config.ts) strips fenced code blocks with the non-greedy regex/```[\s\S]*?```/g, then treats any remaining#line as a heading.Any inline triple-backtick run in prose is taken as a fence opener and flips every later fence pairing.
docs/batch-changes/batch-spec-yaml-reference.mdxhas two (`"true```on line 376,`"*```on line 709), so from there on the "inside/outside a fence" state is inverted: YAML# commentlines leak into the TOC as headings whose anchors don't exist, and real headings are dropped.Live repro: https://sourcegraph.com/docs/batch-changes/batch-spec-yaml-reference has a TOC entry linking to
#do-not-meddle-in-the-affairs-of-wizards-for-they-are-subtle-and-quick-to-anger(line 572 of the MDX, a YAML comment inside a fence). No element with that id exists. This page alone accounted for 14 of the broken anchors found by lychee in the investigation behind #1858.Before / after
TOC on
/batch-changes/batch-spec-yaml-reference, localnext dev, 1600px viewport.main)Before: 12 YAML comments (
if: is true, step always executes.,Mount a Python script and run the script,Do not meddle in the affairs of wizards…) render as TOC entries with dead anchors, and everychangesetTemplate.*heading except.forkis missing. After: the comments are gone andsteps.mount,importChangesets*,changesetTemplate*,Publishing only specific changesetsare back.Fix
Walk the body line by line: a fence opens on a line starting with 3+ backticks or tildes and closes on a line of the same character at least as long, matching how the MDX renderer treats fences. Also handles the
four-backtick fences in `cody/troubleshooting.mdx` and `code-navigation/writing-an-indexer.mdx` that contain literal``` ```` text.Verification
.mdxunderdocs/: onlybatch-spec-yaml-reference.mdxchanges — 12 bogus comment entries removed, 13 real headings restored.npx contentlayer build: generatedPostfor that page has 66 headings, 0 bogus, allchangesetTemplate.*ids present.npx tsc --noEmitclean,next lintclean.Follow-up from the link-check work in #1858.