fix(core): add unique heading IDs to Markdown for Outline compatibility#4191
fix(core): add unique heading IDs to Markdown for Outline compatibility#4191saadpocalypse wants to merge 1 commit into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Hi @saadpocalypse! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Description
Outline's documentation states that the
idon an outline item should match the target heading element'sid. WhileuseOutlineFromMarkdownis provided to derive these outline IDs, the<Markdown>component never renderedidattributes on the headings it produced. As a result, clicking an Outline item changed thelocation.hashbut never scrolled the page becausedocument.getElementById(id)returnednull.This PR fixes the issue by generating unique heading IDs during Markdown rendering to match the output of
useOutlineFromMarkdown, and attaches them to the rendered heading tags andcomponents.headingoverrides.Changes
packages/core/src/Outline/parseOutlineFromMarkdown.tsto import helper functions from the parser module, eliminating duplicated code.inlineText,slugify, anduniqueSlugfunctions frompackages/core/src/Markdown/parser.ts.MarkdownComponentstype interface inpackages/core/src/Markdown/Markdown.tsxso customheadingcomponent overrides can accept an optionalid.headingIdMapmemo hook in the<Markdown>component and propagated resolved heading IDs to all rendered header tags and components.headingIdMaphook above the early-return conditional check for inline display mode.packages/core/src/Markdown/Markdown.test.tsxto verify headings are rendered with the correct unique ID attributes.Verification
pnpm -F @astryxdesign/core test packages/core/src/Markdown/Markdown.test.tsx --runand verified all 56 tests passed successfully.Resolves #4173