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);
|
|
|
|
|
2023-02-23 14:33:51 +00:00
|
|
|
const html = await 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"});
|
|
|
|
});`,
|
|
|
|
});
|
|
|
|
}
|