silverbullet/plugs/markdown/markdown.ts

19 lines
623 B
TypeScript
Raw Normal View History

2023-08-28 23:12:15 +08:00
import { clientStore, editor } from "$sb/syscalls.ts";
2022-10-14 21:11:33 +08:00
import { readSettings } from "$sb/lib/settings_page.ts";
import { updateMarkdownPreview } from "./preview.ts";
2022-03-28 21:25:05 +08:00
2022-04-04 21:25:07 +08:00
export async function togglePreview() {
2023-08-26 14:31:51 +08:00
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
await clientStore.set("enableMarkdownPreview", !currentValue);
2022-04-04 21:25:07 +08:00
if (!currentValue) {
await updateMarkdownPreview();
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:53:51 +08:00
await editor.hidePanel(setting.previewOnRHS ? "rhs" : "lhs");
2022-04-04 21:25:07 +08:00
}