Custom AST Nodes
Overview
Quarto now supports custom AST nodes in Pandoc filters. This allows more flexibility in defining and using Lua filters.
We will slowly roll out more extensive changes of the AST, but currently, the following objects are custom AST nodes:
Example: Callouts
In previous versions of Quarto, callouts would be represented directly as a div with a class starting with callout
, and the contents laid out in a particular way.
While authoring documents, this syntax remains unchanged. But when processing the document, the callout divs are now represented as a custom AST node, which can be processed directly in Lua filters. In Quarto 1.3, callouts can be captured in Lua filters more directly. For example, here is a filter that forces every callout to be of type “caution”:
function Callout(callout)
-- do something with the callout
callout.type = "caution"
-- note that custom AST nodes are passed by reference. You can
-- return the value if you choose, but you do not need to.
end
Finally, custom AST node constructors are available in the quarto
object: quarto.Callout
, quarto.Tabset
, etc. See the pages above for details.