kdlet-html
v0.3.1
Published
The HTML renderer for kdlet: a vocabulary and a function that writes a kdlet tree as an HTML string
Readme
The HTML renderer for kdlet, a template language written in KDL.
It brings HTML's words to the language and writes the evaluated tree as a string.
npm install kdlet kdlet-htmlguard featured { is (input)kind featured }
guard has-summary { has (input)summary }
article.teaser {
when featured class=is-featured
h2 (input)title
when has-summary { p.summary (input)summary }
}import { evaluate, read } from 'kdlet';
import { render, vocabulary } from 'kdlet-html';
const { tree } = evaluate(read(text), { vocabulary, inputs });
const html = render(tree, { doctype: true });What it does
- Classes on the name.
article.teaseris anarticlewith the classteaser. An id is writtenid=main. - Pug's attribute rules.
classandstyleadd; for every other attribute the later one wins.#truewrites a bare attribute;#falseand#nulldrop it. - Text. A node's arguments are its text, joined in order. A child named
-is text among child elements. - Everything is escaped. Text and attribute values, always. There is no raw output.
render throws a RenderError that lists every problem, each with its line and column.
Node 20 or later, ESM only.
Read next
- The manual: the language, and this renderer's own rules.
- The repository.
License
MIT.
