Roc Solid
Markup in Roc · pages on a native server · components in WebAssembly

Syntax

Markup wherever an expression can stand

A .rocx file is Roc with markup (HTML elements and components) wherever an expression can stand; inside markup, braces take you back to Roc. rocx turns markup into calls to the platform's Html module, so every .rocx file has import pf.Html. Each example is a real file in site/examples, shown with its output; its switch shows the Roc rocx wrote.

One small component#

Signals, a memo, handlers, holes, keyed rows, an if and a scoped style, each explained below. Type a title and press Enter, or tick a book off.

  • Dune
  • Emma

2 to read

site/Demos/SyntaxTour.rocx
import pf.Html
import pf.Solid exposing [create_memo!, create_signal!]

## A reading list: type a title and press Enter, tick a book off.
SyntaxTour := [].{
	view! : {} => Html
	view! = |{}| {
		book = |id, title| { id, title, done: Bool.False }
		(books!, set_books!) = create_signal!([book(1, "Dune"), book(2, "Emma")])
		(draft!, set_draft!) = create_signal!("")
		left! = create_memo!(|| books!().count_if(|b| !b.done))

		add! = || {
			if !draft!().is_empty() {
				set_books!(books!().append(book(books!().len() + 1, draft!())))
				set_draft!("")
			}
		}
		tick! = |id|
			set_books!(books!().map(|b| if (b.id == id) { ..b, done: !b.done } else b))

		<section class="tour">
			<input
				placeholder="Add a book"
				value={draft!()}
				on:input.value={set_draft!}
				on:keydown.Enter={add!}
			/>
			<ul>
				{...books!().map(|b|
					<li key={b.id} class:done={b.done}>
						<input type="checkbox" checked?={b.done} on:change={|| tick!(b.id)} />
						{b.title}
					</li>
				)}
			</ul>
			{if (left!() == 0) <p>All read.</p> else <p>{left!()} to read</p>}
		</section>
	}

	<style>
		.done {
			text-decoration: line-through;
		}
	</style>
}

At a glance#

This table is a component too: type to filter it.

