1
0
silverbullet/plugs/markdown/markdown.ts

18 lines
612 B
TypeScript
Raw Normal View History

2022-10-14 13:11:33 +00:00
import { clientStore, editor, system } from "$sb/silverbullet-syscall/mod.ts";
import { readSettings } from "$sb/lib/settings_page.ts";
2022-03-28 13:25:05 +00:00
2022-04-04 13:25:07 +00:00
export async function togglePreview() {
2022-10-14 13:11:33 +00:00
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
2022-04-04 13:25:07 +00:00
await clientStore.set("enableMarkdownPreview", !currentValue);
if (!currentValue) {
2022-10-14 13:11:33 +00:00
await system.invokeFunction("client", "preview");
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
}