diff --git a/packages/docusaurus-search-local/src/server/parse.test.js b/packages/docusaurus-search-local/src/server/parse.test.js
index d59939f..4296787 100644
--- a/packages/docusaurus-search-local/src/server/parse.test.js
+++ b/packages/docusaurus-search-local/src/server/parse.test.js
@@ -310,5 +310,43 @@ describe("parser", () => {
],
});
});
+
+ it("parses hashes correctly from URLs", () => {
+ const html = `
+
TITLE
+
+
+ a
+ b
+ c
+
+
+
+ `;
+ expect(html2text(html, "docs")).toEqual({
+ docSidebarParentCategories: [],
+ pageTitle: "a",
+ sections: [
+ {
+ title: "a",
+ hash: "#first#second",
+ content: "",
+ tags: [],
+ },
+ {
+ title: "b",
+ hash: "#first#second",
+ content: "",
+ tags: [],
+ },
+ {
+ title: "c",
+ hash: "#first#second",
+ content: "",
+ tags: [],
+ },
+ ],
+ });
+ });
});
});
diff --git a/packages/docusaurus-search-local/src/server/parse.ts b/packages/docusaurus-search-local/src/server/parse.ts
index d13a7fb..e9a4a75 100644
--- a/packages/docusaurus-search-local/src/server/parse.ts
+++ b/packages/docusaurus-search-local/src/server/parse.ts
@@ -124,8 +124,9 @@ export function html2text(
// #
.not("a[aria-hidden=true], a.hash-link")
.text();
- const hash = $(heading).find("a.hash-link").attr("href") || "";
-
+ const linkHash = $(heading).find("a.hash-link").attr("href") || "";
+ const [, ...hashParts] = linkHash.split("#");
+ const hash = hashParts.length ? `#${hashParts.join("#")}` : "";
let $sectionElements;
if ($(heading).parents(".markdown").length === 0) {
// $(heading) is the page title