Massive restructure of plugin API

This commit is contained in:
Zef Hemel
2022-10-14 15:11:33 +02:00
parent 982623fc38
commit 7d28b53b75
70 changed files with 826 additions and 969 deletions
+2
View File
@@ -1,6 +1,8 @@
name: markdown
imports:
- https://get.silverbullet.md/global.plug.json
assets:
- styles.css
functions:
toggle:
path: "./markdown.ts:togglePreview"
+5 -7
View File
@@ -1,13 +1,11 @@
import { hideLhs, hideRhs } from "../../syscall/silverbullet-syscall/editor.ts";
import { invokeFunction } from "../../syscall/silverbullet-syscall/system.ts";
import * as clientStore from "../../syscall/silverbullet-syscall/clientStore.ts";
import { readSettings } from "../lib/settings_page.ts";
import { clientStore, editor, system } from "$sb/silverbullet-syscall/mod.ts";
import { readSettings } from "$sb/lib/settings_page.ts";
export async function togglePreview() {
let currentValue = !!(await clientStore.get("enableMarkdownPreview"));
const currentValue = !!(await clientStore.get("enableMarkdownPreview"));
await clientStore.set("enableMarkdownPreview", !currentValue);
if (!currentValue) {
await invokeFunction("client", "preview");
await system.invokeFunction("client", "preview");
} else {
await hideMarkdownPreview();
}
@@ -15,6 +13,6 @@ export async function togglePreview() {
async function hideMarkdownPreview() {
const setting = await readSettings({ previewOnRHS: true });
const hide = setting.previewOnRHS ? hideRhs : hideLhs;
const hide = setting.previewOnRHS ? editor.hideRhs : editor.hideLhs;
await hide();
}
+11 -67
View File
@@ -1,69 +1,10 @@
import MarkdownIt from "https://esm.sh/markdown-it@13.0.1";
import {
getText,
showPanel,
} from "../../syscall/silverbullet-syscall/editor.ts";
import * as clientStore from "../../syscall/silverbullet-syscall/clientStore.ts";
import { cleanMarkdown } from "./util.ts";
const css = `
<style>
body {
font-family: georgia,times,serif;
font-size: 14pt;
max-width: 800px;
margin-left: auto;
margin-right: auto;
padding-left: 20px;
padding-right: 20px;
}
table {
width: 100%;
border-spacing: 0;
}
thead tr {
background-color: #333;
color: #eee;
}
th, td {
padding: 8px;
}
tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
a[href] {
text-decoration: none;
}
blockquote {
border-left: 1px solid #333;
margin-left: 2px;
padding-left: 10px;
}
hr {
margin: 1em 0 1em 0;
text-align: center;
border-color: #777;
border-width: 0;
border-style: dotted;
}
hr:after {
content: "···";
letter-spacing: 1em;
}
</style>
`;
import taskLists from "https://esm.sh/markdown-it-task-lists@2.1.1";
import { clientStore, editor } from "$sb/silverbullet-syscall/mod.ts";
import { asset } from "$sb/plugos-syscall/mod.ts";
import { cleanMarkdown } from "./util.ts";
const md = new MarkdownIt({
linkify: true,
html: false,
@@ -74,11 +15,14 @@ export async function updateMarkdownPreview() {
if (!(await clientStore.get("enableMarkdownPreview"))) {
return;
}
let text = await getText();
let cleanMd = await cleanMarkdown(text);
await showPanel(
const text = await editor.getText();
const cleanMd = await cleanMarkdown(text);
const css = await asset.readAsset("styles.css");
await editor.showPanel(
"rhs",
2,
`<html><head>${css}</head><body>${md.render(cleanMd)}</body></html>`,
`<html><head><style>${css}</style></head><body>${
md.render(cleanMd)
}</body></html>`,
);
}
+51
View File
@@ -0,0 +1,51 @@
<style>
body {
font-family: georgia,times,serif;
font-size: 14pt;
max-width: 800px;
margin-left: auto;
margin-right: auto;
padding-left: 20px;
padding-right: 20px;
}
table {
width: 100%;
border-spacing: 0;
}
thead tr {
background-color: #333;
color: #eee;
}
th, td {
padding: 8px;
}
tbody tr:nth-of-type(even) {
background-color: #f3f3f3;
}
a[href] {
text-decoration: none;
}
blockquote {
border-left: 1px solid #333;
margin-left: 2px;
padding-left: 10px;
}
hr {
margin: 1em 0 1em 0;
text-align: center;
border-color: #777;
border-width: 0;
border-style: dotted;
}
hr:after {
content: "···";
letter-spacing: 1em;
}
+3 -3
View File
@@ -2,8 +2,8 @@ import {
findNodeOfType,
renderToText,
replaceNodesMatching,
} from "../../common/tree.ts";
import { parseMarkdown } from "../../syscall/silverbullet-syscall/markdown.ts";
} from "$sb/lib/tree.ts";
import { markdown } from "$sb/silverbullet-syscall/mod.ts";
export function encodePageUrl(name: string): string {
return name.replaceAll(" ", "_");
@@ -13,7 +13,7 @@ export async function cleanMarkdown(
text: string,
validPages?: string[],
): Promise<string> {
const mdTree = await parseMarkdown(text);
const mdTree = await markdown.parseMarkdown(text);
replaceNodesMatching(mdTree, (n) => {
if (n.type === "WikiLink") {
const page = n.children![1].children![0].text!;