greenServeFEgreenServeFE

Documentation home / Reference

Reference documentation

GSVE Construct HTML Generation API

Build HTML documents, semantic elements, metadata, links, CSS, JavaScript and escaped templates from GSVE programs.

Overview

The native construct.so module builds HTML strings from GSVE programs. It generates complete documents, elements, metadata, links, CSS and JavaScript blocks, and performs template substitutions.

Exports

ExportPurpose
pageCreate an HTML document from an options object
documentAlias for page
elementCreate an element with optional attributes
metaCreate curated SEO/social metadata
linkCreate a navigation link
escapeHTML-escape a value
styleWrap CSS source
scriptWrap JavaScript source
renderSubstitute template placeholders using data

Create a page

import construct;
define body = construct.element("h1", "Hello from GSVE") +
    construct.element("p", "Generated HTML from a GSVE program.") +
    construct.link("About", "/about");
define html = construct.page({
    title: "My greenServeFE site",
    body: "<main>" + body + "</main>",
    css: "main{padding:1rem}",
    js: "console.log('GSVE page loaded');",
    lang: "en"
});
print(html);

API details

Escaping and trust boundary

Titles, element text, link labels and URLs, metadata values and template substitutions are escaped. The page's body, CSS and JavaScript fields are raw insertion points for trusted source. Event-handler attributes are not accepted. URL-bearing attributes reject unsafe schemes. Void tags such as input, img and br are emitted without closing tags.

Serve generated HTML

import construct;
import server;
define html = construct.page({title: "Home", body: "<h1>Welcome</h1>"});
func home(req, res) { res.html(html); }
server.get("/", home);
server.serve(".", 8080, {static: false, host: "0.0.0.0"});
Only put trusted markup, CSS and JavaScript into raw page slots. Escaping dynamic values does not make arbitrary raw markup or scripts safe.

Related: HTTP server routes and responses.