-
Notifications
You must be signed in to change notification settings - Fork 7
/
docx-figure-number.lua
78 lines (69 loc) · 1.5 KB
/
docx-figure-number.lua
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
68
69
70
71
72
73
74
75
76
77
78
-- get logging.lua for debug
-- https://github.com/wlupton/pandoc-lua-logging
-- local logging = require 'logging'
if not logging then
logging = {
temp = function(tag, obj)
print(tag)
print(pandoc.utils.stringify(obj))
end
}
end
local chapter = 0
local count = 0
local tcount = 0
function xHeader(el)
-- logging.temp('el', el.level)
if el.level == 1 then
chapter = chapter + 1
count = 0
tcount = 0
end
end
function xFigure(fg)
-- logging.temp('figure', fg)
count = count + 1
if fg.caption and fg.caption.long then
local blocks = fg.caption.long
if blocks and #blocks == 1 then
local block = blocks[1]
if #block.content > 0 then
block.content:insert(1, pandoc.Str(" "))
block.content:insert(1, pandoc.Str('图' .. chapter .. '-' .. count .. ':'))
end
end
end
return fg
end
function xTable(tbl)
-- logging.temp('table', tbl)
tcount = tcount + 1
if tbl.caption and tbl.caption.long then
local blocks = tbl.caption.long
if blocks and #blocks == 1 then
local block = blocks[1]
if #block.content > 0 then
block.content:insert(1, pandoc.Str(" "))
block.content:insert(1, pandoc.Str('表' .. chapter .. '-' .. tcount .. ':'))
end
end
end
return tbl
end
function Pandoc(doc)
for i,el in pairs(doc.blocks) do
if el.t == "Header" then
xHeader(el)
elseif el.t == "Figure" then
xFigure(el)
elseif el.t == "Table" then
xTable(el)
end
end
return doc
end
-- return {
-- { Header = Header },
-- { Figure = Figure },
-- { Table = Table },
-- }