pandoc / lua-filters

A collection of lua filters for pandoc
MIT License
611 stars 166 forks source link

Add running additional filters in `include-files.lua` #140

Open gabyx opened 3 years ago

gabyx commented 3 years ago

I wanted to make PR to add functionality to run additional filter after the recursive transclusion.

-- recursive transclusion
contents = pandoc.walk_block(
  pandoc.Div(contents),
  { Header = update_last_level, CodeBlock = transclude }
  ).content

-- apply all filters if any
if filters then
  for i,f in ipairs(filters) do
    doc = pandoc.Pandoc(contents, metadata)
    contents = utils.run_json_filter(doc, "pandoc").blocks
  end
end

But I got stuck since it needs a more general run_filter function to run all sort of filters: See https://github.com/jgm/pandoc/issues/6830.

Can this be done, or is there another approach around.

Application: I want some filters to be run which affect the transclusion of include-files.lua. Namely replacing variables inside the include blocks

```{.include filter="codeblock-var-replace"}
${meta:chapterPath}/A.md
```
ghost commented 3 years ago

Here a potential workaround.

I'm using a 2 steps generation.

  1. I run pandoc to create one complete md file
  2. I use this file as source for normal generation with all my plugins
wenbopeng commented 1 year ago

pandoc 3.1.2 solves this problem perfectly!