WriteMeans
<tag attr="text" other={expr}>…</tag>An element; {expr} must be a Str, and is escaped.
{expr}Text (escaped), a number or markup, as the expression's type says. In a component, it runs again when a signal it read changes, and patches its node.
{...expr}A List(Html), joined: what .map makes.
checked?={bool}A boolean attribute, there when true.
requiredA boolean attribute that is always on.
rel??={str}An attribute left out when the string is empty.
class:active={bool}Adds a class when true; all classes end up in one class attribute.
style:--size={str}Sets a CSS custom property; unsafe values are left out.
style:color={str}Sets one property of the style, checked the same way; computed if it reads a signal.
on:click={|| …}In a component: runs the handler, an effect, when the event happens.
on:input.value={set_draft!}Gives the handler the target's value (a Str).
on:change.checked={|done| …}Gives the handler whether the target is checked (a Bool).
on:keydown.key={|key| …}Gives the handler the key's name (Enter, Escape…).
on:keydown.ArrowUp={|| …}Runs for that key only, with no modifier key held, and keeps the key from scrolling the page. .Space is the space bar.
on:keydown.Mod+K={|| …}Runs for that key with exactly those modifier keys held: Shift, Ctrl, Alt, Meta, and Mod (⌘ on macOS, Ctrl elsewhere).
<Document on:keydown.Escape={|| …} />Handlers on the whole document while it is there; it renders nothing. <Window on:resize={…} /> is the window's.
on:keydown.keys={|keys| …}Gives the handler the key and the modifier keys held: keys.key, keys.shift, keys.mod…
on:frame.ms={|ms| …}Runs every animation frame, given the milliseconds since the last, while the element is on the page.
transition={Transition.fade}Plays as the element's row or part comes and goes; transition:in and transition:out play one way. A row that goes stays until it has.
(count!, set_count!) = create_signal!(0)A signal: an accessor, which whatever reads it subscribes to, and a setter.
total! = create_memo!(|| …)A value computed from signals once per change, for everything that reads it.
{if ready!() { … } else { … }}The branch that holds, kept while it does; made anew when another one does.
{match card!() { Ok(card) => …, Err(_) => … }}The arm that holds, kept while it does; its names read the newest value.
{...rows!().map(|row| <li key={row.id}>…</li>)}A row per key, kept and moved as the list changes; .map_with_index(|row, i| <li key={i}>…) keeps rows by position.
<Loading fallback={…}>What shows while an answer from the server is on its way.
<Errored fallback={|problem, retry| …}>What shows when something inside failed, and a way to try again.
get! = |{ params, context, .. }| Ok(…)In a route's +server.roc: its GET endpoint, given its path's params and what its middleware handed on.
Api.get_profile({ id }).read!()A GET endpoint's answer as a plain value: the server answers it as it renders the page, which carries it to the browser.
<StatusPill status={s} />A component: StatusPill.view!({ status: || s }), run once, where it is rendered; its props are getters, read where it reads them.
<Card>children</Card>Children become a children : List(Html) prop.
<>…</>A fragment: its children side by side, no element around them. <></> is nothing.
<!doctype html>The doctype.
{# a comment }A comment that never reaches the page.
<!-- a comment -->Also a comment that never reaches the page.
<script>…</script>Script or style text, kept as written; never with values in it.
<style>…</style> beside a component's definitionsCSS for that component's markup only, scoped as Svelte scopes it.
&amp; &middot; &#x2014;Entities: the character.

37 of 37

Elements, text and fragments#

Elements are written as in HTML, tag names in lower case. Empty elements close themselves (<br />, <img />, <input />); a bare <br> is refused. Text is escaped: a < in a name shows as itself, never as a tag.

Markup is an ordinary Roc expression: name it, return it, put it in a list. A fragment, <>…</>, holds elements side by side, so nothing needs a single root; <></> is nothing at all. The Roc rocx writes keeps your line numbers, so compiler reports point at your lines.

examples/Hello.rocx What rocx writes: the same lines, in Roc
view : { name : Str, link : Str } -> Html
view = |{ name, link }|
	<p class="greeting">
		Hello, <a href={link} title="Their profile">{name}</a>!
	</p>
view : { name : Str, link : Str } -> Html
view = |{ name, link }|
	Html.element("p", [Html.attr_literal("class", "greeting"),], [
		Html.text("Hello, "), Html.element("a", [Html.attr("href", link), Html.attr_literal("title", "Their profile"),], [Html.shown(name),]), Html.text("!"),
	])
Hello.view({ name: "Ada <Lovelace>", link: "/people/ada?tab=notes&sort=new" }) renders
<p class="greeting">Hello, <a href="/people/ada?tab=notes&amp;sort=new" title="Their profile">Ada &lt;Lovelace&gt;</a>!</p>

Live

Hello, Ada <Lovelace>!

Holes: Roc values in markup#

A hole, {x}, puts a Roc expression in markup, shown by its type: a Str as escaped text, a number as digits, Html as markup. Any other type, such as a Bool or a record, is a compile error at your line. A list hole, {...xs}, shows a List(Html)'s items in order.

<p>{name} has {count} messages, {"${unread.to_str()} unread"}.</p>
<ul>{...tags.map(|tag| <li>{tag}</li>)}</ul>

In a component, a hole reruns and patches its own node when what it reads changes: a call of a name ending in ! (a signal such as count!(), a memo, an accessor prop) or an effectful component's prop. Any other hole is worked out once.

Attributes#

An attribute's value is a quoted string or a Roc expression in braces. Other forms cover what HTML makes awkward:

WrittenMeans
name="text", name='text'A static value, as written, entities decoded, on one line.
name={expr}A Str from Roc, escaped. In a component, set again when what it reads changes.
nameA boolean attribute that is always on, such as required.
name?={bool}A boolean attribute, there while the Bool is true: disabled?={busy}.
name??={str}Left out while the string is empty.
class:name={bool}Adds the class while the Bool is true. All the element's classes, a computed class={…}'s too, end up in one class attribute.
style:--name={str}Sets a CSS custom property, for the stylesheet to use.
style:color={str}Sets one CSS property. Its name is letters and dashes.
style="…"A static style, which the style: attributes join.
<img enhanced:src={path} />A photo of this site (a quoted path too) that the server makes smaller copies of. Once they are made, a moment after a page first shows it, pages get their srcset, a sizes and the photo's width and height; until then, its src. It loads lazily and decodes off the main thread unless loading, fetchpriority or decoding says otherwise. Only an <img> takes it, and never beside a src or srcset. See the server.
examples/Attributes.rocx What rocx writes: the same lines, in Roc
view : { email : Str, required : Bool, rel : Str, active : Bool, size : Str } -> Html
view = |{ email, required, rel, active, size }|
	<div class="signup">
		<input type="email" name="email" value={email} required?={required} autofocus />
		<a href="/terms" rel??={rel}>Terms</a>
		<button type="button" class="primary" class:active={active} style:--size={size}>Join</button>
	</div>
view : { email : Str, required : Bool, rel : Str, active : Bool, size : Str } -> Html
view = |{ email, required, rel, active, size }|
	Html.element("div", [Html.attr_literal("class", "signup"),], [
		Html.void("input", [Html.attr_literal("type", "email"), Html.attr_literal("name", "email"), Html.attr("value", email), Html.flag("required", required), Html.flag("autofocus", Bool.True),]), Html.text(" "),
		Html.element("a", [Html.attr_literal("href", "/terms"), Html.optional("rel", rel),], [Html.text("Terms"),]), Html.text(" "),
		Html.element("button", [Html.attr_literal("type", "button"), Html.attr_literal("class", "primary"), Html.class_if("active", active), Html.style_var("--size", size),], [Html.text("Join"),]),
	])
Attributes.view({ email: "ada@example.com", required: Bool.True, rel: "", active: Bool.True, size: "1.25rem" }) renders
<div class="signup"><input type="email" name="email" value="ada@example.com" required autofocus> <a href="/terms">Terms</a> <button class="primary active" type="button" style="--size: 1.25rem">Join</button></div>

Live

rocx refuses an unquoted value (class=big), a whole computed style (style={…}) and an inline handler (onclick="…"; in a component, write on:click={…}). A style: value is dropped if it holds anything but letters, digits, spaces and .,%#()-+, or calls a CSS function that could load something (rgb(), calc(), var() and other computing functions are fine; url() is not). URL attributes (href, src, action and a few more) take only safe URLs.

if, match and lists#

Branches and lists need no special syntax: if, match and .map work in a hole as anywhere in Roc. An if in a hole needs no else: {if (late) <p>Late</p>} shows nothing (<></>) while late is false. This example's list is a plain value, rendered once:

examples/Lists.rocx What rocx writes: the same lines, in Roc
Post : { title : Str, status : [Draft, Published(Str)] }

view : List(Post) -> Html
view = |posts|
	<section>
		<h3>{if (posts.is_empty()) "No posts yet" else "${posts.len().to_str()} posts"}</h3>
		<ul>
			{...posts.map(|post|
				<li>
					{post.title}
					{match post.status {
						Draft => <em>draft</em>
						Published(day) => <time>{day}</time>
					}}
				</li>
			)}
		</ul>
	</section>
Post : { title : Str, status : [Draft, Published(Str)] }

view : List(Post) -> Html
view = |posts|
	Html.element("section", [], [
		Html.element("h3", [], [Html.shown(if (posts.is_empty()) "No posts yet" else "${posts.len().to_str()} posts"),]), Html.text(" "),
		Html.element("ul", [], [
			Html.join(posts.map(|post|
				Html.element("li", [], [
					Html.shown(post.title), Html.text(" "),
					Html.shown(match post.status {
						Draft => Html.element("em", [], [Html.text("draft"),])
						Published(day) => Html.element("time", [], [Html.shown(day),])
					}),
				])
			)),
		]),
	])
Lists.view([{ title: "Hello, rocx", status: Published("Nov 19") }, { title: "Islands", status: Draft }]) renders
<section><h3>2 posts</h3> <ul><li>Hello, rocx <time>Nov 19</time></li><li>Islands <em>draft</em></li></ul></section>

Live

2 posts

  • Hello, rocx
  • Islands draft

In a component, where values change, they keep the markup they made:

if, match and .map, on the components page, shows each live.

Components#

A capitalised tag is a component: a function from a record of props to Html. <StatusPill status={s} /> calls StatusPill.view (or view!) when the file imports or defines a StatusPill module, and this file's status_pill otherwise. Each attribute is a prop: a string, a Roc value in braces, or a bare name (Bool.True). What is between the tags is the children prop, a List(Html). A missing prop is a type error, unless the props are a nominal record with defaults (title : Str ?? "").

examples/Components.rocx What rocx writes: the same lines, in Roc
view : { name : Str, unread : U64 } -> Html
view = |{ name, unread }|
	<Card title="Inbox">
		<p>Welcome back, {name}. <Badge count={unread} /></p>
	</Card>

card : { title : Str, children : List(Html) } -> Html
card = |{ title, children }|
	<article class="card">
		<h4>{title}</h4>
		{...children}
	</article>

badge : { count : U64 } -> Html
badge = |{ count }| <span class="badge" class:zero={count == 0}>{count.to_str()} new</span>
view : { name : Str, unread : U64 } -> Html
view = |{ name, unread }|
	card({ title: "Inbox", children: [
		Html.element("p", [], [Html.text("Welcome back, "), Html.shown(name), Html.text(". "), badge({ count: unread, }),]),
	], })

card : { title : Str, children : List(Html) } -> Html
card = |{ title, children }|
	Html.element("article", [Html.attr_literal("class", "card"),], [
		Html.element("h4", [], [Html.shown(title),]), Html.text(" "),
		Html.join(children),
	])

badge : { count : U64 } -> Html
badge = |{ count }| Html.element("span", [Html.attr_literal("class", "badge"), Html.class_if("zero", count == 0),], [Html.shown(count.to_str()), Html.text(" new"),])
Components.view({ name: "Grace", unread: 3 }) renders
<article class="card"><h4>Inbox</h4> <p>Welcome back, Grace. <span class="badge">3 new</span></p></article>

Live

Inbox

Welcome back, Grace. 3 new

There are two kinds of component (pure and effectful):

WrittenMeans
<Field value!={draft!} />A prop named with ! is an accessor, called like a signal: value!() (props that change).
<Card {...rest} />Passes a record of props on as is, such as the rest of a view's props (|{ title, ..rest }|).
<Repeat count!={n!()}>{|index| …}</Repeat>A function as the only child is passed as children to the component's view_with!, which calls it.
<ThemeContext value={dark}>…</ThemeContext>Provides a context, defined with create_context, to the markup inside (contexts).
<Card key={card.id} … />On a component that is a list row's outermost tag, key is the row's key, never a prop.

Handlers, keys and transitions#

A handler, on:event={…}, is a Roc function the browser runs when the event reaches the element. It may set signals, call the server and so on; the server renders nothing for it. A suffix on the event's name says what the handler is given, or when it runs:

WrittenMeans
on:click={|| …}Runs on the event. on:submit also stops the browser's own submit.
on:input.value={set_draft!}Given the element's value, a Str.
on:change.checked={|on| …}Given whether it is checked, a Bool.
on:keydown.key={|key| …}Given the key's name (Enter, k). .keys gives the key and the modifier keys held (keys.shift, keys.mod…).
on:keydown.Escape={|| …}Runs for that key alone, with no modifier held, and stops the browser's default (an arrow key scrolling the page). .Space is the space bar; letters and digits work too (.w).
on:keydown.Mod+K={|| …}Runs for that key with exactly those modifier keys held: Shift, Ctrl, Alt, Meta, and Mod, which is ⌘ on macOS and Ctrl elsewhere.
on:click.prevent={|| …}Stops the browser's default first, such as following a link the page takes over.
on:pointermove.point={|p| …}Given where the pointer is over the element, as shares of its width and height.
on:drop.data={|items| …}, .filesGiven what a drop or a paste carries, or its files; on:change.files on a file input gives the files chosen.
on:frame.ms={|ms| …}Runs every animation frame while the element is on the page, given the milliseconds since the last.
on:viewport={|view| …}Runs when the element shows, and each time it scrolls or changes size, given what of it shows.
on:visibilitychange.visible={|shown| …}On <Document>: given whether the page shows (false while its tab is hidden).
examples/Events.rocx What rocx writes: the same lines, in Roc
view! : {} => Html
view! = |{}| {
	(draft!, set_draft!) = create_signal!("Hello")
	(agreed!, set_agreed!) = create_signal!(Bool.False)
	(saved!, set_saved!) = create_signal!("")
	<form on:submit={|| set_saved!(draft!())}>
		<input value={draft!()} on:input.value={set_draft!} on:keydown.Escape={|| set_draft!("")} />
		<input type="checkbox" checked?={agreed!()} on:change.checked={set_agreed!} />
		<button disabled?={!agreed!()}>Save</button>
		<output>{saved!()}</output>
	</form>
}
view! : {} => Html
view! = |{}| {
	(draft!, set_draft!) = create_signal!("Hello")
	(agreed!, set_agreed!) = create_signal!(Bool.False)
	(saved!, set_saved!) = create_signal!("")
	Html.element("form", [Html.on("submit", || set_saved!(draft!())),], [
		Html.void("input", [Html.attr_of("value", || draft!()), Html.on_value("input", set_draft!), Html.on_named_key("keydown", "Escape", || set_draft!("")),]), Html.text(" "),
		Html.void("input", [Html.attr_literal("type", "checkbox"), Html.flag_of("checked", || agreed!()), Html.on_checked("change", set_agreed!),]), Html.text(" "),
		Html.element("button", [Html.flag_of("disabled", || !agreed!()),], [Html.text("Save"),]), Html.text(" "),
		Html.element("output", [], [Html.hole_of(|| Html.hole(saved!())),]),
	])
}

Other attributes that only mean something in the browser:

Markup inside a <NoHydration> never runs in the browser, so rocx refuses a handler, key, transition or drag: attribute there, at its line. The components page covers signals and handlers in depth.

Built-in tags#

A few capitalised tags are rocx's own, unless your file has a module of the same name:

WrittenMeans
<NoHydration>…</NoHydration>Markup only the server renders. The browser keeps its HTML as is; none of the code inside is in the wasm.
<Document on:keydown.Mod+K={…} />, <Window on:resize={…} />Handlers on the whole document or window, while the markup around the tag is rendered. They take only handlers and render nothing.
<Meta name="description" content={…} />, <Link … />, <Style>…</Style>A <meta>, <link> or <style> in the document's <head>, while the markup around the tag is rendered.
<!doctype html>The doctype, at the top of a root layout.
<story name="…">…</story>One way a component looks, for the dev build's catalog (stories).

The platform also has components you import (import pf.Loading, and so on): <Loading fallback={…}> and <Errored fallback={…}> for waiting and failing, <Repeat> for rows without a list, <Title> for the document's title, <HttpStatusCode code={404} /> for the status the server answers the page with, and <Navigate> for navigating.

Whitespace, as HTML has it#

Text follows HTML's rule, as in Svelte (not JSX): each run of spaces, tabs and line breaks is one space. Whitespace with a line break next to an element's own opening or closing tag is dropped; a space on the tag's line stays (<b>On the tag's line: </b>). So prose can break lines anywhere, even next to a link or a value, and elements on lines of their own get a space between them. <pre> and <textarea> keep text as written.

