Quillon.Node (Quillon v0.1.0)

Copy Markdown View Source

Utilities for working with Quillon AST nodes.

Provides accessors, type guards, and predicates for node tuples.

Summary

Functions

Get the attrs of a node.

Check if a node is a block type.

Check if a node is a blockquote.

Check if a node is a bullet list.

Check if a node is a callout.

Get the children of a node.

Check if a node is a code block.

Check if a node is a container type.

Check if a node is a divider.

Check if a node is a document.

Check if a node is a heading.

Check if a node is an image.

Check if a node is an inline type.

Check if a node is a list (bullet or ordered).

Check if a node is a list item.

Check if a value is a valid node tuple.

Check if a node is an ordered list.

Check if a node is a paragraph.

Check if a node is a table.

Check if a node is a table cell.

Check if a node is a table row.

Check if a node is a text node.

Get the type of a node.

Check if a node is a video.

Functions

attrs(arg)

@spec attrs(tuple()) :: map()

Get the attrs of a node.

Examples

iex> Quillon.Node.attrs({:heading, %{level: 2}, []})
%{level: 2}

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

block?(arg1)

@spec block?(any()) :: boolean()

Check if a node is a block type.

Examples

iex> Quillon.Node.block?({:paragraph, %{}, []})
true

iex> Quillon.Node.block?({:heading, %{level: 1}, []})
true

iex> Quillon.Node.block?({:text, %{text: "Hi", marks: []}, []})
false

blockquote?(arg1)

@spec blockquote?(any()) :: boolean()

Check if a node is a blockquote.

Examples

iex> Quillon.Node.blockquote?({:blockquote, %{}, []})
true

iex> Quillon.Node.blockquote?({:paragraph, %{}, []})
false

bullet_list?(arg1)

@spec bullet_list?(any()) :: boolean()

Check if a node is a bullet list.

Examples

iex> Quillon.Node.bullet_list?({:bullet_list, %{}, []})
true

iex> Quillon.Node.bullet_list?({:ordered_list, %{start: 1}, []})
false

callout?(arg1)

@spec callout?(any()) :: boolean()

Check if a node is a callout.

Examples

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

iex> Quillon.Node.callout?({:paragraph, %{}, []})
false

children(arg)

@spec children(tuple()) :: list()

Get the children of a node.

Examples

iex> Quillon.Node.children({:paragraph, %{}, [{:text, %{text: "Hi", marks: []}, []}]})
[{:text, %{text: "Hi", marks: []}, []}]

iex> Quillon.Node.children({:divider, %{}, []})
[]

code_block?(arg1)

@spec code_block?(any()) :: boolean()

Check if a node is a code block.

Examples

iex> Quillon.Node.code_block?({:code_block, %{code: "x = 1", language: "elixir"}, []})
true

iex> Quillon.Node.code_block?({:paragraph, %{}, []})
false

container?(arg1)

@spec container?(any()) :: boolean()

Check if a node is a container type.

Examples

iex> Quillon.Node.container?({:document, %{}, []})
true

iex> Quillon.Node.container?({:paragraph, %{}, []})
false

divider?(arg1)

@spec divider?(any()) :: boolean()

Check if a node is a divider.

Examples

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

iex> Quillon.Node.divider?({:paragraph, %{}, []})
false

document?(arg1)

@spec document?(any()) :: boolean()

Check if a node is a document.

Examples

iex> Quillon.Node.document?({:document, %{id: "doc_1"}, []})
true

iex> Quillon.Node.document?({:paragraph, %{}, []})
false

heading?(arg1)

@spec heading?(any()) :: boolean()

Check if a node is a heading.

Examples

iex> Quillon.Node.heading?({:heading, %{level: 2}, []})
true

iex> Quillon.Node.heading?({:paragraph, %{}, []})
false

image?(arg1)

@spec image?(any()) :: boolean()

Check if a node is an image.

Examples

iex> Quillon.Node.image?({:image, %{src: "/img.jpg", alt: ""}, []})
true

iex> Quillon.Node.image?({:paragraph, %{}, []})
false

inline?(arg1)

@spec inline?(any()) :: boolean()

Check if a node is an inline type.

Examples

iex> Quillon.Node.inline?({:text, %{text: "Hi", marks: []}, []})
true

iex> Quillon.Node.inline?({:paragraph, %{}, []})
false

list?(arg1)

@spec list?(any()) :: boolean()

Check if a node is a list (bullet or ordered).

Examples

iex> Quillon.Node.list?({:bullet_list, %{}, []})
true

iex> Quillon.Node.list?({:ordered_list, %{start: 1}, []})
true

iex> Quillon.Node.list?({:paragraph, %{}, []})
false

list_item?(arg1)

@spec list_item?(any()) :: boolean()

Check if a node is a list item.

Examples

iex> Quillon.Node.list_item?({:list_item, %{}, []})
true

iex> Quillon.Node.list_item?({:paragraph, %{}, []})
false

node?(arg1)

@spec node?(any()) :: boolean()

Check if a value is a valid node tuple.

Examples

iex> Quillon.Node.node?({:paragraph, %{}, []})
true

iex> Quillon.Node.node?({:text, %{text: "Hi", marks: []}, []})
true

iex> Quillon.Node.node?("not a node")
false

iex> Quillon.Node.node?({:paragraph, [], []})
false

ordered_list?(arg1)

@spec ordered_list?(any()) :: boolean()

Check if a node is an ordered list.

Examples

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

iex> Quillon.Node.ordered_list?({:bullet_list, %{}, []})
false

paragraph?(arg1)

@spec paragraph?(any()) :: boolean()

Check if a node is a paragraph.

Examples

iex> Quillon.Node.paragraph?({:paragraph, %{}, []})
true

iex> Quillon.Node.paragraph?({:heading, %{level: 1}, []})
false

table?(arg1)

@spec table?(any()) :: boolean()

Check if a node is a table.

Examples

iex> Quillon.Node.table?({:table, %{}, []})
true

iex> Quillon.Node.table?({:paragraph, %{}, []})
false

table_cell?(arg1)

@spec table_cell?(any()) :: boolean()

Check if a node is a table cell.

Examples

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

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

table_row?(arg1)

@spec table_row?(any()) :: boolean()

Check if a node is a table row.

Examples

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

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

text?(arg1)

@spec text?(any()) :: boolean()

Check if a node is a text node.

Examples

iex> Quillon.Node.text?({:text, %{text: "Hello", marks: [:bold]}, []})
true

iex> Quillon.Node.text?({:paragraph, %{}, []})
false

type(arg)

@spec type(tuple()) :: atom()

Get the type of a node.

Examples

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

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

video?(arg1)

@spec video?(any()) :: boolean()

Check if a node is a video.

Examples

iex> Quillon.Node.video?({:video, %{src: "/vid.mp4"}, []})
true

iex> Quillon.Node.video?({:paragraph, %{}, []})
false