Skip to contents

Parsing and rendering

Convert between QMD text/files and q2r’s two AST representations, and render an AST back to QMD source.

parse_qmd() experimental
Parse QMD input with pampa
to_qmd() experimental
Render an R-side AST back to QMD text
render_qmd() experimental
Render an AST to an output document with Quarto

Diagnostics

Structured parse diagnostics emitted by the reader, plus the lazy text renderer used by print() / format().

pampa_diagnostic()
Parse diagnostic produced by the pampa parser

Files and collections

File round-trip sugar over parse_qmd() / to_qmd(), and a lightweight container for parsing and writing back a whole directory of QMD documents at once.

read_qmd() write_qmd() edit_qmd() experimental
Read, write, and edit QMD files
qmd_collection() parse_qmd_dir() write_qmd_dir() experimental
A collection of QMD documents

Querying and rewriting the AST

A predicate-driven query/rewrite vocabulary shared across both the Pandoc S7 AST and the tree-sitter AST.

Locating nodes

tidyselect-style verbs for locating nodes by predicate. Predicates are unquoted expressions evaluated against a per-node data mask that exposes slot names and helpers (is(), has_class(), has_id(), has_attr(), is_leaf(), …).

Mutating nodes

Predicate-driven mutation verbs. Each return value is a node, a list of nodes (splice), or NULL (delete). The walker is post-order, matching Pandoc Lua filters’ default.

Filter-table rewriting (Lua-filter-style)

ast_filter() rewrites multiple node types in one pass using a table of S7-class-keyed handlers, with optional top-down traversal and list-level dispatch on pandoc_inlines / pandoc_blocks. ast_text() flattens a subtree to plain text.

ast_filter() experimental
Apply a table of type-keyed handlers to a pandoc AST
ast_skip() experimental
Mark a value as "use as-is, do not descend" inside ast_filter()
ast_text() experimental
Flatten a pandoc subtree to plain text

Attribute helpers

Concise immutable getters and setters for the @attr slot (id, classes, key-value attributes) found on headers, divs, code, links, spans, and friends.

has_class() add_class() remove_class() get_id() set_id() get_attr() set_attr() experimental
Attribute manipulation helpers

Constructing content

Ergonomic coercion helpers that accept strings, single nodes, or lists and produce the canonical pandoc_inlines / pandoc_blocks wrappers.

as_inlines() as_blocks() experimental
Coerce flexible input into pandoc_inlines or pandoc_blocks

Tables

Convert between a pandoc_table and a data.frame: flatten a parsed table to columns, or build a renderable table from a data frame (alignment, caption, and id ride along as attributes).

as_df() as_table() experimental
Convert between pandoc tables and data frames

Code cells

Read and edit Quarto executable cells: engine, label, body, and #| options on a pandoc_code_block, plus collect_code() to tangle a document’s cells. Inside a predicate the mask also exposes is_code_cell() and has_option().

Document structure

Author-altitude helpers over the top-level block stream: the enclosing-heading chain, section slicing and splitting, a tabular overview, and a generated table of contents.

ast_sections() experimental
Heading-section path for each top-level block
select_section() experimental
Select the blocks belonging to a heading section
ast_summary() experimental
Tabular overview of a document's top-level blocks
ast_toc() experimental
Build a table of contents from a document's headings
split_sections() experimental
Split a document into per-section sub-documents

Tree-sitter queries

Raw tree-sitter .scm query escape hatch with capture support, for cases where the predicate API is not expressive enough.

ts_query() experimental
Run a tree-sitter .scm query against QMD source

Pandoc AST

The S7 class hierarchy returned by parse_qmd() (the default ast = "pd") and accepted by to_qmd().

Root and abstract classes

pandoc is the document root and pandoc_node the common ancestor for every concrete node (with the abstract pandoc_block / pandoc_inline parents). pandoc_blocks / pandoc_inlines are the strict-typed list wrappers used in content slots. pandoc_children / pandoc_format_label are the generics behind the tree display, which print.pandoc documents.

pandoc()
Top-level Pandoc document
pandoc_node() pandoc_block() pandoc_inline()
Virtual parent classes
pandoc_blocks() pandoc_inlines()
Typed list wrappers
pandoc_children()
Children of a pandoc AST node for tree display
pandoc_format_label()
Label a pandoc AST node for tree display
print.pandoc print.pandoc_node print.pandoc_blocks print.pandoc_inlines
Print a Pandoc AST

Block constructors

Constructors for the concrete block-level node classes, collected on a single page (one alias and usage entry per constructor).

Inline constructors

Constructors for the concrete inline node classes, collected on a single page (one alias and usage entry per constructor).

Support types

Helper types that appear inside concrete nodes: attributes, table substructures, citations, captions, metadata.

Tree-sitter AST

S7 classes for the tree-sitter concrete syntax tree returned by parse_qmd(ast = "ts"). The tree is structurally faithful to the source bytes; use it when to_qmd() round-trip equivalence matters. print.ts_tree documents the tree display and its position / ascii knobs.

ts_point() ts_range() ts_nodes() ts_node() ts_tree()
Tree-sitter AST classes
print.ts_tree print.ts_node
Print a tree-sitter AST