Coerce flexible input into pandoc_inlines or pandoc_blocks
Source:R/ast-construct.R
ast_construct.RdValue
A pandoc_inlines or pandoc_blocks wrapper.
Details
Smooth over the verbosity of pandoc constructors by accepting plain
strings, single nodes, lists of nodes, or already-wrapped sequences,
and producing the canonical wrapper type. Inspired by Pandoc Lua
filters, where constructors like pandoc.Para("hi") coerce strings
to inline sequences automatically.
For as_inlines():
A character vector is split on whitespace, producing
pandoc_strruns joined bypandoc_space(); embedded newlines (or multi-element character vectors) becomepandoc_soft_break().A single
pandoc_inlineis wrapped inpandoc_inlines.A list is validated and wrapped.
An existing
pandoc_inlinesis returned as-is.
For as_blocks():
A character vector becomes one
pandoc_paragraphper non-empty element (each paragraph's content isas_inlines(line)).A single
pandoc_blockis wrapped inpandoc_blocks.A list is validated and wrapped.
An existing
pandoc_blocksis returned as-is.
These exist as ergonomic shortcuts for use inside ast_filter()
handlers and ad-hoc AST construction; the strict-typed constructors
(pandoc_inlines, pandoc_blocks, pandoc_str, ...) remain
the canonical way to build nodes.
Examples
if (FALSE) { # \dontrun{
pandoc_emph(content = as_inlines("hello world"))
as_blocks(c("first paragraph", "second paragraph"))
} # }