/// Templaters: the tags of tagged template literals (ADR 0048). /// /// `css`body { color: {c} }`` calls `css` with the literal's `Template`: /// its static text and the values of its `{...}` holes. A templater is a /// plain function from a `Template`; write your own for other languages. /// /// Holes are safe by default: a `String` or a value with `Show` is text /// the templater escapes; an `Element` is embedded as is. /// /// std's own `pug`, `html` and `xml` are not functions: the compiler /// lowers a template tagged with one of them to the HTML tree it denotes /// (ADR 0057), so their holes are typed by position and a malformed /// template is a compile error. The declarations below exist only as the /// tags' resolution targets; they are never called. import std/html /// A template literal's static text and holes. `parts` holds one item /// more than `holes`: text, hole, text, ..., hole, text. pub type Template { Template(parts: List, holes: List>) } /// A hole's value: `Text` is untrusted text a templater escapes; `Embed` /// is an element inserted as is. pub type Hole { Text(String), Embed(html.Element) } /// `html`

{body}

``: the markup as written, with text /// holes escaped when rendered and element holes embedded. /// /// Compiled (ADR 0057): this declaration is the tag's resolution target /// and is never called. pub fn html :: template: Template -> html.Element { panic "unreachable: std's templaters are compiled syntax (ADR 0057)" } /// XML built by the `xml` templater; `render_xml` returns the markup. pub opaque type Xml { Xml(String) } /// `xml`{name}``: the markup as written, with the /// holes escaped. /// /// Compiled (ADR 0057): this declaration is the tag's resolution target /// and is never called. pub fn xml :: template: Template -> Xml { panic "unreachable: std's templaters are compiled syntax (ADR 0057)" } /// The markup of an `Xml` value. pub fn render_xml :: x: Xml -> String { let Xml(s) = x s } /// The compiled `xml` templater's runtime part (ADR 0057): the compiler /// lowers `xml`…`` to the HTML fragment the template denotes (raw parts, /// typed holes) and calls this to render it into an `Xml` — the runtime /// `xml`'s output, byte for byte. pub fn xml_of_element :: element: html.Element -> Xml { Xml(html.render element) } /// Pug markup, the indentation-based shorthand: /// /// ```louise /// pug` /// .card /// h2 {title} /// p.body-text Hello, {name}! /// ul /// {items} /// ` /// ``` /// /// A line is an element (a `tag`, `.class`es, an `#id` and attributes in /// parentheses, then inline content after a space), a `| text` line, a /// `//` comment, or a hole on its own (the element embedded there). Deeper /// lines are children. `.card` and `#id` shorthands are `div`s, void /// elements and escaping are as in `std/html`, an uppercase tag calls a /// component, and a malformed template is a compile error naming the /// line. /// /// Compiled (ADR 0057): this declaration is the tag's resolution target /// and is never called. pub fn pug :: template: Template -> html.Element { panic "unreachable: std's templaters are compiled syntax (ADR 0057)" }