import MarkdownIt from "markdown-it"; import { getText, showLhs, showRhs, hideRhs, hideLhs, } from "@silverbulletmd/plugos-silverbullet-syscall/editor"; import * as clientStore from "@silverbulletmd/plugos-silverbullet-syscall/clientStore"; import { cleanMarkdown } from "./util"; import { readSettings, writeSettings } from "@silverbulletmd/plugs/lib/settings_page"; const css = ` `; var taskLists = require("markdown-it-task-lists"); const md = new MarkdownIt({ linkify: true, html: false, typographer: true, }).use(taskLists); export async function updateMarkdownPreview() { if (!(await clientStore.get("enableMarkdownPreview"))) { return; } let text = await getText(); let cleanMd = await cleanMarkdown(text); const setting = await readSettings({previewOnRHS: true}); const show = setting.previewOnRHS ? showRhs : showLhs; await show( `${css}${md.render(cleanMd)}`, undefined, 2 ); } export async function switchSide() { const {previewOnRHS} = await readSettings({previewOnRHS: true}); const isVisible = await clientStore.get("enableMarkdownPreview"); if (isVisible) { if (previewOnRHS){ hideRhs(); } else { hideLhs(); } } await writeSettings({previewOnRHS: !previewOnRHS}); if (isVisible) { updateMarkdownPreview(); } }