-
Notifications
You must be signed in to change notification settings - Fork 5
/
odt-lists.lua
89 lines (81 loc) · 2.81 KB
/
odt-lists.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
79
80
81
82
83
84
85
86
87
88
89
--
-- Improves lists when converting to ODT, by adding list styles to lists, and
-- apropriate paragraph styles to list items. Only lists that are one level deep
-- are supported; in lists with two or more levels, only the innermost level is
-- improved, generating strange results.
--
-- In bullet lists, the list style turns to that in variable `listStyle`,
-- and the paragraph style of list items turns to that in variable
-- `listParaStyle`.
--
-- In ordered lists, the list style turns to that in variable `numListStyle`,
-- and the paragraph style of list items turns to that in variable
-- `numListParaStyle`.
--
-- Currently, just italics, bold, links and line blocks are preserved in lists;
-- all other markup is ignored.
--
-- dependencies: util.lua, need to be in the same directory of this filter
-- author:
-- - name: José de Mattos Neto
-- - address: https://github.com/jzeneto
-- date: february 2018 (first version)
-- license: GPL version 3 or later
local listStyle = 'List_20_1'
local numListStyle = 'Numbering_20_1'
local listParaStyle = 'List_20_1'
local numListParaStyle = 'Numbering_20_1'
local path = require 'pandoc.path'
utilPath = path.directory(PANDOC_SCRIPT_FILE)
dofile(path.join{utilPath, 'util.lua'})
local tags = {}
tags.listStart = '<text:list text:style-name=\"' .. listStyle .. '\">'
tags.numListStart = '<text:list text:style-name=\"' .. numListStyle .. '\">'
tags.listEnd = '</text:list>'
tags.listItemStart = '<text:list-item>'
tags.listItemEnd = '</text:list-item>'
local function listHasInnerList(list)
local hasInnerList = false
pandoc.walk_block(list, {
RawBlock = function (raw)
hasInnerList = true
end
})
return hasInnerList
end
local function getFilter(forOrderedList)
local blockToRaw = util.blockToRaw
blockToRaw.Plain = function (item)
local paraStyle = listParaStyle
if forOrderedList then
paraStyle = numListParaStyle
end
local paraStartTag = '<text:p text:style-name=\"' .. paraStyle .. '\">'
local para = paraStartTag .. pandoc.utils.stringify(item) .. '</text:p>'
local content = tags.listItemStart .. para .. tags.listItemEnd
return pandoc.Plain(pandoc.Str(content))
end
return blockToRaw
end
local function listFilter(list, isOrdered)
if listHasInnerList(list) then
return list
end
list = pandoc.walk_block(list, getFilter(isOrdered))
local listTag = tags.listStart
if isOrdered then
listTag = tags.numListStart
end
local rawList = listTag .. pandoc.utils.stringify(list) .. tags.listEnd
return pandoc.RawBlock('opendocument', rawList)
end
function BulletList(list)
if FORMAT == 'odt' then
return listFilter(list, false)
end
end
function OrderedList(list)
if FORMAT == 'odt' then
return listFilter(list, true)
end
end