Skip to content

Commit 6ce64dc

Browse files
authored
Add missing lua-types declarations for public Lua API (#14295)
Add type declarations for functions exported in init.lua that were missing from the lua-types annotations. This feeds into the autogen docs effort (quarto-dev/quarto-web#1649). quarto.doc: add_resource, add_supporting, is_filter_active quarto.utils: type, table.isarray, table.contains, table.sortedPairs, resolve_path_relative_to_document, as_inlines, as_blocks, is_empty_node, render, match, add_to_blocks
1 parent e8e4df7 commit 6ce64dc

File tree

2 files changed

+145
-3
lines changed

2 files changed

+145
-3
lines changed

src/resources/lua-types/quarto/doc.lua

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,25 @@ which must be copied into the LaTeX output directory.
4848
function quarto.doc.add_format_resource(file) end
4949

5050
--[[
51-
Include text at the specified location (`in-header`, `before-body`, or `after-body`).
51+
Add a resource file to the document. The file will be copied to the same
52+
relative location in the output directory.
53+
54+
The path should be relative to the Lua script calling this function.
55+
]]
56+
---@param path string Resource file path (relative to Lua script)
57+
function quarto.doc.add_resource(path) end
58+
59+
--[[
60+
Add a supporting file to the document. Supporting files are moved to the
61+
output directory and may be cleaned up after rendering.
62+
63+
The path should be relative to the Lua script calling this function.
64+
]]
65+
---@param path string Supporting file path (relative to Lua script)
66+
function quarto.doc.add_supporting(path) end
67+
68+
--[[
69+
Include text at the specified location (`in-header`, `before-body`, or `after-body`).
5270
]]
5371
---@param location 'in-header'|'before-body'|'after-body' Location for include
5472
---@param text string Text to include
@@ -101,6 +119,13 @@ Does the current output format include Bootstrap themed HTML
101119
---@return boolean
102120
function quarto.doc.has_bootstrap() end
103121

122+
--[[
123+
Check whether a specific internal Quarto filter is currently active.
124+
]]
125+
---@param filter string Filter name to check
126+
---@return boolean
127+
function quarto.doc.is_filter_active(filter) end
128+
104129
--[[
105130
Provides the project relative path to the current input
106131
if this render is in the context of a project (otherwise `nil`)

src/resources/lua-types/quarto/utils.lua

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,60 @@ Note that you should use `quarto.log.output()` instead of this function.
1212
function quarto.utils.dump(value) end
1313

1414
--[[
15-
Compute the absolute path to a file that is installed alongside the Lua script.
15+
Extended type function that returns Pandoc types with Quarto custom node awareness.
1616
17-
This is useful for internal resources that your filter needs but should
17+
Returns `"CustomBlock"` for Quarto custom block nodes and `"CustomInline"` for
18+
custom inline nodes, otherwise delegates to `pandoc.utils.type()`.
19+
]]
20+
---@param value any Value to check
21+
---@return string
22+
function quarto.utils.type(value) end
23+
24+
quarto.utils.table = {}
25+
26+
--[[
27+
Return `true` if the table is a plain integer-indexed array.
28+
]]
29+
---@param t table Table to check
30+
---@return boolean
31+
function quarto.utils.table.isarray(t) end
32+
33+
--[[
34+
Return `true` if the array-like table contains the given value.
35+
]]
36+
---@param t table Array-like table to search
37+
---@param value any Value to find
38+
---@return boolean
39+
function quarto.utils.table.contains(t, value) end
40+
41+
--[[
42+
Iterator that traverses table keys in sorted order.
43+
]]
44+
---@param t table Table to iterate
45+
---@param f? function Optional comparison function for sorting
46+
---@return function Iterator function
47+
function quarto.utils.table.sortedPairs(t, f) end
48+
49+
--[[
50+
Compute the absolute path to a file that is installed alongside the Lua script.
51+
52+
This is useful for internal resources that your filter needs but should
1853
not be visible to the user.
1954
]]
2055
---@param path string Path of file relative to the Lua script
2156
---@return string
2257
function quarto.utils.resolve_path(path) end
2358

59+
--[[
60+
Resolve a file path relative to the document's working directory.
61+
62+
Unlike `resolve_path()` which resolves relative to the Lua script,
63+
this resolves relative to the document being rendered.
64+
]]
65+
---@param path string File path to resolve
66+
---@return string
67+
function quarto.utils.resolve_path_relative_to_document(path) end
68+
2469
--[[
2570
Converts a string to a list of Pandoc Inlines, processing any Quarto custom
2671
syntax in the string.
@@ -38,6 +83,78 @@ syntax in the string.
3883
---@return pandoc.Blocks
3984
function quarto.utils.string_to_blocks(path) end
4085

86+
--[[
87+
Coerce the given object into a `pandoc.Inlines` list.
88+
89+
Handles Inline, Inlines, Block, Blocks, List, and table inputs.
90+
More performant than `pandoc.Inlines()` as it avoids full marshal roundtrips.
91+
92+
Note: The input object may be modified destructively.
93+
]]
94+
---@param obj any Object to coerce
95+
---@return pandoc.Inlines
96+
function quarto.utils.as_inlines(obj) end
97+
98+
--[[
99+
Coerce the given object into a `pandoc.Blocks` list.
100+
101+
Handles Block, Blocks, Inline, Inlines, List, Caption, and table inputs.
102+
More performant than `pandoc.Blocks()` as it avoids full marshal roundtrips.
103+
104+
Note: The input object may be modified destructively.
105+
]]
106+
---@param obj any Object to coerce
107+
---@return pandoc.Blocks
108+
function quarto.utils.as_blocks(obj) end
109+
110+
--[[
111+
Return `true` if the given AST node is empty.
112+
113+
A node is considered empty if it's an empty list/table, has empty `content`,
114+
has empty `caption`, or has an empty `text` field.
115+
]]
116+
---@param node any AST node to check
117+
---@return boolean
118+
function quarto.utils.is_empty_node(node) end
119+
120+
--[[
121+
Walk and render extended/custom AST nodes.
122+
123+
Processes Quarto custom AST nodes (like Callout, Tabset, etc.) into their
124+
final Pandoc representation.
125+
]]
126+
---@param node pandoc.Node AST node to render
127+
---@return pandoc.Node
128+
function quarto.utils.render(node) end
129+
130+
--[[
131+
CSS-selector-like AST matcher for Pandoc nodes.
132+
133+
Accepts string path selectors separated by `/` with support for:
134+
- Element type selectors (e.g. `"Header"`, `"Para"`, `"Div"`)
135+
- Child traversal via `/` separator
136+
- `*` wildcard to match any child
137+
- `{Type}` capture syntax to return matched nodes
138+
- `:child` to search direct children
139+
- `:descendant` to search all descendants
140+
- `:nth-child(n)` to match a specific child index
141+
142+
Returns a function that, when called with an AST node, returns the matched
143+
node(s) or `false`/`nil` if no match.
144+
]]
145+
---@param ... string|function Selector path components
146+
---@return function Matcher function
147+
function quarto.utils.match(...) end
148+
149+
--[[
150+
Append a Block, Blocks, or Inlines value to an existing Blocks list.
151+
152+
Inlines are wrapped in a Plain block before appending.
153+
]]
154+
---@param blocks pandoc.Blocks Target Blocks list
155+
---@param block pandoc.Block|pandoc.Blocks|pandoc.Inlines Value to append
156+
function quarto.utils.add_to_blocks(blocks, block) end
157+
41158
--[[
42159
Returns a filter that parses book metadata markers during document traversal.
43160

0 commit comments

Comments
 (0)