Skip to content

Commit

Permalink
fix: build error
Browse files Browse the repository at this point in the history
  • Loading branch information
blurfx committed Nov 2, 2024
1 parent 6d4b753 commit 6e4c465
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions frontend/src/components/editor/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ 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 @typescript-eslint/no-var-requires
const IncrementalDOM = require("incremental-dom");
import "./editor.css";
import "./preview.css";

const md = new MarkdownIt({
html: true,
linkify: true,
breaks: true,
highlight(code: string, lang: string) {
return `<pre class="language-${lang}"><code>${toHtml(
refractor.highlight(code, lang) as Root
)}</code></pre>`;
highlight: (code: string, lang: string): string => {
try {
return `<pre class="language-${lang}"><code>${toHtml(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
refractor.highlight(code, lang) as any
)}</code></pre>`;
} catch (error) {
console.error(`Error highlighting code with language '${lang}':`, error);
return `<pre class="language-"><code>${md.utils.escapeHtml(code)}</code></pre>`;
}
},
})
.use(markdownItIncrementalDOM, IncrementalDOM)
Expand Down Expand Up @@ -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 (
Expand Down

0 comments on commit 6e4c465

Please sign in to comment.