silverbullet/packages/plugs/markdown/markdown.ts

21 lines
771 B
TypeScript
Raw Normal View History

2022-10-06 21:14:21 +08:00
import { hideLhs, hideRhs } from "../../plugos-silverbullet-syscall/editor.ts";
import { invokeFunction } from "../../plugos-silverbullet-syscall/system.ts";
import * as clientStore from "../../plugos-silverbullet-syscall/clientStore.ts";
import { readSettings } from "../lib/settings_page.ts";
2022-03-28 21:25:05 +08:00
2022-04-04 21:25:07 +08:00
export async function togglePreview() {
let currentValue = !!(await clientStore.get("enableMarkdownPreview"));
await clientStore.set("enableMarkdownPreview", !currentValue);
if (!currentValue) {
await 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() {
2022-10-06 21:14:21 +08:00
const setting = await readSettings({ previewOnRHS: true });
const hide = setting.previewOnRHS ? hideRhs : hideLhs;
await hide();
2022-04-04 21:25:07 +08:00
}