fix: onthispage navbar component#6
Open
JVP008 wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes the “On this page” (TOC) navigation for wiki pages by ensuring rendered markdown headings receive stable id attributes that match the TOC’s generated anchor IDs.
Changes:
- Adjusts heading ID generation in
createHeadingId(trimming and underscore normalization). - Adds explicit
idattributes to rendered markdownh1–h4elements so TOC links can scroll correctly. - Updates the desktop TOC sidebar container sizing (
bottom-0) to better fit the page layout.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/lib/markdown.ts |
Updates heading ID normalization used for extracted TOC headings/anchors. |
src/client/routes/wiki-route.tsx |
Assigns IDs to rendered markdown heading elements and tweaks TOC sidebar layout. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return text | ||
| .toLowerCase() | ||
| .replace(/[^\w\s-]/g, "") | ||
| .replace(/_/g, "") |
Comment on lines
135
to
+141
| export function createHeadingId(text: string) { | ||
| return text.toLowerCase().replace(/[^\w\s-]/g, "").replace(/\s+/g, "-"); | ||
| return text | ||
| .toLowerCase() | ||
| .replace(/[^\w\s-]/g, "") | ||
| .replace(/_/g, "") | ||
| .trim() | ||
| .replace(/\s+/g, "-"); |
Comment on lines
+27
to
+32
| function getTextContent(children: React.ReactNode): string { | ||
| if (typeof children === "string") return children; | ||
| if (Array.isArray(children)) return children.map(getTextContent).join(""); | ||
| // @ts-ignore - children might be a ReactElement with props | ||
| if (children?.props?.children) return getTextContent(children.props.children); | ||
| return ""; |
Comment on lines
+30
to
+37
| // @ts-ignore - children might be a ReactElement with props | ||
| if (children?.props?.children) return getTextContent(children.props.children); | ||
| return ""; | ||
| } | ||
|
|
||
| const markdownComponents = { | ||
| h1: ({ ...props }) => <h1 className="mb-4 text-3xl scroll-mt-20" {...props} />, | ||
| h2: ({ ...props }) => <h2 className="font-display mb-3 mt-10 text-xl font-light scroll-mt-20" {...props} />, | ||
| h3: ({ ...props }) => <h3 className="font-display mb-2 mt-7 text-lg font-light scroll-mt-20" {...props} />, | ||
| h4: ({ ...props }) => <h4 className="mb-2 mt-5 text-base font-medium scroll-mt-20" {...props} />, | ||
| h1: ({ children, ...props }: any) => { | ||
| const id = createHeadingId(getTextContent(children)); |
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.
No description provided.