diff --git a/packages/plugos/compile.ts b/packages/plugos/compile.ts index 9c1a2c27..16c14983 100644 --- a/packages/plugos/compile.ts +++ b/packages/plugos/compile.ts @@ -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", diff --git a/packages/plugos/syscalls/fs.node.ts b/packages/plugos/syscalls/fs.node.ts index a0f077c7..bfec017d 100644 --- a/packages/plugos/syscalls/fs.node.ts +++ b/packages/plugos/syscalls/fs.node.ts @@ -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 => { let p = resolvedPath(filePath); + await mkdir(path.dirname(p), { recursive: true }); await writeFile(p, text); let s = await stat(p); return { diff --git a/packages/plugs/lib/yaml_page.ts b/packages/plugs/lib/yaml_page.ts index c0deaafe..efa29472 100644 --- a/packages/plugs/lib/yaml_page.ts +++ b/packages/plugs/lib/yaml_page.ts @@ -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 { + const text = YAML.stringify(data); + await writePage(pageName, "```yaml\n" + text + "\n```"); +} diff --git a/packages/plugs/markdown/util.ts b/packages/plugs/markdown/util.ts index 739e568d..659fda2a 100644 --- a/packages/plugs/markdown/util.ts +++ b/packages/plugs/markdown/util.ts @@ -9,20 +9,38 @@ export function encodePageUrl(name: string): string { return name.replaceAll(" ", "_"); } -export async function cleanMarkdown(text: string): Promise { +export async function cleanMarkdown( + text: string, + validPages?: string[] +): Promise { 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) {