# Markup as HTML

> Status: implemented are markup as HTML, components of the server, their results, `Response`
> going up, `Content<T>`, component values with a result, decorators with guards, wrappers that
> take the body and the request context, routes, and `rooklang/server`; the server of the site, `site/server/main.rk`, is written
> with them, and the guide has a section on them. The decisions are collected at the end of the
> document, together with what is not decided yet. Server markup, components and `rooklang/server`
> remain **experimental** in 1.x and may change between releases.

> This document builds on [components.md](https://github.com/QWERN-9876r/RookLang/blob/HEAD/docs/components.md): components, decorators, context,
> components as values. It describes only what is different on the server.

```go
const name = "Ann & Bob"
const link = <a href="/users?sort=name" class="nav">Hello, {name}</a>   // Html
```

```js
const link = $$html`<a href="/users?sort=name" class="nav">Hello, ${name}</a>`
```

- **The type of markup is `Html`,** HTML that is known to be safe. It is a type of its own: a
  `string` is not an `Html`, nor an `Html` a `string`. In JS it is an object of the runtime whose
  `text` is the HTML, so that the runtime tells it from text too; `String(page)` and
  `` `${page}` `` give the text.
- **Attributes are checked by the DOM**, as in the browser: `<input value={1}>` and
  `<a hreff="/">` are errors. The types come from the same `lib.dom` or `src/checker/dom.ts`, only
  the result is `Html` instead of `HTMLAnchorElement`.
- **Escaping.** Text and the values of attributes are escaped; an `Html` is put in as it is. A
  string that is known to be HTML (from a Markdown renderer, say) becomes one with `html(s)`:
  `<article>{html(rendered)}</article>`. That is the only way around escaping, so a search for
  `html(` finds every place that can inject markup.
- **Children** are `Html`, strings, numbers, arrays of them and `null`, as in the browser. A
  `Response` among them stops the rendering (see "A `Response` goes up"); any other value is a
  compile error:
  `a component of type User[] cannot be in markup; return it, or show its fields, e.g. {user.name}`.
- **`class={[...]}`, `bool` in ARIA attributes, SVG** work as in the browser. A `bool` attribute
  without a value, `<input disabled={off}>`, is written only when it is true.
- **`<html>` at the top of a result** gets `<!doctype html>` in front of it.
- **What the browser has and the server has not** is an error that says what to do instead:
  - `onClick` and the other handlers:
    `"onClick" has no meaning on the server: markup there is a string; make a client component with @html-tag for code that runs in the browser`;
  - `bind:`, `ref`, `state`, `derived`, `effect`, `mount`;
  - `state` at the top level of a module: on the server it would be shared by all requests at
    once. A value of the module that requests share on purpose (a cache, a pool of connections) is
    a `let` or a `const`.

