Sync engine (#298)

Fixes #261
This commit is contained in:
Zef Hemel
2023-01-13 15:41:29 +01:00
committed by GitHub
parent de6f531e91
commit a56e14bff1
51 changed files with 1033 additions and 1418 deletions
+3 -3
View File
@@ -24,14 +24,14 @@ functions:
path: "./preview.ts:previewClickHandler"
env: client
events:
- preview:click
- preview:click
# $share: file:* publisher for markdown files
sharePublisher:
path: ./share.ts:sharePublisher
events:
- share:file
- share:file
markdownWidget:
path: ./widget.ts:markdownWidget
codeWidget: markdown
codeWidget: markdown
+4 -2
View File
@@ -1,5 +1,5 @@
import { markdown, space } from "$sb/silverbullet-syscall/mod.ts";
import { fs } from "$sb/plugos-syscall/mod.ts";
import { LocalFileSystem } from "$sb/plugos-syscall/mod.ts";
import { asset } from "$sb/plugos-syscall/mod.ts";
import { renderMarkdownToHtml } from "./markdown_render.ts";
import { PublishEvent } from "$sb/app_event.ts";
@@ -10,12 +10,14 @@ export async function sharePublisher(event: PublishEvent) {
const text = await space.readPage(pageName);
const tree = await markdown.parseMarkdown(text);
const rootFS = new LocalFileSystem("");
const css = await asset.readAsset("assets/styles.css");
const markdownHtml = renderMarkdownToHtml(tree, {
smartHardBreak: true,
});
const html =
`<html><head><style>${css}</style></head><body><div id="root">${markdownHtml}</div></body></html>`;
await fs.writeFile(path, html, "utf8");
await rootFS.writeFile(path, html, "utf8");
return true;
}