examples/Whitespace.rocx What rocx writes: the same lines, in Roc
	view : { name : Str } -> Html
	view = |{ name }|
		<div>
			<p>
				Prose breaks lines anywhere: next to a
				<a href="/links">link</a> or a value like
				{name}, and each break is one space.
			</p>
			<p><b>On the tag's line: </b>a space stays.</p>
			<pre>kept   as
  written</pre>
		</div>
	view : { name : Str } -> Html
	view = |{ name }|
		Html.element("div", [], [
			Html.element("p", [], [
				Html.text("Prose breaks lines anywhere: next to a "),
				Html.element("a", [Html.attr_literal("href", "/links"),], [Html.text("link"),]), Html.text(" or a value like "),
				Html.shown(name), Html.text(", and each break is one space."),
			]), Html.text(" "),
			Html.element("p", [], [Html.element("b", [], [Html.text("On the tag's line: "),]), Html.text("a space stays."),]), Html.text(" "),
			Html.element("pre", [], [Html.text("kept   as\n  written"),
  ]),
		])
Whitespace.view({ name: "Grace" }) renders
<div><p>Prose breaks lines anywhere: next to a <a href="/links">link</a> or a value like Grace, and each break is one space.</p> <p><b>On the tag&#39;s line: </b>a space stays.</p> <pre>kept   as
  written</pre></div>

