···11-import Markdoc, { Config } from "@markdoc/markdoc";
11+import { Config } from "@markdoc/markdoc";
22import { createFenceNode } from "./nodes/fence.ts";
33+import type { Includes } from "./types.ts";
3445export function createMarkdocConfig() {
55- const scripts = new Set<string>();
66-66+ const includes: Includes = new Set();
77 const config: Config = {
88 tags: {
99 slide: {
···1414 },
1515 },
1616 nodes: {
1717- fence: createFenceNode(scripts),
1717+ fence: createFenceNode(includes),
1818 },
1919 };
20202121- return { scripts, config };
2121+ return { includes, config };
2222}
+13-7
core/nodes/fence.ts
···11-import Markdoc, { nodes, RenderableTreeNode, Tag } from "@markdoc/markdoc";
11+import {
22+ Config,
33+ Node,
44+ nodes,
55+ RenderableTreeNode,
66+ Schema,
77+ Tag,
88+} from "@markdoc/markdoc";
29import { codeToHast } from "shiki";
310import { isElement } from "hast-util-is-element";
44-import type { Node as HastNode } from "@types/hast";
1111+import type { Node as HastNode } from "hast";
1212+import type { Includes } from "../types.ts";
513614function hastToRenderNode(node: HastNode): RenderableTreeNode {
715 let tag: Tag;
···2735 return tag;
2836}
29373030-export function createFenceNode(scripts: Set<string>) {
3838+export function createFenceNode(includes: Includes): Schema {
3139 return {
3240 render: "pre",
3341 attributes: {
3442 content: { type: "String", render: false },
3543 language: { type: "String", render: false },
3644 },
3737- async transform(node: any, config: any) {
4545+ async transform(node: Node, config: Config) {
3846 const { content, language = "text" } = node.attributes;
39474048 if (language === "mermaid") {
4141- scripts.add(
4242- "https://cdn.jsdelivr.net/npm/mermaid@11.9.0/dist/mermaid.min.js",
4343- );
4949+ includes.add("mermaid");
44504551 // Bail out for Mermaid to handle later
4652 const base = (nodes.fence.transform!)(node, config);
+15-27
core/renderer.ts
···11import Markdoc, { Node } from "@markdoc/markdoc";
22import { createMarkdocConfig } from "./markdoc-config.ts";
33import { Eta } from "@eta-dev/eta";
44+import type { RenderOptions } from "./types.ts";
4556const eta = new Eta({ views: Deno.cwd() + "/templates" });
6777-export async function renderBody(path: string) {
88+export async function renderPresentationHtml(
99+ path: string,
1010+ options?: RenderOptions,
1111+) {
812 const file = await Deno.readTextFile(path);
913 const ast = Markdoc.parse(file);
1014···2832 ], "slide")
2933 );
30343131- const { config, scripts } = createMarkdocConfig();
3535+ const { config, includes } = createMarkdocConfig();
3236 const tree = Markdoc.transform(ast, config);
33373434- return {
3535- scripts,
3636- body: Markdoc.renderers.html(await Promise.resolve(tree)),
3737- };
3838-}
3838+ if (options?.devMode) {
3939+ includes.add("live-reload");
4040+ }
39414040-export async function buildStatic(sourcePath: string, outputDir: string) {
4141- // Ensure output directory exists
4242- await Deno.mkdir(outputDir, { recursive: true });
4343-4444- // Get the presentation title from the first heading
4545- const sourceContent = await Deno.readTextFile(sourcePath);
4646- const titleMatch = sourceContent.match(/^# (.+)$/m);
4242+ const titleMatch = file.match(/^# (.+)$/m);
4743 const title = titleMatch ? titleMatch[1] : "Presentation";
4848-4949- // Render the presentation
5050- const { body, scripts } = await renderBody(sourcePath);
5151-5252- // Generate static HTML
5353- const html = eta.render("static", {
5454- body,
5555- scripts: Array.from(scripts),
5656- title
4444+4545+ return eta.render("presentation", {
4646+ body: Markdoc.renderers.html(await Promise.resolve(tree)),
4747+ title,
4848+ includes,
5749 });
5858-5959- // Write to output file
6060- const outputPath = `${outputDir}/index.html`;
6161- await Deno.writeTextFile(outputPath, html);
6250}
+8
core/types.ts
···11+export interface RenderOptions {
22+ devMode?: boolean;
33+}
44+55+// String identifiers for output partials; things like CDN links, styles, and web components
66+export type Includes = Set<
77+ "live-reload" | "mermaid"
88+>;