You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/extensions/lua-api.qmd
+31Lines changed: 31 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -72,6 +72,37 @@ function Div(el)
72
72
end
73
73
```
74
74
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
+
localutility=require('./utils')
85
+
functionPandoc(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
+
localparsing=require('./utils/parsing')
96
+
functionPandoc(doc)
97
+
-- process
98
+
end
99
+
```
100
+
101
+
```{.lua filename="utils/parsing.lua"}
102
+
localutils=require("../utils")
103
+
-- ...
104
+
```
105
+
75
106
### Format Detection
76
107
77
108
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