From 8fe830895124f2585936e3a27b51073d47280a7b Mon Sep 17 00:00:00 2001 From: Greg Brimble Date: Thu, 3 Oct 2024 18:28:13 -0400 Subject: [PATCH] [Docs Site] Support HTML entities in ToC (#17311) --- package-lock.json | 10 ++++++++++ package.json | 2 ++ src/components/overrides/PageSidebar.astro | 7 +++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 64ac01010b8120e..c32d8fe6d3bdcb0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,6 +21,7 @@ "@codingheads/sticky-header": "^1.0.2", "@stoplight/json-schema-tree": "^4.0.0", "@types/dompurify": "^3.0.5", + "@types/he": "^1.2.3", "@types/node": "^20.16.1", "@types/react": "^18.3.5", "@types/react-dom": "^18.3.0", @@ -34,6 +35,7 @@ "dot-prop": "^9.0.0", "github-slugger": "^2.0.0", "hastscript": "^9.0.0", + "he": "^1.2.0", "instantsearch.css": "^8.5.0", "instantsearch.js": "^4.74.0", "littlefoot": "^4.1.1", @@ -3042,6 +3044,13 @@ "@types/unist": "*" } }, + "node_modules/@types/he": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/@types/he/-/he-1.2.3.tgz", + "integrity": "sha512-q67/qwlxblDzEDvzHhVkwc1gzVWxaNxeyHUBF4xElrvjL11O+Ytze+1fGpBHlr/H9myiBUaUXNnNPmBHxxfAcA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/hogan.js": { "version": "3.0.5", "resolved": "https://registry.npmjs.org/@types/hogan.js/-/hogan.js-3.0.5.tgz", @@ -6789,6 +6798,7 @@ "resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz", "integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==", "dev": true, + "license": "MIT", "bin": { "he": "bin/he" } diff --git a/package.json b/package.json index 20bf3d504215212..42a7345405187a9 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "@codingheads/sticky-header": "^1.0.2", "@stoplight/json-schema-tree": "^4.0.0", "@types/dompurify": "^3.0.5", + "@types/he": "^1.2.3", "@types/node": "^20.16.1", "@types/react": "^18.3.5", "@types/react-dom": "^18.3.0", @@ -43,6 +44,7 @@ "dot-prop": "^9.0.0", "github-slugger": "^2.0.0", "hastscript": "^9.0.0", + "he": "^1.2.0", "instantsearch.css": "^8.5.0", "instantsearch.js": "^4.74.0", "littlefoot": "^4.1.1", diff --git a/src/components/overrides/PageSidebar.astro b/src/components/overrides/PageSidebar.astro index a871e1774df3fe2..c69f72d40378290 100644 --- a/src/components/overrides/PageSidebar.astro +++ b/src/components/overrides/PageSidebar.astro @@ -4,6 +4,7 @@ import Default from "@astrojs/starlight/components/PageSidebar.astro"; import type { CollectionEntry } from "astro:content"; import { entryToString } from "~/util/container"; import { parse } from "node-html-parser"; +import he from "he"; let rangeBetween = (x: number, y: number) => Array.from({ length: y - x + 1 }, (_, i) => i + x); @@ -48,9 +49,11 @@ if (Astro.props.toc) { for (const header of headers) { const depth = headerDepth(header); + const title = he.decode(header.innerText); + if (depth === 2) { Astro.props.toc.items.push({ - text: header.innerText, + text: title, slug: header.id, depth, children: [], @@ -60,7 +63,7 @@ if (Astro.props.toc) { } Astro.props.toc.items.at(-1)?.children.push({ - text: header.innerText, + text: title, slug: header.id, depth, children: [],