v0.1A scripting language for the web
Standard Library

html

Build HTML pages with function calls. Each builder returns a string you can compose into larger documents.

Import:

import "html";

The builder pattern

Every element function takes one object argument. Inside it you can pass two fields: children (an array) and attributes (an object).

h1({
    children: ["Hello, world"],
    attributes: { class: "text-2xl font-bold" }
});

Children can be strings or other element calls, so you can nest:

div({
    children: [
        h1({ children: ["Title"] }),
        p({ children: ["Some prose."] })
    ]
});

Built-in elements

Each of these is a function with the same signature as h1 above:

htmlheadbodydivspanpah1h2h3h4h5h6imgformbuttonvideoscript

element

If a tag does not have a dedicated builder, fall back to element. Pass the tag name as the first argument and the same options object as the second:

element("ul", {
    children: [
        element("li", { children: ["First"] }),
        element("li", { children: ["Second"] })
    ]
});

router

Match an incoming request path against a map of routes. Returns the matched body, or the string "404" if nothing matches.

send_html(client, router(req, {
    "/": home(),
    "/about": about()
}));

Tips

Element builders return plain strings. You can store them in variables, pass them between functions, and compose them like any other value.

There is no virtual DOM and no escaping — the strings you provide are emitted verbatim. If you want to render user input safely, escape it before passing it in.