Skip to contents

[Experimental]

Usage

ast_toc(x, max_level = 3L, ...)

Arguments

x

A pandoc document, a pandoc_blocks wrapper, or a list of blocks.

max_level

Deepest heading level to include (default 3).

...

Unused; for future extension.

Value

A pandoc_bullet_list block (empty when there are no qualifying headings).

Details

Walks the headings of a pandoc document in order and returns a nested pandoc_bullet_list linking to each one, the q2r analog of mq's section::toc(). The result is an ordinary block, so it can be spliced into the document with insert_after() or wrapped in a pandoc and rendered with to_qmd().

Each entry links to the heading's explicit identifier (@attr@id) when it has one; otherwise an approximate Pandoc-style slug of the heading text is used. Headings deeper than max_level are omitted.

Examples

if (FALSE) { # \dontrun{
doc = parse_qmd("# A\n\n## B\n\ntext\n\n# C\n")
toc = ast_toc(doc)
doc |> insert_before(is(pandoc_header), .what = toc)
} # }