# `Otera.Markup`
[🔗](https://github.com/georgeguimaraes/otera/blob/v0.2.0/lib/otera/markup.ex#L1)

A string that is safe to insert into HTML, like `Markup` of markupsafe, which Jinja2 uses.

With autoescape, Otera escapes the output of each `{{ ... }}`, except a `Markup`. The filters `safe`, `escape`, `forceescape` and `tojson` give a `Markup`, and with autoescape, macros, `caller()`, blocks and the bodies of set and filter blocks give a `Markup` too.

Templates see a `Markup` as the Python `Markup`, a subclass of `str`. An operation that combines a `Markup` with a plain string escapes the plain string: `+`, `%`, `join`, `format` and the `replace` filter. Most string methods of a `Markup` give a `Markup`.

To give a template a string that it does not escape, pass a `Markup` in the variables:

    Otera.render("{{ link }}", %{link: Otera.Markup.new(~s(<a href="/">Home</a>))}, autoescape: true)
    #=> {:ok, ~s(<a href="/">Home</a>)}

A custom filter, test or function gets a `Markup` as this struct, and can return one.

# `t`

```elixir
@type t() :: %Otera.Markup{text: String.t()}
```

# `escape`

```elixir
@spec escape(term()) :: t()
```

Escapes `value` like `markupsafe.escape`: a `Markup` stays as it is, and another value becomes the `Markup` of its escaped `str()`.

# `map`

```elixir
@spec map(String.t() | t(), (String.t() -&gt; String.t())) :: String.t() | t()
```

Applies `fun` to the text of `value`, and gives a `Markup` back when `value` is a `Markup`.

# `new`

```elixir
@spec new(String.t()) :: t()
```

Marks `text` as safe, like `Markup(text)`.

# `soft_str`

```elixir
@spec soft_str(term()) :: String.t() | t()
```

Like `markupsafe.soft_str`: a string or a `Markup` stays as it is, and another value becomes its `str()`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
