Skip to content

Commit 83bd671

Browse files
committed
Add require()
1 parent a063c1c commit 83bd671

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

docs/extensions/lua-api.qmd

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,37 @@ function Div(el)
7272
end
7373
```
7474

75+
### `require()`
76+
77+
In larger, more complex filters, it becomes useful to structure your Lua code in modules.
78+
Quarto overwrites the standard LUA `require()` to support the use of relative paths,
79+
so that small modules can be easily created and reused.
80+
81+
For example:
82+
83+
```{.lua filename="filter.lua"}
84+
local utility = require('./utils')
85+
function Pandoc(doc)
86+
-- process
87+
end
88+
```
89+
90+
Using relative paths makes it harder for multiple filters to accidentally
91+
create conflicting module names (as would eventually happen when using the standard Lua
92+
`require('utils')` syntax). It's possible to refer to subdirectories and parent directories as well:
93+
94+
```{.lua filename="filter2.lua"}
95+
local parsing = require('./utils/parsing')
96+
function Pandoc(doc)
97+
-- process
98+
end
99+
```
100+
101+
```{.lua filename="utils/parsing.lua"}
102+
local utils = require("../utils")
103+
-- ...
104+
```
105+
75106
### Format Detection
76107

77108
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

0 commit comments

Comments
 (0)