Quillon.Factory (Quillon v0.1.0)

Copy Markdown View Source

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

blockquote()

@spec blockquote() :: tuple()

Create an empty blockquote.

Examples

iex> Quillon.Factory.blockquote()
{:blockquote, %{}, []}

blockquote(children)

@spec blockquote(list()) :: tuple()

Create a blockquote with children.

Examples

iex> Quillon.Factory.blockquote([{:paragraph, %{}, [{:text, %{text: "Quote", marks: []}, []}]}])
{:blockquote, %{}, [{:paragraph, %{}, [{:text, %{text: "Quote", marks: []}, []}]}]}

blockquote(children, citation)

@spec blockquote(list(), binary()) :: tuple()

Create a blockquote with children and citation.

Examples

iex> Quillon.Factory.blockquote([{:paragraph, %{}, []}], "Author")
{:blockquote, %{citation: "Author"}, [{:paragraph, %{}, []}]}

bullet_list()

@spec bullet_list() :: tuple()

Create an empty bullet list.

Examples

iex> Quillon.Factory.bullet_list()
{:bullet_list, %{}, []}

bullet_list(items)

@spec bullet_list(list()) :: tuple()

Create a bullet list with list item children.

Examples

iex> Quillon.Factory.bullet_list([{:list_item, %{}, [{:paragraph, %{}, []}]}])
{:bullet_list, %{}, [{:list_item, %{}, [{:paragraph, %{}, []}]}]}

callout(type)

@spec callout(atom()) :: tuple()

Create an empty callout with type.

Examples

iex> Quillon.Factory.callout(:info)
{:callout, %{type: :info}, []}

iex> Quillon.Factory.callout(:warning)
{:callout, %{type: :warning}, []}

callout(type, children)

@spec callout(atom(), list()) :: tuple()

Create a callout with type and children.

Examples

iex> Quillon.Factory.callout(:info, [{:paragraph, %{}, []}])
{:callout, %{type: :info}, [{:paragraph, %{}, []}]}

callout(type, children, title)

@spec callout(atom(), list(), binary()) :: tuple()

Create a callout with type, children, and title.

Examples

iex> Quillon.Factory.callout(:warning, [{:paragraph, %{}, []}], "Note")
{:callout, %{type: :warning, title: "Note"}, [{:paragraph, %{}, []}]}

code_block(code)

@spec code_block(binary()) :: tuple()

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: ""}, []}

code_block(code, language)

@spec code_block(binary(), binary()) :: tuple()

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"}, []}

divider()

@spec divider() :: tuple()

Create a divider with default style (solid).

Examples

iex> Quillon.Factory.divider()
{:divider, %{style: :solid}, []}

divider(style)

@spec divider(atom()) :: tuple()

Create a divider with a specific style.

Examples

iex> Quillon.Factory.divider(:dashed)
{:divider, %{style: :dashed}, []}

iex> Quillon.Factory.divider(:dotted)
{:divider, %{style: :dotted}, []}

document()

@spec document() :: tuple()

Create an empty document.

Examples

iex> Quillon.Factory.document()
{:document, %{}, []}

document(children)

@spec document(list()) :: tuple()

Create a document with children.

Examples

iex> Quillon.Factory.document([{:paragraph, %{}, []}])
{:document, %{}, [{:paragraph, %{}, []}]}

document(attrs, children)

@spec document(map(), list()) :: tuple()

Create a document with attrs and children.

Examples

iex> Quillon.Factory.document(%{id: "doc_1"}, [{:paragraph, %{}, []}])
{:document, %{id: "doc_1"}, [{:paragraph, %{}, []}]}

heading(level)

@spec heading(integer()) :: tuple()

Create a heading with a level.

Examples

iex> Quillon.Factory.heading(1)
{:heading, %{level: 1}, []}

iex> Quillon.Factory.heading(3)
{:heading, %{level: 3}, []}

heading(level, text)

@spec heading(integer(), binary() | list()) :: tuple()

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]}, []}]}

image(src)

@spec image(binary()) :: tuple()

Create an image with src.

Examples

iex> Quillon.Factory.image("/images/photo.jpg")
{:image, %{src: "/images/photo.jpg", alt: ""}, []}

image(src, alt)

@spec image(binary(), binary()) :: tuple()

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"}, []}

image(src, alt, opts)

@spec image(binary(), binary(), keyword()) :: tuple()

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}, []}

list_item()

@spec list_item() :: tuple()

Create an empty list item.

Examples

iex> Quillon.Factory.list_item()
{:list_item, %{}, []}

list_item(children)

@spec list_item(list()) :: tuple()

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: []}, []}]}]}

new(type, attrs)

@spec new(atom(), map()) :: tuple()

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}, []}

new(type, attrs, children)

@spec new(atom(), map(), list() | binary()) :: tuple()

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}, []}

ordered_list()

@spec ordered_list() :: tuple()

Create an empty ordered list with start=1.

Examples

iex> Quillon.Factory.ordered_list()
{:ordered_list, %{start: 1}, []}

ordered_list(items)

@spec ordered_list(list()) :: tuple()

Create an ordered list with list item children.

Examples

iex> Quillon.Factory.ordered_list([{:list_item, %{}, [{:paragraph, %{}, []}]}])
{:ordered_list, %{start: 1}, [{:list_item, %{}, [{:paragraph, %{}, []}]}]}

ordered_list(items, start)

@spec ordered_list(list(), integer()) :: tuple()

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, %{}, []}]}

paragraph()

@spec paragraph() :: tuple()

Create an empty paragraph.

Examples

iex> Quillon.Factory.paragraph()
{:paragraph, %{}, []}

paragraph(text)

@spec paragraph(binary() | list()) :: tuple()

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]}, []}]}

table()

@spec table() :: tuple()

Create an empty table.

Examples

iex> Quillon.Factory.table()
{:table, %{}, []}

table(rows)

@spec table(list()) :: tuple()

Create a table with table row children.

Examples

iex> Quillon.Factory.table([{:table_row, %{header: false}, []}])
{:table, %{}, [{:table_row, %{header: false}, []}]}

table_cell()

@spec table_cell() :: tuple()

Create an empty table cell.

Examples

iex> Quillon.Factory.table_cell()
{:table_cell, %{colspan: 1, rowspan: 1}, []}

table_cell(children)

@spec table_cell(list()) :: tuple()

Create a table cell with block children.

Examples

iex> Quillon.Factory.table_cell([{:paragraph, %{}, []}])
{:table_cell, %{colspan: 1, rowspan: 1}, [{:paragraph, %{}, []}]}

table_cell(children, opts)

@spec table_cell(
  list(),
  keyword()
) :: tuple()

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, %{}, []}]}

table_row()

@spec table_row() :: tuple()

Create an empty table row.

Examples

iex> Quillon.Factory.table_row()
{:table_row, %{header: false}, []}

table_row(cells)

@spec table_row(list()) :: tuple()

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}, []}]}

table_row(cells, opts)

@spec table_row(
  list(),
  keyword()
) :: tuple()

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}, []}]}

text(content)

@spec text(binary()) :: tuple()

Create a text node with no marks.

Examples

iex> Quillon.Factory.text("Hello")
{:text, %{text: "Hello", marks: []}, []}

text(content, marks)

@spec text(binary(), list()) :: tuple()

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"}}]}, []}

video(src)

@spec video(binary()) :: tuple()

Create a video with src.

Examples

iex> Quillon.Factory.video("/videos/clip.mp4")
{:video, %{src: "/videos/clip.mp4"}, []}

video(src, opts)

@spec video(
  binary(),
  keyword()
) :: tuple()

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"}, []}