Skip to content

Commit b503494

Browse files
committed
Fix dupplicate attribute issue and clean the code
1 parent 8a2fbca commit b503494

File tree

4 files changed

+18
-28
lines changed

4 files changed

+18
-28
lines changed

column-div/column-div.lua

+7-18
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ Usage: classname attributes
1414
balanced columns .columns column-count
1515
columns(container) .columns
1616
column(each column) .column width(percent) valign(t|c|b)
17-
other divs .<somename> data-latex
1817
1918
See README.md for details
2019
@@ -23,9 +22,6 @@ Note: You need to include multicol latex package to get balanced columns
2322
I tried to use well known html or latex parameter.
2423
Even if lua doen't like hyphens like in column-count.
2524
26-
Bugs: * html rendering throws a warning [WARNING] Ignoring duplicate attribute style="width:60%;".
27-
when width AND color are set and totally ignore the width
28-
attribute. Don't know if this bug is mine
2925
--]]
3026
local List = require 'pandoc.List'
3127

@@ -39,9 +35,6 @@ function Div(div)
3935

4036
-- if the div has no class, the object is left unchanged
4137
-- if the div has no class but an id, div.classes ~= nil
42-
-- TODO: use a div with no class to build a 'scope' in Latex
43-
-- usefull for user who would throw inline Latex code and limit it's
44-
-- effect.
4538
if not div.classes or #div.classes == 0 then return nil end
4639

4740
-- if the format is latex then do minipage and others (like multicol)
@@ -101,16 +94,6 @@ function Div(div)
10194
-- process supported options
10295
opt = div.attributes['column-count']
10396
if opt then options = '{' .. opt .. '}' end
104-
--[[ This functionality will be moved in another filter since it can't be consistent with the positionless classname requirement
105-
else
106-
-- Latex skilled users can use arbitrary environments passed as
107-
-- the first (and only signifiant) class name.
108-
env = div.classes[1]
109-
-- default if no known options
110-
if options == '' and div.attributes['data-latex'] then
111-
options = div.attributes['data-latex']
112-
end
113-
--]]
11497
end
11598

11699
begin_env = List:new{pandoc.RawBlock('tex',
@@ -146,9 +129,15 @@ function Div(div)
146129
end
147130
-- if we have style then build returned list
148131
if style then
132+
-- process width attribute since Pandoc complains about duplicate
133+
-- style attribute and ignores it.
134+
opt = div.attributes.width
135+
if opt then
136+
style = 'width: ' .. opt .. ';' .. (style or '')
137+
div.attributes.width = nil -- consume attribute
138+
end
149139
div.attributes.style = style .. (div.attributes.style or '')
150140
returned_list = List:new{pandoc.Div(div.content, div.attr)}
151-
--returned_list = List:new{pandoc.Div(div.content)}
152141
end
153142
end
154143
return returned_list

column-div/expected.html

+7-6
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,10 @@
145145
ul.task-list{list-style: none;}
146146
.display.math{display: block; text-align: center; margin: 0.5rem auto;}
147147
</style>
148+
148149
<!--[if lt IE 9]>
149150
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
150151
<![endif]-->
151-
152152
</head>
153153
<body>
154154
<header id="title-block-header">
@@ -167,9 +167,9 @@ <h2 id="three-columns">Three columns</h2>
167167
</div>
168168
<h2 id="two-uneven-columns">Two uneven columns</h2>
169169
<div class="columns">
170-
<div class="column" data-valign="b" style="width:40%;">
170+
<div class="column" data-valign="b" style="width:30%;">
171171
<p>contents…</p>
172-
</div><div class="column" data-valign="b" style="width:60%;">
172+
</div><div class="column" data-valign="b" style="width:70%;">
173173
<p>contents…</p>
174174
</div>
175175
</div>
@@ -199,14 +199,15 @@ <h2 id="columns-in-columns">Columns in columns</h2>
199199
</div>
200200
<h2 id="columns-and-colors">Columns and Colors</h2>
201201
<div class="columns">
202-
<div class="column" style="color: blue;">
202+
<div class="column" style="width: 40%;color: blue;">
203203
<p>blue content…</p>
204-
</div><div class="column" style="background-color: red;">
204+
</div><div class="column" style="width: 60%;background-color: red;">
205205
<p>content on red background…</p>
206206
</div>
207207
</div>
208208
<div class="columns">
209-
<div class="column" style="background-color: red;color: blue;">
209+
<div class="column"
210+
style="width: 60%;background-color: red;color: blue;">
210211
<p>blue content on red background…</p>
211212
</div><div class="column" style="width:40%;">
212213
<p>contents…</p>

column-div/expected.tex

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ \subsection{Two uneven columns}\label{two-uneven-columns}}
2424

2525
\mbox{
2626

27-
\begin{minipage}[b]{0.4\columnwidth}
27+
\begin{minipage}[b]{0.3\columnwidth}
2828

2929
contents\ldots{}
3030

3131
\end{minipage}
3232

33-
\begin{minipage}[b]{0.6\columnwidth}
33+
\begin{minipage}[b]{0.7\columnwidth}
3434

3535
contents\ldots{}
3636

column-div/sample.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ content...
2626

2727
## Two uneven columns
2828
:::::: {.columns}
29-
::: {.column width="40%" valign="b"}
29+
::: {.column width="30%" valign="b"}
3030
contents...
3131
:::
32-
::: {.column width="60%" valign="b"}
32+
::: {.column width="70%" valign="b"}
3333
contents...
3434
:::
3535
::::::

0 commit comments

Comments
 (0)