From 020c12ddc47f10aa9252dab6e262ae8aa0f95033 Mon Sep 17 00:00:00 2001 From: blurfx Date: Sun, 3 Nov 2024 03:18:16 +0900 Subject: [PATCH] fix: build error --- frontend/src/components/editor/Preview.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/frontend/src/components/editor/Preview.tsx b/frontend/src/components/editor/Preview.tsx index 5da9e454..1632e932 100644 --- a/frontend/src/components/editor/Preview.tsx +++ b/frontend/src/components/editor/Preview.tsx @@ -9,14 +9,14 @@ import MarkdownIt from "markdown-it"; import { toHtml } from "hast-util-to-html"; import markdownItKatex from "@vscode/markdown-it-katex"; import { refractor } from "refractor"; -import { Root } from "hast"; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import markdownItIncrementalDOM from "markdown-it-incremental-dom"; -import * as IncrementalDOM from "incremental-dom"; // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore import markdownItSanitizer from "markdown-it-sanitizer"; +// eslint-disable-next-line +const IncrementalDOM = require("incremental-dom"); import "./editor.css"; import "./preview.css"; @@ -24,10 +24,16 @@ const md = new MarkdownIt({ html: true, linkify: true, breaks: true, - highlight(code: string, lang: string) { - return `
${toHtml(
-			refractor.highlight(code, lang) as Root
-		)}
`; + highlight: (code: string, lang: string): string => { + try { + return `
${toHtml(
+				// eslint-disable-next-line @typescript-eslint/no-explicit-any
+				refractor.highlight(code, lang) as any
+			)}
`; + } catch (error) { + console.error(`Error highlighting code with language '${lang}':`, error); + return `
${md.utils.escapeHtml(code)}
`; + } }, }) .use(markdownItIncrementalDOM, IncrementalDOM) @@ -69,7 +75,7 @@ const Preview = () => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore IncrementalDOM.patch(containerRef.current, md.renderToIncrementalDOM(content)); - }, [content, md]); + }, [content]); if (!editorStore?.doc) { return (