Skip to content

Commit 340c765

Browse files
feat: safe type check
Signed-off-by: David Dal Busco <david.dalbusco@outlook.com>
1 parent 717f499 commit 340c765

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

plugins/docusaurus.llms.plugin.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ const prepareMarkdown = async ({
275275
turndownService.addRule("docusaurus-skip-to-main-content", {
276276
filter: (element: HTMLElement, _options: Options): boolean =>
277277
element.getAttribute("role") === "region" &&
278-
element.parentElement.getAttribute("id") === "__docusaurus",
278+
element.parentElement?.getAttribute("id") === "__docusaurus",
279279
replacement: (_content: string, _node: TurndownNode, _options: Options) =>
280280
""
281281
});
@@ -290,7 +290,7 @@ const prepareMarkdown = async ({
290290

291291
turndownService.addRule("docusaurus-admonition", {
292292
filter: (element: HTMLElement, _options: Options): boolean =>
293-
element.parentElement.classList.contains("theme-admonition") &&
293+
element.parentElement?.classList.contains("theme-admonition") === true &&
294294
element.className.includes("admonitionHeading"),
295295
replacement: (content: string, _node: TurndownNode, _options: Options) =>
296296
`**${capitalize(content)}:**`
@@ -310,7 +310,7 @@ const prepareMarkdown = async ({
310310

311311
const href = (node as HTMLElement).getAttribute("href");
312312

313-
if (href.startsWith("#")) {
313+
if (href?.startsWith("#")) {
314314
// Anchor are rendered after titles - e.g "<h3> Something[#](#anchor)" which is handy for the web but,
315315
// a bit noise in markdown. So we try to clean those.
316316
const empty = cleanZeroWidthSpace(content) === "";
@@ -323,7 +323,7 @@ const prepareMarkdown = async ({
323323
}
324324

325325
// Not a link to the documentation can be printed as standard link
326-
if (!href.startsWith(`/${docsDir}/`)) {
326+
if (!href?.startsWith(`/${docsDir}/`)) {
327327
return `[${content.trim()}](${href})`;
328328
}
329329

0 commit comments

Comments
 (0)