silverbullet/plugs/markdown/markdown.ts

19 lines
635 B
TypeScript
Raw Normal View History

2022-10-14 21:11:33 +08:00
import { clientStore, editor, system } from "$sb/silverbullet-syscall/mod.ts";
import { readSettings } from "$sb/lib/settings_page.ts";
2022-03-28 21:25:05 +08:00
2022-04-04 21:25:07 +08:00
export async function togglePreview() {
2022-10-14 21:11:33 +08:00
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
2022-04-04 21:25:07 +08:00
await clientStore.set("enableMarkdownPreview", !currentValue);
if (!currentValue) {
2022-10-14 21:11:33 +08:00
await system.invokeFunction("client", "preview");
2022-04-04 21:25:07 +08:00
} else {
await hideMarkdownPreview();
2022-04-09 20:57:59 +08:00
}
2022-03-28 21:25:05 +08:00
}
2022-04-04 21:25:07 +08:00
async function hideMarkdownPreview() {
const setting = await readSettings({ previewOnRHS: true });
2022-10-14 21:11:33 +08:00
const hide = setting.previewOnRHS ? editor.hideRhs : editor.hideLhs;
await hide();
2022-04-04 21:25:07 +08:00
}