Skip to main content

Examples

Values from this very render.

The lua-env shortcode printing the Pandoc and Quarto state of the render that produced this page.

Every value in the tables below was read out of the render that produced this page. The filter is enabled in this site’s _quarto.yml:

filters:
  - lua-env

Pandoc

Pandoc globals, as this page was written.
Source Value
{{< lua-env pandoc.FORMAT >}}

html

{{< lua-env pandoc.PANDOC_VERSION >}}

3.13

{{< lua-env pandoc.PANDOC_API_VERSION >}}

1.23.1.2

Render the same document to another format and pandoc.FORMAT changes with it.

Quarto

The Quarto version that built this page.
Source Value
{{< lua-env quarto.version >}}

1.12.3

Deeper paths

The argument is one dot-separated path, and it reaches as far down the tree as you need. A key that holds a hyphen needs no quoting, because the path is split on the full stop alone.

Deeper paths, as this page was rendered.
Source Value
{{< lua-env pandoc.PANDOC_WRITER_OPTIONS.wrap_text >}}

wrap-none

{{< lua-env pandoc.PANDOC_WRITER_OPTIONS.html_math_method.method >}}

mathjax

{{< lua-env quarto.doc.language.back-to-top >}}

Back to top

{{< lua-env quarto.project.offset >}}

.

The first two rows are options Quarto hands to Pandoc for this format. The third is one of Quarto’s own interface strings, in the language the document declares. The fourth is the path from this page back to the root of the project, so a page in a subdirectory prints something else.

Note

Some of what the extension reports describes the machine that ran the render. quarto.version, pandoc.PANDOC_VERSION and pandoc.PANDOC_API_VERSION are the versions installed there, so a local preview and the published build print different numbers. pandoc.FORMAT and the interface strings follow the document instead, and stay the same wherever it is rendered.

Important

quarto.version is the only list the shortcode joins, and it joins it with full stops. Every other list prints its items one after another with nothing between them, so {{< lua-env pandoc.PANDOC_WRITER_OPTIONS.extensions >}} gives auto_identifiersline_blocksnative_divsnative_spans here.

Through the meta shortcode

Everything sits under the lua-env metadata key as well, so Quarto’s own shortcode reaches it without the extension’s own:

The same value, read as ordinary metadata.
Source Value
{{< meta lua-env.pandoc.FORMAT >}}

html

Note

The two shortcodes are not interchangeable. meta prints scalars, and reports ?invalid meta type for anything else, so a path such as lua-env.quarto.version, which is a list of three numbers, needs the extension’s own shortcode.

When a path does not resolve

None of the calls in this section run on this page, because each one writes a message the build would report.

A call with no argument gives one message and renders nothing:

{{< lua-env >}}
(E) [lua-env] The "lua-env" shortcode needs its "variable" argument.

A path whose last part is absent gives one warning and renders nothing:

{{< lua-env pandoc.NOPE >}}
(W) [lua-env] Variable 'pandoc.NOPE' not found in lua-env metadata.

A path that resolves to false gives the same warning, because the shortcode tests the value rather than its presence. pandoc.PANDOC_WRITER_OPTIONS.incremental is such a path in a default render:

(W) [lua-env] Variable 'pandoc.PANDOC_WRITER_OPTIONS.incremental' not found in lua-env metadata.

Two other shapes stop the render instead of reporting it:

  • A path whose middle part is absent, such as pandoc.NOPE.name, fails with attempt to index a nil value.
  • A path that names a key-value branch, such as pandoc.PANDOC_WRITER_OPTIONS, fails with Inline expected, got table. A list branch prints its items instead, as pandoc.PANDOC_WRITER_OPTIONS.extensions does above.

Read a path off the tree in What is published before you use it.

Exporting to JSON

This site leaves the export off, since it would write host paths into a file the site then publishes:

extensions:
  lua-env:
    json: false

Turning it on writes lua-env.json beside the source document, so add it to .gitignore:

extensions:
  lua-env:
    json: true

Narrow it to what you actually want, and the file stays readable:

extensions:
  lua-env:
    json: true
    json-include:
      - pandoc.FORMAT
      - quarto.version

Or keep everything except one noisy branch:

extensions:
  lua-env:
    json: true
    json-exclude:
      - quarto._quarto

You can use both at once. The exclusion wins, so it drops a branch from inside what the inclusion kept:

extensions:
  lua-env:
    json: true
    json-include: pandoc.PANDOC_WRITER_OPTIONS
    json-exclude: pandoc.PANDOC_WRITER_OPTIONS.extensions

Either option also takes a single path, as above, rather than a list.

Warning

json-exclude-sensitive defaults to true and drops the input file, the output file, the project directories, and the Pandoc script path. Leave it on unless the file stays on your own machine.

Naming the export file

json-file names the file, and the extension reads it only when json is true:

extensions:
  lua-env:
    json: true
    json-file: "_build/lua-env.json"

The path is resolved against the directory of the source document. A document in posts/first/ therefore writes posts/first/_build/lua-env.json, whatever the project root and the output directory are.

The extension writes the file but does not create the directory above it. A directory that is absent is reported, and the render carries on without an export:

(E) [lua-env] Failed to write JSON file: _build/lua-env.json: No such file or directory

An empty json-file falls back to lua-env.json.

What the redaction leaves behind

The JSON on this page is laid out for reading. The file itself is one line, as the Reference says.

A redacted path is removed with everything under it. quarto.project is not itself a redacted path, but two of its four entries are, directory and output_directory. The third, offset, survives. The fourth, profile, is an empty list when no Quarto profile is active, and an empty list is pruned:

extensions:
  lua-env:
    json: true
    json-include: quarto.project

For a document at the root of its project, with no profile active, that writes:

{
  "quarto": {
    "project": {
      "offset": "."
    }
  }
}

Run the same document under a profile and the branch carries it as well, since quarto.project.profile is not redacted:

{
  "quarto": {
    "project": {
      "offset": ".",
      "profile": ["demo"]
    }
  }
}

Set the option to false to keep the two that were dropped:

extensions:
  lua-env:
    json: true
    json-include: quarto.project
    json-exclude-sensitive: false

Redacted paths lists everything the option removes.

Exporting from a build server

json-warn-on-server is true unless you set it. With the export on, and one of the continuous integration variables set, the filter warns once and still writes the file:

(W) [lua-env] JSON export is enabled in a server/CI context (CI is set). The exported file may leak host filesystem paths. Set extensions.lua-env.json-warn-on-server: false to silence this warning.

Silence the warning once you have decided the export is safe there:

extensions:
  lua-env:
    json: true
    json-warn-on-server: false

A variable that is empty, or set to the text false, does not count as a build server. The check belongs to the export alone. With json: false the extension writes no file and reports no warning, whatever the environment holds. JSON export names the variables the check looks at.

Source

The repository ships a short, standalone starting point you can copy: example.qmd.

Back to top