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
| Export | Purpose |
|---|---|
page | Create an HTML document from an options object |
document | Alias for page |
element | Create an element with optional attributes |
meta | Create curated SEO/social metadata |
link | Create a navigation link |
escape | HTML-escape a value |
style | Wrap CSS source |
script | Wrap JavaScript source |
render | Substitute 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
page(options)/document(options): options include title, body, css, js and lang.element(tag, text, attrs?): optional attributes are filtered through an allowlist plus validateddata-*andaria-*attributes.meta(name, content): supports a curated set of SEO/social metadata names.link(label, href): creates a link element.escape(value): HTML-escapes dynamic text.style(css)/script(js): wrap trusted CSS or JavaScript.render(template, data): substitutes data values into template placeholders and escapes inserted values.
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.
greenServeFE