Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarto support #14

Open
andrewheiss opened this issue Apr 5, 2023 · 0 comments
Open

Quarto support #14

andrewheiss opened this issue Apr 5, 2023 · 0 comments

Comments

@andrewheiss
Copy link

This isn't a bug report or anything—just a note about how to use {rmdfiltr}'s word count with Quarto.

Quarto doesn't support inline R code in YAML (quarto-dev/quarto-cli#1391 (comment)), so adding !expr rmdfiltr::add_wordcount_filter() to the YAML in a .qmd file doesn't work. Additionally, there's no way to specify pandoc_args, so there's no straightforward way to make citeproc run before the wordcount filter.

Fortunately, this GitHub comment shows that it's possible to make a Lua filter that basically behaves like --citeproc by feeding the whole document to pandoc.utils.citeproc(). That means we can create a little Lua script like citeproc.lua:

-- Lua filter that behaves like `--citeproc`
function Pandoc (doc)
  return pandoc.utils.citeproc(doc)
end

…and then include that as a filter:

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

This creates a pandoc command that looks something like this, feeding the document to the citeproc "filter" first, then feeding that to the word count script:

pandoc whatever.md --output whatever.html  --lua-filter citeproc.lua --lua-filter wordcount.lua

There's still no way that I've found to dynamically generate /path/to/wordcount.lua like !expr rmdfiltr::add_wordcount_filter(), so users need to download the Lua file themselves and put it somewhere in their project.

The Lua files can also be included in a Quarto format extension like this so there's no need to manually deal with Lua files in the YAML. Instead, users can just specify a wordcount-enabled format:

title: Something
format:
  wordcount-html: default
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant