@lediv/html
v0.3.0
Published
HTML parser, serializer, and template evaluator for Lediv
Maintainers
Readme
@lediv/html
HTML parser, serializer, and template evaluator for Lediv. Parses component-aware HTML, resolves component trees, evaluates template expressions, and serializes back to HTML strings.
You probably want @lediv/vite-plugin. This package is published because @lediv/build and the plugin depend on it, not because it is meant to be called directly.
Usage
npm install @lediv/htmlimport { parseRaw, serializeNode, buildPageFromSource } from '@lediv/html';
const nodes = parseRaw('<p class="intro">Hello</p>');
const html = nodes.map(serializeNode).join('');
const page = buildPageFromSource(pageSource, {
readComponent: (name) => components.get(name) ?? null,
});parseRaw returns AnyNode[] (from domhandler). buildPageFromSourceDetailed returns the same HTML plus the MountRuntimeScript objects describing each component's inline mount code.
The template language itself, the expressions and the loops and conditionals it supports, is documented at https://lediv.com/docs/expressions.
Budgets
Building a page is bounded, because template expansion can turn a few hundred bytes of source into gigabytes of HTML and kill the process. A page may render at most 30,000 element instances, nest components at most 64 levels deep, and produce at most MAX_PAGE_OUTPUT_CHARS (4,000,000) characters unless the caller passes its own maxOutputChars or a shared outputBudget. Passing any of them throws BuildPageError.
Errors
Every failure is a BuildPageError carrying a code. The codes, the options, the result shapes and the exported helpers all ship with type definitions; read those rather than a table here that can go stale.
License
MIT
