Enable writing on the settings page from plugs

This commit is contained in:
Guillermo Vaya
2022-07-23 19:18:03 +02:00
parent 88121da341
commit dd3cfd8e98
5 changed files with 102 additions and 8 deletions
@@ -14,3 +14,7 @@ functions:
- editor:updated
- editor:pageLoaded
- editor:pageReloaded
switchSide:
path: "./preview.ts:switchSide"
command:
name: "Swith Preview to other Sidebar"
+6 -2
View File
@@ -1,6 +1,8 @@
import { hideRhs } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import { hideRhs, hideLhs } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import { invokeFunction } from "@silverbulletmd/plugos-silverbullet-syscall/system";
import * as clientStore from "@silverbulletmd/plugos-silverbullet-syscall/clientStore";
import { readSettings, writeSettings } from "@silverbulletmd/plugs/lib/settings_page";;
export async function togglePreview() {
let currentValue = !!(await clientStore.get("enableMarkdownPreview"));
@@ -13,5 +15,7 @@ export async function togglePreview() {
}
async function hideMarkdownPreview() {
await hideRhs();
const setting = await readSettings({previewOnRHS: true});
const hide = setting.previewOnRHS ? hideRhs : hideLhs;
await hide();
}
+23 -1
View File
@@ -1,10 +1,14 @@
import MarkdownIt from "markdown-it";
import {
getText,
showLhs,
showRhs,
hideRhs,
hideLhs,
} from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import * as clientStore from "@silverbulletmd/plugos-silverbullet-syscall/clientStore";
import { cleanMarkdown } from "./util";
import { readSettings, writeSettings } from "@silverbulletmd/plugs/lib/settings_page";
const css = `
<style>
@@ -76,9 +80,27 @@ export async function updateMarkdownPreview() {
}
let text = await getText();
let cleanMd = await cleanMarkdown(text);
await showRhs(
const setting = await readSettings({previewOnRHS: true});
const show = setting.previewOnRHS ? showRhs : showLhs;
await show(
`<html><head>${css}</head><body>${md.render(cleanMd)}</body></html>`,
undefined,
2
);
}
export async function switchSide() {
const {previewOnRHS} = await readSettings({previewOnRHS: true});
const isVisible = await clientStore.get("enableMarkdownPreview");
if (isVisible) {
if (previewOnRHS){
hideRhs();
} else {
hideLhs();
}
}
await writeSettings({previewOnRHS: !previewOnRHS});
if (isVisible) {
updateMarkdownPreview();
}
}