ExAnydoc.Document (ExAnydoc v0.1.0)

Copy Markdown View Source

The information-preserving document model produced by ExAnydoc.to_document/2.

blocks contains the document body in reading order. notes contains footnotes and endnotes, while assets retains embedded files together with their original bytes.

Blocks and inline elements are represented as tagged tuples that mirror the variants in anydoc's recursive model.

See the document model guide for traversal examples and the complete table representation.

Summary

Types

An embedded asset whose bytes are retained by the model.

A recursive block-level document element.

A slot in a table grid.

The source of an image.

An inline document element.

A target used by a link.

A list item in the document model.

A footnote or endnote.

Character formatting applied to an inline text run.

t()

A data or layout table.

A table cell containing block-level content.

Types

asset()

@type asset() :: %{
  id: non_neg_integer(),
  media_type: String.t(),
  origin_part: String.t(),
  bytes: binary()
}

An embedded asset whose bytes are retained by the model.

block()

@type block() ::
  {:heading,
   %{level: pos_integer(), anchor: String.t() | nil, content: [inline()]}}
  | {:paragraph, [inline()]}
  | {:list,
     %{
       marker:
         :bullet
         | :decimal
         | :lower_alpha
         | :upper_alpha
         | :lower_roman
         | :upper_roman,
       start: non_neg_integer(),
       items: [list_item()]
     }}
  | {:table, table()}
  | {:block_quote, [block()]}
  | {:code_block, %{lang: String.t() | nil, text: String.t()}}
  | :rule

A recursive block-level document element.

cell_slot()

@type cell_slot() ::
  {:origin, table_cell()}
  | {:covered, %{origin_row: non_neg_integer(), origin_col: non_neg_integer()}}

A slot in a table grid.

image_source()

@type image_source() ::
  {:external, String.t()} | {:asset, non_neg_integer()} | :unavailable

The source of an image.

inline()

@type inline() ::
  {:text, %{text: String.t(), style: style()}}
  | {:link, %{content: [inline()], target: link_target()}}
  | {:image, %{alt: String.t(), source: image_source()}}
  | {:anchor, String.t()}
  | {:note_ref, String.t()}
  | :line_break

An inline document element.

list_item()

@type list_item() :: %{
  blocks: [block()],
  checked: boolean() | nil,
  marker_label: String.t() | nil
}

A list item in the document model.

note()

@type note() :: %{id: String.t(), kind: :footnote | :endnote, blocks: [block()]}

A footnote or endnote.

style()

@type style() :: %{
  bold: boolean(),
  italic: boolean(),
  strike: boolean(),
  code: boolean()
}

Character formatting applied to an inline text run.

t()

@type t() :: %ExAnydoc.Document{assets: [asset()], blocks: [block()], notes: [note()]}

table()

@type table() :: %{
  grid: [[cell_slot()]],
  header_rows: non_neg_integer(),
  kind: :data | :layout
}

A data or layout table.

table_cell()

@type table_cell() :: %{
  blocks: [block()],
  col_span: pos_integer(),
  row_span: pos_integer()
}

A table cell containing block-level content.