Files
el/lang/examples/html-page.el
T
2026-05-05 01:38:51 -05:00

41 lines
1.2 KiB
EmacsLisp

// html-page.el Example of native HTML template syntax in El.
//
// El HTML templates let you write HTML directly in expression position.
// Interpolated values are automatically HTML-escaped.
// Use raw(expr) to bypass escaping when you know the content is safe.
//
// Compile and run:
// ./dist/platform/elc examples/html-page.el > /tmp/html-page.c
// cc -std=c11 -I el-compiler/runtime -lcurl -lpthread \
// -o /tmp/html-page /tmp/html-page.c el-compiler/runtime/el_runtime.c
// /tmp/html-page
fn render_item(item: String) -> String {
return <li class="item">{item}</li>
}
fn render_page(title: String, items: [String]) -> String {
return <!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>{title}</title>
</head>
<body>
<h1>{title}</h1>
<ul>
{#each items as item}
<li class="item">{item}</li>
{/each}
</ul>
<p>Built with El HTML templates</p>
</body>
</html>
}
fn main() -> Void {
let items: [String] = ["Lexer", "Parser", "Codegen", "Runtime"]
let page: String = render_page("El Compiler Stages", items)
println(page)
}