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

Integrate 1.3 and 1.4 LUA/AST changes #1166

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add require()
cwickham committed Jun 17, 2024
commit 83bd671d926f0ae613b0c9dea24266864b1e40da
31 changes: 31 additions & 0 deletions docs/extensions/lua-api.qmd
Original file line number Diff line number Diff line change
@@ -72,6 +72,37 @@ function Div(el)
end
```

### `require()`

In larger, more complex filters, it becomes useful to structure your Lua code in modules.
Quarto overwrites the standard LUA `require()` to support the use of relative paths,
so that small modules can be easily created and reused.

For example:

```{.lua filename="filter.lua"}
local utility = require('./utils')
function Pandoc(doc)
-- process
end
```

Using relative paths makes it harder for multiple filters to accidentally
create conflicting module names (as would eventually happen when using the standard Lua
`require('utils')` syntax). It's possible to refer to subdirectories and parent directories as well:

```{.lua filename="filter2.lua"}
local parsing = require('./utils/parsing')
function Pandoc(doc)
-- process
end
```

```{.lua filename="utils/parsing.lua"}
local utils = require("../utils")
-- ...
```

### Format Detection

Extensions will often need to detect the current format to create custom content depending on the target output medium. The `quarto.doc.is_format()` function