Monorepo with yarn workspaces requires yarn 3.2

This commit is contained in:
Zef Hemel
2022-04-21 13:57:45 +02:00
parent 32f3501773
commit 1f842ec1d6
167 changed files with 10424 additions and 8263 deletions
@@ -0,0 +1,14 @@
functions:
toggle:
path: "./markdown.ts:togglePreview"
command:
name: "Toggle Markdown Preview"
key: Ctrl-p
mac: Cmd-p
preview:
path: "./preview.ts:updateMarkdownPreview"
env: client
events:
- plug:load
- editor:updated
- editor:pageSwitched
+18
View File
@@ -0,0 +1,18 @@
import { hideRhs } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import { invokeFunction } from "@silverbulletmd/plugos-silverbullet-syscall/system";
import * as clientStore from "@silverbulletmd/plugos-silverbullet-syscall/clientStore";
export async function togglePreview() {
let currentValue = !!(await clientStore.get("enableMarkdownPreview"));
await clientStore.set("enableMarkdownPreview", !currentValue);
if (!currentValue) {
await invokeFunction("client", "preview");
// updateMarkdownPreview();
} else {
await hideMarkdownPreview();
}
}
async function hideMarkdownPreview() {
await hideRhs();
}
+80
View File
@@ -0,0 +1,80 @@
import MarkdownIt from "markdown-it";
import { getText, showRhs } from "@silverbulletmd/plugos-silverbullet-syscall/editor";
import * as clientStore from "@silverbulletmd/plugos-silverbullet-syscall/clientStore";
import { cleanMarkdown } from "./util";
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>
`;
var taskLists = require("markdown-it-task-lists");
const md = new MarkdownIt({
linkify: true,
html: false,
typographer: true,
}).use(taskLists);
export async function updateMarkdownPreview() {
if (!(await clientStore.get("enableMarkdownPreview"))) {
return;
}
let text = await getText();
let cleanMd = await cleanMarkdown(text);
await showRhs(
`<html><head>${css}</head><body>${md.render(cleanMd)}</body></html>`,
2
);
}
+33
View File
@@ -0,0 +1,33 @@
import { findNodeOfType, renderToText, replaceNodesMatching } from "@silverbulletmd/common/tree";
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
export function encodePageUrl(name: string): string {
return name.replaceAll(" ", "_");
}
export async function cleanMarkdown(text: string): Promise<string> {
let mdTree = await parseMarkdown(text);
replaceNodesMatching(mdTree, (n) => {
if (n.type === "WikiLink") {
const page = n.children![1].children![0].text!;
return {
// HACK
text: `[${page}](/${encodePageUrl(page)})`,
};
}
// Simply get rid of these
if (n.type === "CommentBlock" || n.type === "Comment") {
return null;
}
if (n.type === "FencedCode") {
let codeInfoNode = findNodeOfType(n, "CodeInfo");
if (!codeInfoNode) {
return;
}
if (codeInfoNode.children![0].text === "meta") {
return null;
}
}
});
return renderToText(mdTree);
}