1
0
silverbullet/plugs/markdown/markdown.ts

20 lines
689 B
TypeScript
Raw Normal View History

import { editor } from "$sb/silverbullet-syscall/mod.ts";
2022-10-14 13:11:33 +00:00
import { readSettings } from "$sb/lib/settings_page.ts";
import { updateMarkdownPreview } from "./preview.ts";
2023-08-26 06:31:51 +00:00
import { clientStore } from "$sb/silverbullet-syscall/mod.ts";
2022-03-28 13:25:05 +00:00
2022-04-04 13:25:07 +00:00
export async function togglePreview() {
2023-08-26 06:31:51 +00:00
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
await clientStore.set("enableMarkdownPreview", !currentValue);
2022-04-04 13:25:07 +00:00
if (!currentValue) {
await updateMarkdownPreview();
2022-04-04 13:25:07 +00:00
} else {
await hideMarkdownPreview();
2022-04-09 12:57:59 +00:00
}
2022-03-28 13:25:05 +00:00
}
2022-04-04 13:25:07 +00:00
async function hideMarkdownPreview() {
const setting = await readSettings({ previewOnRHS: true });
2022-10-14 13:53:51 +00:00
await editor.hidePanel(setting.previewOnRHS ? "rhs" : "lhs");
2022-04-04 13:25:07 +00:00
}