Nuedom is the rendering engine at the core of Nue. It takes HTML-extended templates, parses them into an AST, optionally compiles that AST to JavaScript, and renders the result to an HTML string. The package exposes four named exports that map directly to each stage of that pipeline.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/nuejs/nue/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Exports
parseNue(template)
Parses an HTML template string into a structured document object (AST). This is the first step in the pipeline — it tokenizes the source, resolves script blocks, detects component types, and returns metadata that the subsequent stages rely on.
The raw HTML template string. May include
<!doctype>, <script> blocks, YAML front-matter, and custom element tags.| Property | Type | Description |
|---|---|---|
lib | Array | Array of AST nodes, one per top-level element |
root | object | The first node in lib — the primary component |
script | string | Concatenated content of all <script> blocks |
doctype | string | Value from <!doctype …> if present |
is_lib | boolean | true when the file contains only named/custom components |
is_dhtml | boolean | true when the template has event handlers or ES module imports |
meta | object | YAML front-matter data attached to the document or to a component |
compileNue(template)
Compiles a template string (or a pre-parsed document) into a JavaScript module source string. The output can be evaluated to obtain the component library array ready for runtime mounting.
Either the raw HTML template string or a document object previously returned by
parseNue. When a string is passed, parseNue is called internally.string of JavaScript source. The string exports a lib constant and, if the template had a <script> block, the script’s contents are prepended.
Example:
compileNue is primarily useful when you want to ship pre-compiled component libraries. For direct server-side rendering you can skip this step and call renderNue directly.renderNue(template, opts?)
The primary server-side rendering function. Accepts either a raw template string or a pre-parsed AST and returns an HTML string. This is what Nuekit calls internally to render every page and component.
The template to render. When a string is passed,
parseNue is called internally and the first component in lib is rendered. When an AST object is passed the function skips parsing.Optional rendering options.
string representing the rendered output of the root component.
Example:
createDocument()
Creates a minimal fake DOM environment used internally by renderNue during server-side rendering. The returned object implements enough of the browser document API — createElement, createTextNode, createDocumentFragment — for Nue’s rendering pipeline to work in a Node/Bun environment.
document object. Nodes created by this document serialize to HTML strings via innerHTML.
You rarely need to call
createDocument directly. renderNue sets global.document before rendering. The export exists for testing and for advanced use cases where you need to mount a Nue component into a custom document context.The pipeline
The three main functions form a linear pipeline. You can enter at any step:Parse — parseNue(template)
Tokenize the HTML string and build an AST. Extracts script blocks, resolves component names, and flags which features the template uses (event handlers, custom elements, etc.).
Compile — compileNue(doc)
Convert the AST into a JavaScript source string. Use this step when you want to pre-compile component libraries for delivery to the browser.
Template syntax reference
Nuedom extends plain HTML with a small set of directives. All directives live in attributes, keeping the template parseable as standard HTML.Data interpolation
Curly-brace expressions are evaluated against thedata object:
Event listeners
Prefix any event name with:on to attach a handler. The handler expression receives the event as $e:
Loops
Use:for to render a list of elements from an array:
Conditionals
Use:if, :else-if, and :else for conditional rendering:
Dynamic attributes
Prefix any attribute with: to evaluate its value as an expression:
Component composition
A file may contain multiple top-level elements. Non-script elements become entries inlib. Custom elements reference siblings by tag name: