quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.

Home Page:https://quarto.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

improve pre-post filter decomposition

cscheid opened this issue · comments

cc @dragonstyle

We want to do filters like this:

      filters:
        pre:
          - pre.lua
        render:
          - render.lua
        post:
          - post.lua

The inspiration is the sweet positioning of asciidoc.lua and that's how everything else should be in our filter chain.

This would definitely help fill the gap with some R Markdown feature for custom formats. With R Markdown, one can define some pre / post hooks in output_format() and obviously do stuff during rendering:

  • Before knitting
  • (During knitting by using knitr hooks)
  • After knitting
  • Before render with Pandoc
  • (During pandoc render by passing filters to Pandoc)
  • After render after render with Pandoc.

Everything is in R for those hooks. Obviously for Quarto it will be Lua. Some pre and post filter will definitely help !

So 👍 to this !

This unblocks @allenmanning's switch to a simpler, more robust confluence render. So it's going to 1.3.

After discussing with Al, we're ok with doing this on 1.4.

See also #2294. Let's consider how to allow after-citeproc filters as well (and where exactly to take citeproc processing since we can call it with pandoc.utils.citeproc)

Here's a quick example of where a post-rendering Lua filter would be helpful: https://github.com/andrewheiss/quarto-wordcount#how-this-all-works. The filter works now because of the citeproc.lua wrapper mentioned in #2294 (in this comment), but someday it'll be neat to just do something like this:

format:
  html:
    filter:
      post:
        - '/path/to/wordcount.lua'

@andrewheiss Just to be clear, we already have "post" filters, they're not just "post enough" for handling the output of citeproc!

With that said, your use case is more than sufficient to convince me. (The quarto-wordcount filter is sweet!)

Ha, html: filter: super-duper-post: then :)

Related to this again, it would be helpful to have control over the filter ordering here in order to do things like extract the #appendix section for counting words. Right now in quarto-wordcount, if I want to count the words in the appendix separately, I have to put all the appendix sections in their own custom div (see https://github.com/andrewheiss/quarto-wordcount#appendices and andrewheiss/quarto-wordcount#2 (comment)). The Lua script seems to run before Quarto moves all the {.appendix} sections down to the end.

This is now available on main. Full documentation incoming, but a brief description is available on the pre-release notes.