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 Markdownto_latex/1— Convert to basic LaTeX
Import (format to JSON)
from_markdown/1— Parse Markdown into editor JSONfrom_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"}
]}
]
}
Summary
Functions
Parses an HTML string into an editor JSON document.
Parses a Markdown string into an editor JSON document.
Converts an editor JSON document to a basic LaTeX string.
Converts an editor JSON document to a Markdown string.
Functions
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"}]}
]}
]}
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 ().
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"}
]}
]}
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"
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"