8
8
end
9
9
10
10
local function get_colspecs (div_attributes , column_count )
11
- local aligns = {}
12
- local widths = {}
11
+ -- list of (align, width) pairs
12
+ local colspecs = {}
13
+
14
+ for i = 1 , column_count do
15
+ table.insert (colspecs , {pandoc .AlignDefault , nil })
16
+ end
13
17
14
18
if div_attributes .align then
15
19
local alignments = {
@@ -18,33 +22,57 @@ local function get_colspecs(div_attributes, column_count)
18
22
r = ' AlignRight' ,
19
23
c = ' AlignCenter'
20
24
}
25
+ local i = 1
21
26
for a in div_attributes .align :gmatch (' [^,]' ) do
22
27
assert (alignments [a ] ~= nil ,
23
28
" unknown column alignment " .. tostring (a ))
24
- table.insert (aligns , alignments [a ])
29
+ colspecs [i ][1 ] = alignments [a ]
30
+ i = i + 1
25
31
end
26
32
div_attributes .align = nil
27
- else
28
- for i = 1 , column_count do
29
- table.insert (aligns , pandoc .AlignDefault )
30
- end
31
33
end
32
34
33
35
if div_attributes .widths then
34
36
local total = 0
37
+ local widths = {}
35
38
for w in div_attributes .widths :gmatch (' [^,]' ) do
36
39
table.insert (widths , tonumber (w ))
37
40
total = total + tonumber (w )
38
41
end
39
- for i = 1 , column_count do widths [i ] = widths [i ] / total end
40
- div_attributes .widths = nil
41
- else
42
42
for i = 1 , column_count do
43
- table.insert ( widths , 0 ) -- let pandoc determine col widths
43
+ colspecs [ i ][ 2 ] = widths [ i ] / total
44
44
end
45
+ div_attributes .widths = nil
45
46
end
46
47
47
- return aligns , widths
48
+ return colspecs
49
+ end
50
+
51
+ local function new_table_head (rows )
52
+ return {{}, rows }
53
+ end
54
+
55
+ local function new_table_body (rows )
56
+ return {
57
+ attr = {},
58
+ body = rows ,
59
+ head = {},
60
+ row_head_columns = 0
61
+ }
62
+ end
63
+
64
+ local function new_row (cells )
65
+ return {{}, cells }
66
+ end
67
+
68
+ local function new_cell (contents )
69
+ return {
70
+ attr = {},
71
+ alignment = pandoc .AlignDefault ,
72
+ contents = contents ,
73
+ col_span = 1 ,
74
+ row_span = 1
75
+ }
48
76
end
49
77
50
78
local function process (div )
@@ -54,7 +82,8 @@ local function process(div)
54
82
local caption = {}
55
83
56
84
if div .content [1 ].t == " Para" then
57
- caption = table.remove (div .content , 1 ).content
85
+ local para = table.remove (div .content , 1 )
86
+ caption = {pandoc .Plain (para .content )}
58
87
end
59
88
60
89
assert (div .content [1 ].t == " BulletList" ,
@@ -67,16 +96,26 @@ local function process(div)
67
96
assert (# list .content [i ] == 1 , " expected item to contain only one block" )
68
97
assert (list .content [i ][1 ].t == " BulletList" ,
69
98
" expected bullet list, found " .. list .content [i ][1 ].t )
70
- table.insert (rows , list .content [i ][1 ].content )
99
+ local cells = {}
100
+ for _ , cell_content in pairs (list .content [i ][1 ].content ) do
101
+ table.insert (cells , new_cell (cell_content ))
102
+ end
103
+ local row = new_row (cells )
104
+ table.insert (rows , row )
71
105
end
72
106
73
- local headers = table.remove ( rows , 1 )
74
- local aligns , widths = get_colspecs ( div . attr . attributes , # headers )
107
+ local colspecs = get_colspecs ( div . attr . attributes , # rows [ 1 ][ 2 ] )
108
+ local thead_rows = { table.remove ( rows , 1 )}
75
109
76
- local table = pandoc .utils .from_simple_table (
77
- pandoc .SimpleTable (caption , aligns , widths , headers , rows ))
78
- table .attr = div .attr
79
- return {table }
110
+ local table_foot = {{}, {}};
111
+ return pandoc .Table (
112
+ {long = caption , short = {}},
113
+ colspecs ,
114
+ new_table_head (thead_rows ),
115
+ {new_table_body (rows )},
116
+ table_foot ,
117
+ div .attr
118
+ )
80
119
end
81
120
82
121
return {{Div = process }}
0 commit comments