fix: plugin imports

This commit is contained in:
amhsirak
2025-11-20 04:10:12 +05:30
parent b14d84d83a
commit 839f9fa5ce

View File

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