1
1
--[[
2
2
column-div - leverage Pandoc native divs to make balanced and unbalanced column
3
- and other things based on class name and attirbutes .
3
+ and other things based on class name and attributes .
4
4
5
5
Copyright: © 2021 Christophe Agathon <[email protected] >
6
6
License: MIT – see LICENSE file for details
@@ -50,7 +50,7 @@ function Div(div)
50
50
end
51
51
-- build the returned list of blocks
52
52
begin_env = List :new {pandoc .RawBlock (' tex' ,
53
- ' \\ begin' .. ' {' .. env .. ' }' .. options )}
53
+ ' \\ begin{' .. env .. ' }' .. options )}
54
54
end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{' .. env .. ' }' )}
55
55
returned_list = begin_env .. div .content .. end_env
56
56
@@ -69,8 +69,17 @@ function Div(div)
69
69
if opt then options = ' [' .. opt .. ' ]' .. options end
70
70
71
71
begin_env = List :new {pandoc .RawBlock (' tex' ,
72
- ' \\ begin' .. ' {' .. ' minipage' .. ' }' .. options )}
73
- end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{' .. ' minipage' .. ' }' )}
72
+ ' \\ begin{minipage}' .. options )}
73
+ end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{minipage}' )}
74
+
75
+ -- add support for color TODO: background
76
+ opt = div .attributes .color
77
+ if opt then
78
+ begin_env = begin_env .. List :new {pandoc .RawBlock (' tex' ,
79
+ ' \\ color{' .. opt .. ' }' )}
80
+ div .attributes .color = nil -- consume attribute
81
+ end
82
+
74
83
returned_list = begin_env .. div .content .. end_env
75
84
76
85
elseif div .classes :includes (' columns' ) then
@@ -109,25 +118,39 @@ function Div(div)
109
118
end
110
119
111
120
begin_env = List :new {pandoc .RawBlock (' tex' ,
112
- ' \\ begin' .. ' {' .. env .. ' }' .. options )}
121
+ ' \\ begin{' .. env .. ' }' .. options )}
113
122
end_env = List :new {pandoc .RawBlock (' tex' , ' \\ end{' .. env .. ' }' )}
114
123
returned_list = begin_env .. div .content .. end_env
115
124
end
116
125
117
- -- if the format is html add support for multi columns
126
+ -- if the format is html add what is not already done by plain pandoc
118
127
elseif FORMAT :match ' html' then
128
+ local style
129
+ -- add support for multi columns
119
130
opt = div .attributes [' column-count' ]
120
131
if opt then
121
- -- add column-count to style if it exists
122
- if div .attributes .style then
123
- div .attributes .style = div .attributes .style ..
124
- ' ; column-count: ' .. opt
125
- else
126
- div .attributes .style = ' column-count: ' .. opt
127
- end
132
+ -- add column-count to style
133
+ style = ' column-count: ' .. opt .. ' ;' .. (style or ' ' )
128
134
div .attributes [' column-count' ] = nil
129
135
-- column-count is "consumed" by the filter otherwise it would appear as
130
136
-- data-column-count="…" in the resulting document
137
+ end
138
+ -- add support for color TODO: latex counterpart
139
+ opt = div .attributes .color
140
+ if opt then
141
+ -- add color to style
142
+ style = ' color: ' .. opt .. ' ;' .. (style or ' ' )
143
+ div .attributes .color = nil -- consume attribute
144
+ end
145
+ opt = div .attributes [' background-color' ]
146
+ if opt then
147
+ -- add color to style
148
+ style = ' background-color: ' .. opt .. ' ;' .. (style or ' ' )
149
+ div .attributes [' background-color' ] = nil -- consume attribute
150
+ end
151
+ -- if we have style then build returned list
152
+ if style then
153
+ div .attributes .style = style .. (div .attributes .style or ' ' )
131
154
returned_list = List :new {pandoc .Div (div .content , div .attr )}
132
155
end
133
156
end
0 commit comments