Skip to content

Commit

Permalink
[Docs Site] Support HTML entities in ToC (#17311)
Browse files Browse the repository at this point in the history
  • Loading branch information
GregBrimble authored Oct 3, 2024
1 parent d1c291b commit 8fe8308
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
7 changes: 5 additions & 2 deletions src/components/overrides/PageSidebar.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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: [],
Expand All @@ -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: [],
Expand Down

0 comments on commit 8fe8308

Please sign in to comment.