# `PhiaUi.Editor.ExportHelpers`
[🔗](https://github.com/charlenopires/PhiaUI/blob/v0.1.17/lib/phia_ui/editor/export_helpers.ex#L1)

Pure Elixir helpers for converting editor JSON documents to and from various
text formats.

These functions operate on the TipTap/ProseMirror JSON document format used
by PhiaUI editor components. No JavaScript or external dependencies required.

## Supported Conversions

### Export (JSON to format)
- `to_markdown/1` — Convert to Markdown
- `to_latex/1`    — Convert to basic LaTeX

### Import (format to JSON)
- `from_markdown/1` — Parse Markdown into editor JSON
- `from_html/1`     — Parse HTML into editor JSON

## Document Format

The editor JSON format follows the TipTap/ProseMirror schema:

    %{
      "type" => "doc",
      "content" => [
        %{"type" => "paragraph", "content" => [
          %{"type" => "text", "text" => "Hello ", "marks" => [%{"type" => "bold"}]},
          %{"type" => "text", "text" => "world"}
        ]}
      ]
    }

# `from_html`

```elixir
@spec from_html(String.t()) :: map()
```

Parses an HTML string into an editor JSON document.

Supports `<p>`, `<h1>`-`<h6>`, `<strong>`/`<b>`, `<em>`/`<i>`, `<a>`,
`<ul>`/`<ol>`/`<li>`, `<pre><code>`, `<blockquote>`, `<hr>`, and `<img>`.

Uses basic regex/string parsing — not a full HTML parser. Suitable for
simple, well-formed HTML from editor output.

## Examples

    iex> PhiaUi.Editor.ExportHelpers.from_html("<p>Hello <strong>world</strong></p>")
    %{"type" => "doc", "content" => [
      %{"type" => "paragraph", "content" => [
        %{"type" => "text", "text" => "Hello "},
        %{"type" => "text", "text" => "world", "marks" => [%{"type" => "bold"}]}
      ]}
    ]}

# `from_markdown`

```elixir
@spec from_markdown(String.t()) :: map()
```

Parses a Markdown string into an editor JSON document.

Supports headings (`#`), paragraphs, bold (`**`), italic (`*`), code (`` ` ``),
links (`[text](url)`), bullet lists (`-` or `*`), ordered lists (`1.`),
code blocks (triple backticks), blockquotes (`>`), horizontal rules (`---`),
and images (`![alt](src)`).

## Examples

    iex> PhiaUi.Editor.ExportHelpers.from_markdown("## Hello\n\nWorld")
    %{"type" => "doc", "content" => [
      %{"type" => "heading", "attrs" => %{"level" => 2}, "content" => [
        %{"type" => "text", "text" => "Hello"}
      ]},
      %{"type" => "paragraph", "content" => [
        %{"type" => "text", "text" => "World"}
      ]}
    ]}

# `to_latex`

```elixir
@spec to_latex(map() | nil) :: String.t()
```

Converts an editor JSON document to a basic LaTeX string.

Produces a minimal LaTeX document body (no preamble). Suitable for embedding
in a `\begin{document}` block.

## Examples

    iex> doc = %{"type" => "doc", "content" => [
    ...>   %{"type" => "heading", "attrs" => %{"level" => 1}, "content" => [
    ...>     %{"type" => "text", "text" => "Title"}
    ...>   ]},
    ...>   %{"type" => "paragraph", "content" => [
    ...>     %{"type" => "text", "text" => "Hello"}
    ...>   ]}
    ...> ]}
    iex> PhiaUi.Editor.ExportHelpers.to_latex(doc)
    "\\section{Title}\n\nHello\n\n"

# `to_markdown`

```elixir
@spec to_markdown(map() | nil) :: String.t()
```

Converts an editor JSON document to a Markdown string.

Walks the document tree and converts each node type to its Markdown equivalent.

## Examples

    iex> doc = %{"type" => "doc", "content" => [
    ...>   %{"type" => "heading", "attrs" => %{"level" => 2}, "content" => [
    ...>     %{"type" => "text", "text" => "Hello"}
    ...>   ]},
    ...>   %{"type" => "paragraph", "content" => [
    ...>     %{"type" => "text", "text" => "World"}
    ...>   ]}
    ...> ]}
    iex> PhiaUi.Editor.ExportHelpers.to_markdown(doc)
    "## Hello\n\nWorld\n\n"

---

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