From 54905c502c5e6de5516e36ddcd4969893572baa5 Mon Sep 17 00:00:00 2001 From: Shinya Fujino Date: Fri, 16 Jun 2023 00:15:16 +0900 Subject: Encode heading id when finding current link (#216) --- .changeset/orange-moose-impress.md | 5 +++++ packages/starlight/components/TableOfContents/starlight-toc.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/orange-moose-impress.md diff --git a/.changeset/orange-moose-impress.md b/.changeset/orange-moose-impress.md new file mode 100644 index 00000000..9aa06f0e --- /dev/null +++ b/.changeset/orange-moose-impress.md @@ -0,0 +1,5 @@ +--- +"@astrojs/starlight": patch +--- + +Encode heading id when finding current link diff --git a/packages/starlight/components/TableOfContents/starlight-toc.ts b/packages/starlight/components/TableOfContents/starlight-toc.ts index f327ff71..ffe7d68e 100644 --- a/packages/starlight/components/TableOfContents/starlight-toc.ts +++ b/packages/starlight/components/TableOfContents/starlight-toc.ts @@ -60,7 +60,7 @@ export class StarlightTOC extends HTMLElement { if (!isIntersecting) continue; const heading = getElementHeading(target); if (!heading) continue; - const link = links.find((link) => link.hash === '#' + heading.id); + const link = links.find((link) => link.hash === '#' + encodeURIComponent(heading.id)); if (link) { this.current = link; break; -- cgit