Tweaks
parent
799144a74e
commit
6fe05c1b13
|
@ -43,6 +43,10 @@ export async function compile(
|
|||
external: excludeModules,
|
||||
loader: {
|
||||
".css": "text",
|
||||
".md": "text",
|
||||
".txt": "text",
|
||||
".html": "text",
|
||||
".hbs": "text",
|
||||
".png": "dataurl",
|
||||
".gif": "dataurl",
|
||||
".jpg": "dataurl",
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { readdir, readFile, stat, writeFile, unlink } from "fs/promises";
|
||||
import { readdir, readFile, stat, writeFile, unlink, mkdir } from "fs/promises";
|
||||
import path from "path";
|
||||
import type { SysCallMapping } from "../system";
|
||||
|
||||
|
@ -46,6 +46,7 @@ export default function fileSystemSyscalls(root: string = "/"): SysCallMapping {
|
|||
text: string
|
||||
): Promise<FileMeta> => {
|
||||
let p = resolvedPath(filePath);
|
||||
await mkdir(path.dirname(p), { recursive: true });
|
||||
await writeFile(p, text);
|
||||
let s = await stat(p);
|
||||
return {
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
import { findNodeOfType, ParseTree, renderToText, replaceNodesMatching, traverseTree } from "@silverbulletmd/common/tree";
|
||||
import { findNodeOfType, traverseTree } from "@silverbulletmd/common/tree";
|
||||
import { parseMarkdown } from "@silverbulletmd/plugos-silverbullet-syscall/markdown";
|
||||
import { readPage, writePage } from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
||||
import {
|
||||
readPage,
|
||||
writePage,
|
||||
} from "@silverbulletmd/plugos-silverbullet-syscall/space";
|
||||
import YAML from "yaml";
|
||||
|
||||
export async function readYamlPage(
|
||||
|
@ -40,3 +43,11 @@ export async function readYamlPage(
|
|||
|
||||
return data;
|
||||
}
|
||||
|
||||
export async function writeYamlPage(
|
||||
pageName: string,
|
||||
data: any
|
||||
): Promise<void> {
|
||||
const text = YAML.stringify(data);
|
||||
await writePage(pageName, "```yaml\n" + text + "\n```");
|
||||
}
|
||||
|
|
|
@ -9,20 +9,38 @@ export function encodePageUrl(name: string): string {
|
|||
return name.replaceAll(" ", "_");
|
||||
}
|
||||
|
||||
export async function cleanMarkdown(text: string): Promise<string> {
|
||||
export async function cleanMarkdown(
|
||||
text: string,
|
||||
validPages?: string[]
|
||||
): Promise<string> {
|
||||
let mdTree = await parseMarkdown(text);
|
||||
replaceNodesMatching(mdTree, (n) => {
|
||||
if (n.type === "WikiLink") {
|
||||
const page = n.children![1].children![0].text!;
|
||||
if (validPages && !validPages.includes(page)) {
|
||||
return {
|
||||
// HACK
|
||||
text: `_${page}_`,
|
||||
};
|
||||
}
|
||||
return {
|
||||
// HACK
|
||||
text: `[${page}](/${encodePageUrl(page)})`,
|
||||
};
|
||||
}
|
||||
// Simply get rid of these
|
||||
if (n.type === "CommentBlock" || n.type === "Comment") {
|
||||
if (
|
||||
n.type === "CommentBlock" ||
|
||||
n.type === "Comment" ||
|
||||
n.type === "NamedAnchor"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
if (n.type === "Hashtag") {
|
||||
return {
|
||||
text: `__${n.children![0].text}__`,
|
||||
};
|
||||
}
|
||||
if (n.type === "FencedCode") {
|
||||
let codeInfoNode = findNodeOfType(n, "CodeInfo");
|
||||
if (!codeInfoNode) {
|
||||
|
|
Loading…
Reference in New Issue