1
0
silverbullet/plugs/markdown/widget.ts

21 lines
547 B
TypeScript
Raw Normal View History

2023-08-28 15:12:15 +00:00
import { markdown } from "$sb/syscalls.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> {
2023-08-28 15:12:15 +00:00
const mdTree = await markdown.parseMarkdown(bodyText);
2022-12-22 15:20:05 +00:00
2023-08-28 15:12:15 +00:00
const html = renderMarkdownToHtml(mdTree, {
2022-12-22 15:20:05 +00:00
smartHardBreak: true,
});
return Promise.resolve({
html: html,
script: `updateHeight();
document.addEventListener("click", () => {
api({type: "blur"});
});`,
});
}