-
DescriptionI am creating a lua filter in Quarto 1.5 to extract all headings from the source document, and want to add a Here is my lua filter and qmd -- Function to create a slug from a string
local function slugify(s)
return s:lower()
:gsub("[^%w%s-]", "") -- remove non-word chars
:gsub("%s+", "-") -- replace spaces with hyphens
:gsub("^-+", "") -- trim starting hyphens
:gsub("-+$", "") -- trim ending hyphens
end
-- Table to store extracted headings
local headings = {}
-- Function to process headers
function Header(el)
if el.level == 2 or el.level == 3 then
local title = pandoc.utils.stringify(el.content)
table.insert(headings, {
depth = el.level,
title = title,
slug = slugify(title)
})
end
return el
end
function Meta(meta)
quarto.log.output("headings: " .. pandoc.utils.stringify(headings))
meta["headings"] = headings
return meta
end ---
format:
gfm:
variant: +yaml_metadata_block
filters:
- filters/headings.lua
---
# Main Title
## First Section
Some content here.
### Subsection A
More content.
## Second Section
Even more content.
### Subsection B
Final content. During render, the filter is getting headings correctly and prints
But no |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Why would you think there will be something? You are adding the headings as metadata not as output. |
Beta Was this translation helpful? Give feedback.
-
Your filter is perfectly fine, as it correspond to the orders filter are run (first Header will be processed, before any Meta) If you try with pandoc it will work (removing
However, with Quarto, we don't support this use case for now. For some reason, we are taking over To be clear, very simply, we do get the YAML in the input, and put it back on the output when asked. So currently doing what you want is not possible. We would need to reimplement the logic differently. That is a current limitation of Quarto |
Beta Was this translation helpful? Give feedback.
Your filter is perfectly fine, as it correspond to the orders filter are run (first Header will be processed, before any Meta)
If you try with pandoc it will work (removing
quarto.log.output
specific API)However, with Quarto, we don't support this use case for now. For some reason, we are taking over
+yaml_metadata_block
behavior to recreate the feature, but without taking into account any modification by user in Lua filter.To be clear, very simply, we do get the YAML in the input, and put it back on the output when asked. So currently doing what you want is not possible. We would need to reimplement the logic differ…