Node.js usage
Peisar’s main Node.js package is the native addon published as peisar.
Use it in Node.js servers, scripts, build tools, and frameworks that can load
native .node binaries.
This page is the Node.js overview. Use it as the entry point for framework, runtime, and API-specific guides.
At a glance
- Package:
peisar - Module surface:
require("peisar")orimport ... from "peisar" - Runtime requirement: see the
engines.nodefield in the root package.json - Browser and WASI runtimes: see WASM
- Full API details: see Node.js API reference
For browser-only runtimes or environments that cannot load native addons, use the WebAssembly package documented in WASM.
Install
npm i peisar
Basic usage
const { Peisar } = require("peisar");
const document = new Peisar(
`---
title: Hello
---
# Hello **world**`,
{ fragment: true },
);
console.log(document.html);
console.log(document.frontmatter);
Current API structure
The Node.js API in the peisar namespace currently centers around these
classes and properties:
| Export | Purpose |
|---|---|
Peisar | Parse one Markdown document and read ast, html, or frontmatter |
PeisarAst | Parse a document and read its AST or frontmatter without rendering |
document.frontmatter | Read the detected frontmatter type and raw contents |
Frontmatter is returned as { frontmatterType, raw }. The type is "Yaml",
"Toml", "Json", or "Empty"; Peisar does not deserialize the raw content.
See the API reference for the formats and shape.
Detailed signatures and option shapes are in the Node.js API reference.
Preferred extension API
Use Peisar.use() for Node.js integrations. A plugin may provide any
combination of:
visitBlockvisitInlineparseBlockparseInline
const { Peisar } = require("peisar");
const document = new Peisar("# Hello", { fragment: true });
document.use({
visitBlock([block]) {
if (block.type === "Heading") {
return { recurse: true };
}
},
});