Skip to content

Comments

DEVSITE-1954: Fixed the no url update bug in local dev#80

Merged
jiangy10 merged 2 commits intomainfrom
DEVSITE-1954
Feb 9, 2026
Merged

DEVSITE-1954: Fixed the no url update bug in local dev#80
jiangy10 merged 2 commits intomainfrom
DEVSITE-1954

Conversation

@jiangy10
Copy link
Contributor

@jiangy10 jiangy10 commented Feb 7, 2026

Problem

Anchor links are empty when running in local development environment. When clicking on a header link or an "On This Page" navigation link, the URL contains an empty anchor (e.g., # with nothing after it).

Reason

The to-hast.ts step converts MDAST (Markdown Abstract Syntax Tree) to HAST (HTML Abstract Syntax Tree). Previously, it used defaultHandlers from mdast-util-to-hast, which does not generate id attributes for heading elements.
In local development, content is processed directly through the runtime connector without this additional step, resulting in headings without IDs.

Solution

Added a custom heading handler that:

  • Extracts the text content from the heading using hast-util-to-string
  • Converts the text to a URL-friendly slug (lowercase, hyphenated)
  • Sets the generated slug as the id property on the heading element

Result

  • Before: <h2>anchor</h2>
  • After: <h2 id="anchor">anchor</h2>

@jiangy10 jiangy10 requested a review from timkim February 7, 2026 07:15
@jiangy10 jiangy10 marked this pull request as ready for review February 7, 2026 07:20
@jiangy10 jiangy10 merged commit b38aeee into main Feb 9, 2026
1 check failed
@jiangy10 jiangy10 deleted the DEVSITE-1954 branch February 9, 2026 19:38
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.

2 participants