-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit.lua
More file actions
67 lines (63 loc) · 2.22 KB
/
init.lua
File metadata and controls
67 lines (63 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
---Require a module from the filter directory.
local require = function(modname) -- luacheck: ignore 122
return pandoc.system.with_working_directory(
pandoc.path.directory(PANDOC_SCRIPT_FILE),
function() return require(modname) end
)
end
local parse_attr = require('lib/parse-attr')
local crossrefs = require('lib/crossrefs')
local numbering = require('lib/numbering')
-- Table of Ids and corresponding cross-referenceable elements. To be populated
-- by various element numbering functions.
---@type table<string, {type: ('sec'|'fig'|'tbl'|'eqn'), number: string}>
IDs = {}
---@param doc Pandoc
function Pandoc(doc)
if FORMAT == 'docx' and PANDOC_WRITER_OPTIONS.extensions:includes('native_numbering') then
pandoc.log.warn('`native_numbering` extension must not be used. Exiting.')
return
end
if FORMAT == 'docx' and PANDOC_WRITER_OPTIONS.number_sections == true then
pandoc.log.warn(
'`--number-sections` option must not be used with DOCX. '
.. 'Instead, associate a Number Format with your Heading style in your reference-doc. '
.. 'Exiting.'
)
return
end
return doc:walk({
Table = parse_attr.parse_table_attr,
Inlines = parse_attr.parse_equation_attr,
})
:walk({
Span = parse_attr.remove_temp_classes,
})
:walk({
Inlines = crossrefs.parse_crossrefs,
})
:walk({
Figure = numbering.move_unnumbered_class,
})
:walk({
-- Number cross-referenceable elements and construct table with Ids and numbers.
traverse = 'topdown', -- needed for subfigs
Pandoc = numbering.number_sections,
Span = function(span)
if FORMAT ~= 'docx' then return numbering.number_equations(span) end
end,
Para = function(para)
if FORMAT == 'docx' then return numbering.number_docx_equations(para) end
end,
Figure = numbering.number_fig_or_tbl,
Table = numbering.number_fig_or_tbl,
})
:walk({
-- Resolve cross-reference groups.
Span = crossrefs.write_crossrefs,
})
:walk {
-- Resolve single cross-references.
Link = crossrefs.write_crossref,
}
end