quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.96k stars 327 forks source link

Expose all LUA variables to Quarto meta shortcode #4770

Open mcanouil opened 1 year ago

mcanouil commented 1 year ago

As originally discussed in #2249, here is a separate issue to discuss exposing LUA variables.

Currently, users do not have access to all LUA variables (from Quarto and Pandoc) which could be useful. With that in mind I wrote a LUA filter/shortcode (https://github.com/mcanouil/quarto-lua-env) to expose the following objects recursively, or at least the scalar variables.

lua-env:
  quarto: "quarto"
  pandoc:
    PANDOC_STATE: "PANDOC_STATE"
    FORMAT: "FORMAT"
    PANDOC_READER_OPTIONS: "PANDOC_READER_OPTIONS"
    PANDOC_WRITER_OPTIONS: "PANDOC_WRITER_OPTIONS"
    PANDOC_VERSION: "PANDOC_VERSION"
    PANDOC_API_VERSION: "PANDOC_API_VERSION"
    PANDOC_SCRIPT_FILE: "PANDOC_SCRIPT_FILE"

Variables can be accessed using:

This could be integrated into Quarto if deemed useful to have such behaviour as exposing "all" LUA variables to shortcode for use in Quarto document and possibly in code cells in the future.

cscheid commented 1 year ago

Yes, this is something we should do.

With that said, I'm all but certain that quarto does not want to advertise every single possible variable which is technically accessible via Lua. So, if we're going to do this (which I agree with you we should), then we first need to figure out what parts of the available Lua API are "blessed" for future use.

We need to do this anyway (in order to be able to truly resolve some questions about what's a bug, what's a regression, and what are the API entry points that we need to maintain for the future). But there's a lot of behind-the-scenes work involved in this, so please be aware that it might be a few months until we can start this part of the project.

mcanouil commented 1 year ago

No worries, in my Quarto extension, I do not advertise in depth what is exposed (because there are a lot). It's kind of a brute force extension to expose as much as possible without having to do the lookup/update at every API changes from Quarto or Pandoc.

cscheid commented 1 year ago

It's kind of a brute force extension to expose as much as possible without having to do the lookup/update at every API changes from Quarto or Pandoc.

Right, and that makes total sense to do. I just wanted to clarify that if we make this an internal quarto thing, then we're suddenly exposing all of those "accidentally-available" bits.

cderv commented 1 year ago

Related discussion with a use case for this: https://github.com/quarto-dev/quarto-cli/discussions/5029