From 340c765154f697d1d564bdfecb24a3f3269d345b Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Tue, 21 Apr 2026 13:35:59 +0200 Subject: [PATCH] feat: safe type check Signed-off-by: David Dal Busco --- plugins/docusaurus.llms.plugin.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/docusaurus.llms.plugin.ts b/plugins/docusaurus.llms.plugin.ts index e89cff1b..66af4a7a 100644 --- a/plugins/docusaurus.llms.plugin.ts +++ b/plugins/docusaurus.llms.plugin.ts @@ -275,7 +275,7 @@ const prepareMarkdown = async ({ turndownService.addRule("docusaurus-skip-to-main-content", { filter: (element: HTMLElement, _options: Options): boolean => element.getAttribute("role") === "region" && - element.parentElement.getAttribute("id") === "__docusaurus", + element.parentElement?.getAttribute("id") === "__docusaurus", replacement: (_content: string, _node: TurndownNode, _options: Options) => "" }); @@ -290,7 +290,7 @@ const prepareMarkdown = async ({ turndownService.addRule("docusaurus-admonition", { filter: (element: HTMLElement, _options: Options): boolean => - element.parentElement.classList.contains("theme-admonition") && + element.parentElement?.classList.contains("theme-admonition") === true && element.className.includes("admonitionHeading"), replacement: (content: string, _node: TurndownNode, _options: Options) => `**${capitalize(content)}:**` @@ -310,7 +310,7 @@ const prepareMarkdown = async ({ const href = (node as HTMLElement).getAttribute("href"); - if (href.startsWith("#")) { + if (href?.startsWith("#")) { // Anchor are rendered after titles - e.g "

Something[#](#anchor)" which is handy for the web but, // a bit noise in markdown. So we try to clean those. const empty = cleanZeroWidthSpace(content) === ""; @@ -323,7 +323,7 @@ const prepareMarkdown = async ({ } // Not a link to the documentation can be printed as standard link - if (!href.startsWith(`/${docsDir}/`)) { + if (!href?.startsWith(`/${docsDir}/`)) { return `[${content.trim()}](${href})`; }