2022-10-10 12:50:21 +00:00
|
|
|
import MarkdownIt from "https://esm.sh/markdown-it@13.0.1";
|
|
|
|
import taskLists from "https://esm.sh/markdown-it-task-lists@2.1.1";
|
2022-04-13 12:46:52 +00:00
|
|
|
|
2022-10-14 13:11:33 +00:00
|
|
|
import { clientStore, editor } from "$sb/silverbullet-syscall/mod.ts";
|
|
|
|
import { asset } from "$sb/plugos-syscall/mod.ts";
|
|
|
|
import { cleanMarkdown } from "./util.ts";
|
|
|
|
|
2022-04-13 12:46:52 +00:00
|
|
|
const md = new MarkdownIt({
|
|
|
|
linkify: true,
|
|
|
|
html: false,
|
|
|
|
typographer: true,
|
|
|
|
}).use(taskLists);
|
|
|
|
|
|
|
|
export async function updateMarkdownPreview() {
|
|
|
|
if (!(await clientStore.get("enableMarkdownPreview"))) {
|
|
|
|
return;
|
|
|
|
}
|
2022-10-14 13:11:33 +00:00
|
|
|
const text = await editor.getText();
|
|
|
|
const cleanMd = await cleanMarkdown(text);
|
|
|
|
const css = await asset.readAsset("styles.css");
|
|
|
|
await editor.showPanel(
|
2022-09-30 15:05:45 +00:00
|
|
|
"rhs",
|
|
|
|
2,
|
2022-10-14 13:11:33 +00:00
|
|
|
`<html><head><style>${css}</style></head><body>${
|
|
|
|
md.render(cleanMd)
|
|
|
|
}</body></html>`,
|
2022-04-13 12:46:52 +00:00
|
|
|
);
|
|
|
|
}
|