Live

Prose breaks lines anywhere: next to a link or a value like Grace, and each break is one space.

On the tag's line: a space stays.

kept   as
  written

Comments, entities, script and style#

{# … } and <!-- … --> are comments; they never reach the page. A {# … } comment ends at the first }, so it can't contain one. Entities work: the common named ones (&amp;, &middot;, &nbsp;…) and numeric ones (&#x2192;); rocx refuses one it doesn't know. Write a literal <, >, { or } in text as an entity or a string in a hole ({"{"}), so a stray brace is never silently text.

A <script> or <style> in markup keeps its text as written, braces included, and takes no holes: a page's script is part of the page, never data. A <style> beside a component's definitions, outside its markup, is scoped to that component.

examples/Raw.rocx What rocx writes: the same lines, in Roc
view : {} -> Html
view = |{}|
	<>
		{# For whoever reads this file: it never reaches the page. }
		<style>.raw-demo b { letter-spacing: 0.05em }</style>
		<p class="raw-demo">
			<b>Tom &amp; Jerry</b> &middot; 1&ndash;2 &#x2192; {"{braces}"} and &lt;tags&gt;
		</p>
		<!-- Nor does this. -->
	</>
view : {} -> Html
view = |{}|
	Html.join([
		
		Html.element("style", [], [Html.source_text(".raw-demo b { letter-spacing: 0.05em }"),]), Html.text(" "),
		Html.element("p", [Html.attr_literal("class", "raw-demo"),], [
			Html.element("b", [], [Html.text("Tom & Jerry"),]), Html.text(" · 1–2 → "), Html.shown("{braces}"), Html.text(" and <tags>"),
		]),
		
	])
Raw.view({}) renders
<style>.raw-demo b { letter-spacing: 0.05em }</style> <p class="raw-demo"><b>Tom &amp; Jerry</b> · 1–2 → {braces} and &lt;tags&gt;</p>

Live

Tom & Jerry · 1–2 → {braces} and <tags>

Styles, scoped to their component#

A <style> in a component's block, beside its definitions, styles only that component's markup, as in Svelte. rocx adds a class named after the component to each element written in the block and to each selector: .card .title becomes .card.rx-… .title:where(.rx-…), one class more specific than written, however long the selector. So two components' .card rules never meet, even in one file; a bare p is only this component's paragraphs; and styles don't reach into the components it renders. A page or layout has no block, so its <style> goes at the file's top level, for the whole file. A component, or a file's top level, has at most one <style>, with no attributes, and no @import, @charset or @namespace (they must come first in a stylesheet). Its lines are blank in the Roc, so line numbers stay yours.

examples/Scoped.rocx What rocx writes: the same lines, in Roc
view : { title : Str, note : Str } -> Html
view = |{ title, note }|
	<figure class="card">
		<p class="title">{title}</p>
		<p>{note}</p>
	</figure>

<style>
	.card {
		margin: 0;
		padding: 0.75rem 1rem;
		border-left: 3px solid var(--accent);
	}

	.card .title {
		font-weight: 700;
	}

	p {
		margin: 0.25rem 0 0;
		font-style: italic;
	}
</style>
view : { title : Str, note : Str } -> Html
view = |{ title, note }|
	Html.element("figure", [Html.attr_literal("class", "card rx-xjqvlj"),], [
		Html.element("p", [Html.attr_literal("class", "title rx-xjqvlj"),], [Html.shown(title),]), Html.text(" "),
		Html.element("p", [Html.attr_literal("class", "rx-xjqvlj"),], [Html.shown(note),]),
	])















Scoped.view({ title: "Scoped", note: "This p is styled; the page's other paragraphs aren't." }) renders
<figure class="card rx-xjqvlj"><p class="title rx-xjqvlj">Scoped</p> <p class="rx-xjqvlj">This p is styled; the page&#39;s other paragraphs aren&#39;t.</p></figure>

Live

Scoped

This p is styled; the page's other paragraphs aren't.

Reach outside the component as in Svelte: :global(body), div :global(strong) for any strong inside this component's divs, and a :global { … } block for rules that are all global. A component's @keyframes spin, and spin in its animation, are its own; @keyframes -global-spin is everyone's spin. Nested rules work, & too.

rocx puts every <style> in the app into one stylesheet, Generated/Styles.roc. The root layout adds it to its <head> with <NoHydration>{Styles.style}</NoHydration> (so none of it is in the wasm): a <link> to /rocx/styles-hash.css, named by its content, so the browser keeps it for every page and any change gives it a new name.

Stories#

A <story name="…"> in a component's block holds the markup of one way the component looks; its name starts with a letter, and the tag takes nothing else. Each story becomes a definition in its place (<story name="Tip"> is story_tip!), so every build checks it against the component, but only a dev build (rocx dev) shows it, in a catalog at /__rocx/stories (stories).

Where < starts markup#

< starts markup only where an expression can begin, and only when a letter, > or ! follows. After a value on the same line it is a comparison.

WrittenRead as
x = <b>hi</b>, f(<b/>), [<i/>, <b/>], Html ?? <></>markup: after =, (, [, ,, ??
|post| <li>…</li>, A => <b/>markup: a lambda's body, a branch
if (a < b) <b/> else <i/>a comparison in the condition, then markup after it and after else
first on its linemarkup: a block's last expression
a < b, f(x)<y, n<ba comparison: a value comes before it
"<b>", '<', # <i>left alone: strings, characters and comments

Types#

Markup is the platform's Html type everywhere. A pure component, view, is a function such as { … } -> Html; an effectful one, view!, an effect: { … } => Html. A prop's default may be markup: fallback : Html ?? <></>. In plain Roc, these build markup without rocx:

FunctionFor
Html.to_strHtml -> Strmarkup with nothing to run in it, as a string: an email's HTML, an expect
Html.textStr -> Htmlescaped text
Html.joinList(Html) -> Htmlseveral, as one
Html.empty{} -> Htmlnothing at all (<></> in markup)
Html.doctype{} -> Htmlthe doctype (<!doctype html> in markup)

The platform reference lists every function of Html and the other modules.