# `Typst.Format`
[🔗](https://github.com/Hermanverschooten/typst/blob/main/lib/format.ex#L1)

Contains helper functions for converting Elixir datatypes into
the format that Typst expects.

These functions are useful when building Typst markup with EEx templates.

## Examples

    iex> Typst.render_to_string("Name: <%= name %>", name: Typst.Format.bold("Alice"))
    "Name: *Alice*"

    iex> Typst.render_to_string("columns: <%= cols %>", cols: Typst.Format.array(["1fr", "2fr"]))
    "columns: (1fr, 2fr)"

# `array`

```elixir
@spec array(list()) :: String.t()
```

Converts a list into a Typst array `(...)`.

## Examples

    iex> Typst.Format.array(["1fr", "2fr", "1fr"])
    "(1fr, 2fr, 1fr)"

    iex> Typst.Format.array(["red", "blue"])
    "(red, blue)"

# `bold`

```elixir
@spec bold(String.Chars.t()) :: String.t()
```

Wraps the given element in Typst bold markers (`*...*`).

## Examples

    iex> Typst.Format.bold("hello")
    "*hello*"

    iex> Typst.Format.bold(42)
    "*42*"

# `content`

```elixir
@spec content(String.Chars.t()) :: String.t()
```

Wraps the given element in Typst content brackets (`[...]`).

Returns `[]` for `nil` values.

## Examples

    iex> Typst.Format.content("hello")
    "[hello]"

    iex> Typst.Format.content(nil)
    "[]"

# `escape`

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

Escapes special Typst markup characters in the given string by prefixing them with a backslash.

This is useful when inserting user-provided text that should be rendered literally,
without triggering Typst's markup syntax.

The following characters are escaped: `\`, `*`, `_`, `` ` ``, `$`, `#`, `@`, `<`, `>`, `~`, `=`, `-`, `+`, `/`, `[`, `]`

Note: the `\\` in the examples below is Elixir's string representation of a single backslash.

## Examples

    iex> Typst.Format.escape("hello *world*")
    "hello \\*world\\*"

    iex> Typst.Format.escape("email@example.com")
    "email\\@example.com"

    iex> Typst.Format.escape("price is $10")
    "price is \\$10"

---

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