1
0
silverbullet/plugs/markdown/widget.ts

21 lines
564 B
TypeScript
Raw Normal View History

2022-12-22 15:20:05 +00:00
import { parseMarkdown } from "$sb/silverbullet-syscall/markdown.ts";
2023-01-21 12:37:55 +00:00
import type { WidgetContent } from "$sb/app_event.ts";
2022-12-22 15:20:05 +00:00
import { renderMarkdownToHtml } from "./markdown_render.ts";
export async function markdownWidget(
bodyText: string,
2023-01-21 12:37:55 +00:00
): Promise<WidgetContent> {
2022-12-22 15:20:05 +00:00
const mdTree = await parseMarkdown(bodyText);
const html = renderMarkdownToHtml(mdTree, {
smartHardBreak: true,
});
return Promise.resolve({
html: html,
script: `updateHeight();
document.addEventListener("click", () => {
api({type: "blur"});
});`,
});
}