22 lines
835 B
TypeScript
22 lines
835 B
TypeScript
|
import { markdown, space } from "$sb/silverbullet-syscall/mod.ts";
|
||
|
import { fs } from "$sb/plugos-syscall/mod.ts";
|
||
|
import { asset } from "$sb/plugos-syscall/mod.ts";
|
||
|
import type { PublishEvent } from "../share/publish.ts";
|
||
|
import { renderMarkdownToHtml } from "./markdown_render.ts";
|
||
|
|
||
|
export async function sharePublisher(event: PublishEvent) {
|
||
|
const path = event.uri.split(":")[1];
|
||
|
const pageName = event.name;
|
||
|
const text = await space.readPage(pageName);
|
||
|
const tree = await markdown.parseMarkdown(text);
|
||
|
|
||
|
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");
|
||
|
return true;
|
||
|
}
|