Factory functions for creating Quillon AST nodes.
Provides new/2 and new/3 for generic node creation, plus
convenience functions for each node type.
Summary
Functions
Create an empty blockquote.
Create a blockquote with children.
Create a blockquote with children and citation.
Create an empty bullet list.
Create a bullet list with list item children.
Create an empty callout with type.
Create a callout with type and children.
Create a callout with type, children, and title.
Create a code block with code content.
Create a code block with code and language.
Create a divider with default style (solid).
Create a divider with a specific style.
Create an empty document.
Create a document with children.
Create a document with attrs and children.
Create a heading with a level.
Create a heading with level and text content or children.
Create an image with src.
Create an image with src and alt.
Create an image with src, alt, and additional options.
Create an empty list item.
Create a list item with block children.
Create a new node with type and attrs, empty children.
Create a new node with type, attrs, and children.
Create an empty ordered list with start=1.
Create an ordered list with list item children.
Create an ordered list with items and custom start number.
Create an empty paragraph.
Create a paragraph with text content or children.
Create an empty table.
Create a table with table row children.
Create an empty table cell.
Create a table cell with block children.
Create a table cell with children and span options.
Create an empty table row.
Create a table row with table cell children.
Create a table row with cells and options.
Create a text node with no marks.
Create a text node with marks.
Create a video with src.
Create a video with src and options.
Functions
@spec blockquote() :: tuple()
Create an empty blockquote.
Examples
iex> Quillon.Factory.blockquote()
{:blockquote, %{}, []}
Create a blockquote with children.
Examples
iex> Quillon.Factory.blockquote([{:paragraph, %{}, [{:text, %{text: "Quote", marks: []}, []}]}])
{:blockquote, %{}, [{:paragraph, %{}, [{:text, %{text: "Quote", marks: []}, []}]}]}
Create a blockquote with children and citation.
Examples
iex> Quillon.Factory.blockquote([{:paragraph, %{}, []}], "Author")
{:blockquote, %{citation: "Author"}, [{:paragraph, %{}, []}]}
@spec bullet_list() :: tuple()
Create an empty bullet list.
Examples
iex> Quillon.Factory.bullet_list()
{:bullet_list, %{}, []}
Create a bullet list with list item children.
Examples
iex> Quillon.Factory.bullet_list([{:list_item, %{}, [{:paragraph, %{}, []}]}])
{:bullet_list, %{}, [{:list_item, %{}, [{:paragraph, %{}, []}]}]}
Create an empty callout with type.
Examples
iex> Quillon.Factory.callout(:info)
{:callout, %{type: :info}, []}
iex> Quillon.Factory.callout(:warning)
{:callout, %{type: :warning}, []}
Create a callout with type and children.
Examples
iex> Quillon.Factory.callout(:info, [{:paragraph, %{}, []}])
{:callout, %{type: :info}, [{:paragraph, %{}, []}]}
Create a callout with type, children, and title.
Examples
iex> Quillon.Factory.callout(:warning, [{:paragraph, %{}, []}], "Note")
{:callout, %{type: :warning, title: "Note"}, [{:paragraph, %{}, []}]}
Create a code block with code content.
Examples
iex> Quillon.Factory.code_block("def hello, do: :world")
{:code_block, %{code: "def hello, do: :world", language: ""}, []}
Create a code block with code and language.
Examples
iex> Quillon.Factory.code_block("def hello, do: :world", "elixir")
{:code_block, %{code: "def hello, do: :world", language: "elixir"}, []}
@spec divider() :: tuple()
Create a divider with default style (solid).
Examples
iex> Quillon.Factory.divider()
{:divider, %{style: :solid}, []}
Create a divider with a specific style.
Examples
iex> Quillon.Factory.divider(:dashed)
{:divider, %{style: :dashed}, []}
iex> Quillon.Factory.divider(:dotted)
{:divider, %{style: :dotted}, []}
@spec document() :: tuple()
Create an empty document.
Examples
iex> Quillon.Factory.document()
{:document, %{}, []}
Create a document with children.
Examples
iex> Quillon.Factory.document([{:paragraph, %{}, []}])
{:document, %{}, [{:paragraph, %{}, []}]}
Create a document with attrs and children.
Examples
iex> Quillon.Factory.document(%{id: "doc_1"}, [{:paragraph, %{}, []}])
{:document, %{id: "doc_1"}, [{:paragraph, %{}, []}]}
Create a heading with a level.
Examples
iex> Quillon.Factory.heading(1)
{:heading, %{level: 1}, []}
iex> Quillon.Factory.heading(3)
{:heading, %{level: 3}, []}
Create a heading with level and text content or children.
Examples
iex> Quillon.Factory.heading(1, "Welcome")
{:heading, %{level: 1}, [{:text, %{text: "Welcome", marks: []}, []}]}
iex> Quillon.Factory.heading(2, [{:text, %{text: "Bold", marks: [:bold]}, []}])
{:heading, %{level: 2}, [{:text, %{text: "Bold", marks: [:bold]}, []}]}
Create an image with src.
Examples
iex> Quillon.Factory.image("/images/photo.jpg")
{:image, %{src: "/images/photo.jpg", alt: ""}, []}
Create an image with src and alt.
Examples
iex> Quillon.Factory.image("/images/photo.jpg", "A photo")
{:image, %{src: "/images/photo.jpg", alt: "A photo"}, []}
Create an image with src, alt, and additional options.
Options can include :caption and :width.
Examples
iex> Quillon.Factory.image("/images/photo.jpg", "A photo", caption: "Figure 1")
{:image, %{src: "/images/photo.jpg", alt: "A photo", caption: "Figure 1"}, []}
iex> Quillon.Factory.image("/images/photo.jpg", "A photo", width: 800)
{:image, %{src: "/images/photo.jpg", alt: "A photo", width: 800}, []}
@spec list_item() :: tuple()
Create an empty list item.
Examples
iex> Quillon.Factory.list_item()
{:list_item, %{}, []}
Create a list item with block children.
Examples
iex> Quillon.Factory.list_item([{:paragraph, %{}, [{:text, %{text: "Item", marks: []}, []}]}])
{:list_item, %{}, [{:paragraph, %{}, [{:text, %{text: "Item", marks: []}, []}]}]}
Create a new node with type and attrs, empty children.
Examples
iex> Quillon.Factory.new(:paragraph, %{})
{:paragraph, %{}, []}
iex> Quillon.Factory.new(:heading, %{level: 2})
{:heading, %{level: 2}, []}
Create a new node with type, attrs, and children.
When a string is passed as children, it's automatically wrapped in a text node.
Examples
iex> Quillon.Factory.new(:paragraph, %{}, [{:text, %{text: "Hi", marks: []}, []}])
{:paragraph, %{}, [{:text, %{text: "Hi", marks: []}, []}]}
iex> Quillon.Factory.new(:paragraph, %{}, "Hello")
{:paragraph, %{}, [{:text, %{text: "Hello", marks: []}, []}]}
iex> Quillon.Factory.new(:divider, %{style: :dashed}, [])
{:divider, %{style: :dashed}, []}
@spec ordered_list() :: tuple()
Create an empty ordered list with start=1.
Examples
iex> Quillon.Factory.ordered_list()
{:ordered_list, %{start: 1}, []}
Create an ordered list with list item children.
Examples
iex> Quillon.Factory.ordered_list([{:list_item, %{}, [{:paragraph, %{}, []}]}])
{:ordered_list, %{start: 1}, [{:list_item, %{}, [{:paragraph, %{}, []}]}]}
Create an ordered list with items and custom start number.
Examples
iex> Quillon.Factory.ordered_list([{:list_item, %{}, []}], 5)
{:ordered_list, %{start: 5}, [{:list_item, %{}, []}]}
@spec paragraph() :: tuple()
Create an empty paragraph.
Examples
iex> Quillon.Factory.paragraph()
{:paragraph, %{}, []}
Create a paragraph with text content or children.
Examples
iex> Quillon.Factory.paragraph("Hello world")
{:paragraph, %{}, [{:text, %{text: "Hello world", marks: []}, []}]}
iex> Quillon.Factory.paragraph([{:text, %{text: "Hi", marks: [:bold]}, []}])
{:paragraph, %{}, [{:text, %{text: "Hi", marks: [:bold]}, []}]}
@spec table() :: tuple()
Create an empty table.
Examples
iex> Quillon.Factory.table()
{:table, %{}, []}
Create a table with table row children.
Examples
iex> Quillon.Factory.table([{:table_row, %{header: false}, []}])
{:table, %{}, [{:table_row, %{header: false}, []}]}
@spec table_cell() :: tuple()
Create an empty table cell.
Examples
iex> Quillon.Factory.table_cell()
{:table_cell, %{colspan: 1, rowspan: 1}, []}
Create a table cell with block children.
Examples
iex> Quillon.Factory.table_cell([{:paragraph, %{}, []}])
{:table_cell, %{colspan: 1, rowspan: 1}, [{:paragraph, %{}, []}]}
Create a table cell with children and span options.
Options can include :colspan and :rowspan.
Examples
iex> Quillon.Factory.table_cell([{:paragraph, %{}, []}], colspan: 2)
{:table_cell, %{colspan: 2, rowspan: 1}, [{:paragraph, %{}, []}]}
iex> Quillon.Factory.table_cell([{:paragraph, %{}, []}], rowspan: 3)
{:table_cell, %{colspan: 1, rowspan: 3}, [{:paragraph, %{}, []}]}
iex> Quillon.Factory.table_cell([{:paragraph, %{}, []}], colspan: 2, rowspan: 2)
{:table_cell, %{colspan: 2, rowspan: 2}, [{:paragraph, %{}, []}]}
@spec table_row() :: tuple()
Create an empty table row.
Examples
iex> Quillon.Factory.table_row()
{:table_row, %{header: false}, []}
Create a table row with table cell children.
Examples
iex> Quillon.Factory.table_row([{:table_cell, %{colspan: 1, rowspan: 1}, []}])
{:table_row, %{header: false}, [{:table_cell, %{colspan: 1, rowspan: 1}, []}]}
Create a table row with cells and options.
Options can include :header (boolean).
Examples
iex> Quillon.Factory.table_row([{:table_cell, %{colspan: 1, rowspan: 1}, []}], header: true)
{:table_row, %{header: true}, [{:table_cell, %{colspan: 1, rowspan: 1}, []}]}
Create a text node with no marks.
Examples
iex> Quillon.Factory.text("Hello")
{:text, %{text: "Hello", marks: []}, []}
Create a text node with marks.
Examples
iex> Quillon.Factory.text("Bold text", [:bold])
{:text, %{text: "Bold text", marks: [:bold]}, []}
iex> Quillon.Factory.text("Link", [{:link, %{href: "/page"}}])
{:text, %{text: "Link", marks: [{:link, %{href: "/page"}}]}, []}
Create a video with src.
Examples
iex> Quillon.Factory.video("/videos/clip.mp4")
{:video, %{src: "/videos/clip.mp4"}, []}
Create a video with src and options.
Options can include :poster.
Examples
iex> Quillon.Factory.video("/videos/clip.mp4", poster: "/images/poster.jpg")
{:video, %{src: "/videos/clip.mp4", poster: "/images/poster.jpg"}, []}