1
0
silverbullet/plugs/markdown/widget.ts
2023-02-23 15:33:51 +01:00

21 lines
570 B
TypeScript

import { parseMarkdown } from "$sb/silverbullet-syscall/markdown.ts";
import type { WidgetContent } from "$sb/app_event.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts";
export async function markdownWidget(
bodyText: string,
): Promise<WidgetContent> {
const mdTree = await parseMarkdown(bodyText);
const html = await renderMarkdownToHtml(mdTree, {
smartHardBreak: true,
});
return Promise.resolve({
html: html,
script: `updateHeight();
document.addEventListener("click", () => {
api({type: "blur"});
});`,
});
}