https://github.com/pandoc-ext/run-lua
Run Lua code that is embedded into documents via XML processing instructions
https://github.com/pandoc-ext/run-lua
lua pandoc pandoc-filter quarto quarto-extension quarto-filter
Last synced: about 2 months ago
JSON representation
Run Lua code that is embedded into documents via XML processing instructions
- Host: GitHub
- URL: https://github.com/pandoc-ext/run-lua
- Owner: pandoc-ext
- License: mit
- Created: 2022-12-10T11:57:27.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-04-28T06:33:21.000Z (almost 3 years ago)
- Last Synced: 2023-04-28T07:37:11.610Z (almost 3 years ago)
- Topics: lua, pandoc, pandoc-filter, quarto, quarto-extension, quarto-filter
- Language: Lua
- Homepage:
- Size: 9.77 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
README
run-lua
=======
Executes any Lua command in a `lua` XML processing instruction and
includes the result in the document.
Example:
``` markdown
The number is the fifth triangular number.
```
This yields
>
>
> The number 15 is the fifth triangular number.
>
>
The value that’s returned by the Lua code is spliced back into the
document. The `=` character can be used as a shorthand for
`return` when placed at the beginning of an expression.
``` xml
1 + 2 =
```
Result:
>
>
> 1 + 2 = 3
>
>
The filter tries to detect when the `return` has been omitted and
inserts it automatically in that case. Therefore, the above can be
shortened to
``` xml
1 + 2 =
```
>
>
> 1 + 2 = 3
>
>
Raw attributes syntax with format `run-lua` or `runlua` can be
used as an alternative to the processing-instructions-based
syntax.
For example,
``` markdown
𝜋 ≈ `math.pi`{=run-lua}
𝜏 ≈ `2 * math.pi`{=runlua}
```
yields
>
>
> 𝜋 ≈ 3.1415926535898
>
> 𝜏 ≈ 6.2831853071796
>
>
**Note** that pandoc isn’t an XML processor, and the processing
instruction is terminated by a single `>`. Use the “raw attribute”
syntax if your code contains that character:
```{=runlua}
return 1 > 0 and 'all is well'
```
Usage
-----
The filter modifies the internal document representation; it can
be used with many publishing systems that are based on pandoc.
### Plain pandoc
Pass the filter to pandoc via the `--lua-filter` (or `-L`) command
line option.
pandoc --lua-filter run-lua.lua ...
### Quarto
Users of Quarto can install this filter as an extension with
quarto install extension pandoc-ext/run-lua
and use it by adding `run-lua` to the `filters` entry in their
YAML header.
``` yaml
---
filters:
- run-lua
---
```
### R Markdown
Use `pandoc_args` to invoke the filter. See the [R Markdown
Cookbook](https://bookdown.org/yihui/rmarkdown-cookbook/lua-filters.html)
for details.
``` yaml
---
output:
word_document:
pandoc_args: ['--lua-filter=run-lua.lua']
---
```
License
-------
This pandoc Lua filter is published under the MIT license, see
file `LICENSE` for details.