web: nicer tables
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useMemo } from "preact/hooks";
|
||||
import DOMPurify from "dompurify";
|
||||
import { marked } from "marked";
|
||||
import { marked, Renderer } from "marked";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
type MarkdownMode = "default" | "citationTokens";
|
||||
@@ -21,8 +21,15 @@ function replaceMarkdownLinksWithCitationTokens(markdown: string, resolveCitatio
|
||||
});
|
||||
}
|
||||
|
||||
const markdownRenderer = new Renderer();
|
||||
const renderTable = markdownRenderer.table.bind(markdownRenderer);
|
||||
|
||||
markdownRenderer.table = (token) => {
|
||||
return `<div class="md-table-scroll">${renderTable(token)}</div>`;
|
||||
};
|
||||
|
||||
function renderMarkdown(markdown: string) {
|
||||
const rawHtml = marked.parse(markdown, { gfm: true, breaks: true }) as string;
|
||||
const rawHtml = marked.parse(markdown, { gfm: true, breaks: true, renderer: markdownRenderer }) as string;
|
||||
return DOMPurify.sanitize(rawHtml, { ADD_ATTR: ["class", "target", "rel"] });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user