Markup.Node (Markup v0.1.0)

Copy Markdown View Source

Turns a struct module into a markup node.

defmodule MyLang.Strong do
  use Markup.Node, children: [:nodes], kind: :strong
  defstruct nodes: []
end

:children lists the fields holding child nodes, in document order (default [:nodes]). A field may hold a list of nodes, a single node, or nil.

:kind tags the node with one of the language-neutral kinds in kinds/0, so a bare-atom selector like :emphasis finds it whatever the language calls the struct (Markup.Markdown.Emph, for example). Leave it off for nodes with no common counterpart. Nodes of the same kind share these fields where they have them: nodes (children), literal (text or source content) and url (link and image targets).

use Markup.Node defines __markup_children__/0 and __markup_kind__/0, and implements Access (see Markup.Document) and Enumerable (a pre-order walk, the node included).

Summary

Types

A language-neutral node kind; see kinds/0.

Functions

The node's kind, or nil if it doesn't declare one.

The kinds a node can declare with use Markup.Node, kind: ....

Types

kind()

@type kind() ::
  :text
  | :strong
  | :emphasis
  | :strikethrough
  | :code
  | :code_block
  | :link
  | :image
  | :heading
  | :paragraph
  | :list
  | :list_item
  | :block_quote
  | :table
  | :table_row
  | :table_cell
  | :thematic_break
  | :soft_break
  | :hard_break
  | :raw

A language-neutral node kind; see kinds/0.

Functions

kind(arg1)

@spec kind(term()) :: kind() | nil

The node's kind, or nil if it doesn't declare one.

Markup.Node.kind(%Markup.Djot.Delete{})
#=> :strikethrough

kinds()

@spec kinds() :: [kind()]

The kinds a node can declare with use Markup.Node, kind: ....

:code is inline code and :code_block a fenced or indented block. :raw is the raw HTML node plugins build with Markup.safe_html/2.