Running Markdoc on Deno
January 25th, 2023
Markdoc is imported using an
import statement with a
import Markdoc from "npm:@markdoc/markdoc";
Deno's file system API is used to read and write files, while Markdoc is used to render the content:
const source = await Deno.readTextFile("./index.md"); const ast = Markdoc.parse(source); const content = Markdoc.transform(ast); const html = Markdoc.renderers.html(content); await Deno.writeTextFile("./index.html", html);
Here's a breakdown of the code above:
- Read a Markdown file with Deno.readTextFile.
- Parse the string into an abstract syntax tree with Markdoc.parse.
- Transform the abstract syntax tree into a renderable tree with Markdoc.transform.
- Render the renderable tree into a HTML document as a string with Markdoc.html.
- Output to a HTML file with Deno.writeTextFile.