diff --git a/server/src/markdownify/markdown.ts b/server/src/markdownify/markdown.ts index d1399297..0aeca9e7 100644 --- a/server/src/markdownify/markdown.ts +++ b/server/src/markdownify/markdown.ts @@ -1,27 +1,22 @@ -import TurndownService from "turndown"; -import { gfm } from "joplin-turndown-plugin-gfm"; - export async function parseMarkdown( html: string | null | undefined, ): Promise { - if (!html) return ""; + const TurndownService = require("turndown"); + const { gfm } = require("joplin-turndown-plugin-gfm"); const t = new TurndownService(); - - // Custom rule for inline links t.addRule("inlineLink", { filter: (node: any, opts: any) => opts.linkStyle === "inlined" && node.nodeName === "A" && node.getAttribute("href"), replacement: (content: string, node: any) => { - const href = node.getAttribute("href")?.trim() || ""; + const href = node.getAttribute("href").trim(); const title = node.title ? ` "${node.title}"` : ""; return `[${content.trim()}](${href}${title})\n`; }, }); - // GitHub-flavored markdown features t.use(gfm); try { @@ -52,7 +47,6 @@ function fixBrokenLinks(md: string): string { result += ch; } } - return result; } @@ -60,3 +54,4 @@ function stripSkipLinks(md: string): string { return md.replace(/\[Skip to Content\]\(#[^\)]*\)/gi, ""); } +