import { WidgetContent } from "$sb/app_event.ts"; import { asset, markdown } from "$sb/syscalls.ts"; import { panelHtml } from "../../web/components/panel_html.ts"; import { renderMarkdownToHtml } from "./markdown_render.ts"; export async function markdownContentWidget( markdownText: string, ): Promise { // Parse markdown to a ParseTree const mdTree = await markdown.parseMarkdown(markdownText); // And then render it to HTML const html = renderMarkdownToHtml(mdTree, { smartHardBreak: true }); return { html: await wrapHTML(html), script: await prepareJS(), // And add back the markdown text so we can render it in a different way if desired markdown: markdownText, }; } export async function prepareJS() { const iframeJS = await asset.readAsset("assets/markdown_widget.js"); return ` const panelHtml = \`${panelHtml}\`; ${iframeJS} `; } export async function wrapHTML(html: string): Promise { const css = await asset.readAsset("assets/markdown_widget.css"); return `
${html}
`; }