import { asset, clientStore, editor, markdown, system, } from "@silverbulletmd/silverbullet/syscalls"; import { renderMarkdownToHtml } from "./markdown_render.ts"; import { isLocalPath, resolvePath, } from "@silverbulletmd/silverbullet/lib/resolve"; import { expandCodeWidgets } from "./api.ts"; export async function updateMarkdownPreview() { if (!(await clientStore.get("enableMarkdownPreview"))) { return; } const currentPage = await editor.getCurrentPage(); const text = await editor.getText(); const mdTree = await markdown.parseMarkdown(text); // const cleanMd = await cleanMarkdown(text); const css = await asset.readAsset("markdown", "assets/preview.css"); const js = await asset.readAsset("markdown", "assets/preview.js"); await expandCodeWidgets(mdTree, currentPage); const html = renderMarkdownToHtml(mdTree, { smartHardBreak: true, annotationPositions: true, translateUrls: (url) => { if (isLocalPath(url)) { url = resolvePath(currentPage, decodeURI(url)); } return url; }, }); const customStyles = await editor.getUiOption("customStyles"); const toolbar = renderToolbar(); await editor.showPanel( "rhs", 2, `