@core/html gives you compile-time HTML helpers. The constants fold into HTML strings during compilation and produce no runtime code.
Using helpers in .mtf files
.mtf files see @core/html and @core/css constants without a dependency clause. The compiler supplies the official packages/core/html and packages/core/css packages through their @package.moth facades. You can use the helpers directly:
-- docs/intro.mtf
[p: A paragraph.]
[codeblock, $code "moth": value = 42]
The prelude supplies @core/html and @core/css constants only. Your own values need a qualified reference to a helper file. A template head names the helper path and one selected value, for example @settings then site_name. Root files never expose their declarations to a template.
Binding helpers in .moth files
.moth files need an explicit dependency clause to use @core/html symbols.
@core/html table, th, td
Available helpers
p, h1 through h6, small, large, div, span for structurecanvas for <canvas> elements with id and style slotsbold, italic, underline, strikethrough for formattingcodeblock, table, th, td for code and tablesimg for images with src, alt and style slots
The six basic style inserts (center, right, left, smaller, medium, larger) belong to @core/css. They are available bare inside .mtf files and need an explicit import in .moth files, such as @core/css center. See @core/css for the fragments and the slots they fill.
$code code blocks
$code highlights a balanced template body as a code block. The compiler owns the directive and its formatter, so it works under every builder, not only the HTML one.
[codeblock, $code "moth": value = 42]
Supported aliases: text/txt, html, markdown/md, toml, json, yaml/yml, css, c, sql, moth, javascript/js, typescript/ts, python/py, rust/rs, bash/sh/shell.
$code escapes HTML and applies lexical presentation only. Dynamic expression anchors pass through sealed. It never checks the snippet or reports errors. All profiles share the same palette.
Canvas
@core/html provides the <canvas> markup helper. Browser drawing is provided by @builder/web/canvas and is available only when the builder supports the browser runtime.
@builder/web/canvas get_canvas, context_2d, set_fill_style, fill_rect
element = get_canvas("my-canvas")!
context ~= context_2d(element)!
set_fill_style(~context, "red")
fill_rect(~context, 10.0, 10.0, 50.0, 50.0)
For the full export surface and deferred additions, see @core/html advanced.
@core/html provides compile-time HTML markup helpers as a universal Core package with MothSource backing. It publishes through a directly contained @package.moth, and the compiler reads ordinary Moth source from packages/core/html/@package.moth. See Package origins and backing for origin and backing rules.
@core/html ships as a skeleton. Its exports cover common HTML tags, formatting helpers and table components. Basic style inserts belong to @core/css, while browser drawing stays in the builder-specific @builder/web/canvas package.
The fixed template prelude
Compile-time constants from @core/html and @core/css are visible flat inside .mtf files without an explicit dependency clause. This is the fixed template prelude.
[p: A paragraph built from the @core/html p helper.]
[codeblock, $code "moth": value = 42]
The prelude is compiler policy, not builder configuration. Every builder receives the official @core/html and @core/css Core roots, and .mtf is compiler-supported under every builder. Both packages precede every .mtf consumer.
A .moth file that needs specific @core/html symbols binds them explicitly:
@core/html table, th, td
A .mtf file has no implicit module facade constants. Reach any helper value with a qualified reference that names the helper path and one selected symbol, or move the shared value into a helper the template can select. Root-local declarations in @mod.moth, @package.moth and @entry.moth stay invisible. See Template scope for the full template scope contract.
A qualified selection introduces no local binding, so it never collides with a prelude name. A real local binding that matches a prelude name still fails with an ordinary visible-name collision.
Exported constants
All helpers are compile-time #String constants that produce HTML strings. They fold at compile time and produce no runtime code.
HTML tags
Helper | Produces |
p | <p> paragraph |
h1 through h6 | heading levels |
small | <small> text |
large | <large> text |
img | <img> with src, alt and style slots |
div | <div> container |
span | <span> inline container |
canvas | <canvas> with id and style slots |
Formatting helpers
Helper | Produces |
bold | <b> bold text |
italic | <i> italic text |
underline | <u> underlined text |
strikethrough | <s> strikethrough text |
Code and tables
Helper | Produces |
codeblock | <pre> code block |
table | styled <table> with header and row slots |
th | <th scope="col"> header cell |
td | <td> data cell |
Utility style inserts from @core/css
The style slots exposed by the helpers above accept the six inline fragments from the separate @core/css Core package, including center and larger. See @core/css for the export table and prelude rules.
The $code directive
$code renders a balanced template body as an HTML code block with lexical highlighting. The compiler owns the directive and its formatter, so it is available under every builder, not only the HTML one.
Supported aliases:
text / txthtmlmarkdown / mdtomljsonyaml / ymlcsscsqlmothjavascript / jstypescript / tspython / pyrust / rsbash / sh / shell
[codeblock, $code "moth":
render |name String| -> String:
return ["Hello, ", name]
;
]
$code escapes HTML-sensitive characters and wraps the body in <code class='codeblock'>. Dynamic expression anchors pass through as sealed content without highlighting or escaping. Highlighting is lexical presentation only. It never validates the snippet, resolves names or reports diagnostics. Every language profile shares the same general role palette, and the Moth profile uses the compiler-owned source-word classification plus bounded lexical roles for contracts, functions, directives, dependency paths and the io namespace. Moth template bodies stay plain authored text around their highlighted heads and nested templates. A body is not re-highlighted by the directive that will format it.
Browser drawing
The canvas markup helper remains in @core/html. Drawing functions and opaque canvas handles belong to @builder/web/canvas, which a web-capable builder must provide.
@builder/web/canvas get_canvas, context_2d, set_fill_style, fill_rect
element = get_canvas("my-canvas")!
context ~= context_2d(element)!
set_fill_style(~context, "red")
fill_rect(~context, 10.0, 10.0, 50.0, 50.0)
Backend behaviour
The compile-time constants need no runtime assets. They fold into HTML strings during compilation.
Calls to @builder/web/canvas emit JavaScript runtime assets when reachable. See @builder/web/canvas for the runtime asset contract.
Unsupported source forms
- Direct symbol-path clauses such as
@core/html/p face rejection. Use direct selections or a namespace clause. @core/html exposes no runtime canvas types. Canvas2d comes from @builder/web/canvas.- Only compile-time constants are visible inside
.mtf files. Functions and types require an explicit dependency clause in .moth files.
Deferred surfaces
@core/html ships as a skeleton. Future expansions include richer semantic tag coverage and standard slots. Higher-level layouts, components and additional style systems belong in separate packages. See progress matrix for current status.
Related concepts