git.iko.soy/typeable/pandoc
on master help sign in
Include classes on tr elements in HTML output: "header", "odd", "even".

This allows tables to be styled with lines in alternating colors. Resolves Issue #91. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1467 788f1e2b-df1e-0410-8736-df70ead52e1b

commit5b422262d3889c6b303b7942505ac164bd245546 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 18 Oct 2008, 23:14 (18 years ago) parent2122aa5
2 files changed+23−22
Text/Pandoc/Writers/HTML.hs+5−4 tests/tables.html+18−18
Text/Pandoc/Writers/HTML.hs+5−4
@@ -375,7 +375,7 @@ blockToHtml opts (Table capt aligns widths headers rows') = do
375375 else inlineListToHtml opts capt >>= return . caption
376376 colHeads <- colHeadsToHtml opts alignStrings
377377 widths headers
378− rows'' <- mapM (tableRowToHtml opts alignStrings) rows'
378+ rows'' <- zipWithM (tableRowToHtml opts alignStrings) (cycle ["odd", "even"]) rows'
379379 return $ table $ captionDoc +++ colHeads +++ rows''
380380
381381colHeadsToHtml :: WriterOptions
@@ -387,7 +387,7 @@ colHeadsToHtml opts alignStrings widths headers = do
387387 heads <- sequence $ zipWith3
388388 (\alignment columnwidth item -> tableItemToHtml opts th alignment columnwidth item)
389389 alignStrings widths headers
390− return $ tr $ toHtmlFromList heads
390+ return $ tr ! [theclass "header"] $ toHtmlFromList heads
391391
392392alignmentToString :: Alignment -> [Char]
393393alignmentToString alignment = case alignment of
@@ -398,11 +398,12 @@ alignmentToString alignment = case alignment of
398398
399399tableRowToHtml :: WriterOptions
400400 -> [[Char]]
401+ -> String
401402 -> [[Block]]
402403 -> State WriterState Html
403−tableRowToHtml opts aligns columns =
404+tableRowToHtml opts aligns rowclass columns =
404405 (sequence $ zipWith3 (tableItemToHtml opts td) aligns (repeat 0) columns) >>=
405− return . tr . toHtmlFromList
406+ return . (tr ! [theclass rowclass]) . toHtmlFromList
406407
407408tableItemToHtml :: WriterOptions
408409 -> (Html -> Html)
tests/tables.html+18−18
@@ -3,7 +3,7 @@
33><table
44><caption
55 >Demonstration of simple table syntax.</caption
6− ><tr
6+ ><tr class="header"
77 ><th align="right" style="width: 15%;"
88 >Right</th
99 ><th align="left" style="width: 8%;"
@@ -13,7 +13,7 @@
1313 ><th align="left" style="width: 12%;"
1414 >Default</th
1515 ></tr
16− ><tr
16+ ><tr class="odd"
1717 ><td align="right"
1818 >12</td
1919 ><td align="left"
@@ -23,7 +23,7 @@
2323 ><td align="left"
2424 >12</td
2525 ></tr
26− ><tr
26+ ><tr class="even"
2727 ><td align="right"
2828 >123</td
2929 ><td align="left"
@@ -33,7 +33,7 @@
3333 ><td align="left"
3434 >123</td
3535 ></tr
36− ><tr
36+ ><tr class="odd"
3737 ><td align="right"
3838 >1</td
3939 ><td align="left"
@@ -47,7 +47,7 @@
4747><p
4848>Simple table without caption:</p
4949><table
50−><tr
50+><tr class="header"
5151 ><th align="right" style="width: 15%;"
5252 >Right</th
5353 ><th align="left" style="width: 8%;"
@@ -57,7 +57,7 @@
5757 ><th align="left" style="width: 12%;"
5858 >Default</th
5959 ></tr
60− ><tr
60+ ><tr class="odd"
6161 ><td align="right"
6262 >12</td
6363 ><td align="left"
@@ -67,7 +67,7 @@
6767 ><td align="left"
6868 >12</td
6969 ></tr
70− ><tr
70+ ><tr class="even"
7171 ><td align="right"
7272 >123</td
7373 ><td align="left"
@@ -77,7 +77,7 @@
7777 ><td align="left"
7878 >123</td
7979 ></tr
80− ><tr
80+ ><tr class="odd"
8181 ><td align="right"
8282 >1</td
8383 ><td align="left"
@@ -93,7 +93,7 @@
9393><table
9494><caption
9595 >Demonstration of simple table syntax.</caption
96− ><tr
96+ ><tr class="header"
9797 ><th align="right" style="width: 15%;"
9898 >Right</th
9999 ><th align="left" style="width: 8%;"
@@ -103,7 +103,7 @@
103103 ><th align="left" style="width: 12%;"
104104 >Default</th
105105 ></tr
106− ><tr
106+ ><tr class="odd"
107107 ><td align="right"
108108 >12</td
109109 ><td align="left"
@@ -113,7 +113,7 @@
113113 ><td align="left"
114114 >12</td
115115 ></tr
116− ><tr
116+ ><tr class="even"
117117 ><td align="right"
118118 >123</td
119119 ><td align="left"
@@ -123,7 +123,7 @@
123123 ><td align="left"
124124 >123</td
125125 ></tr
126− ><tr
126+ ><tr class="odd"
127127 ><td align="right"
128128 >1</td
129129 ><td align="left"
@@ -139,7 +139,7 @@
139139><table
140140><caption
141141 >Here's the caption. It may span multiple lines.</caption
142− ><tr
142+ ><tr class="header"
143143 ><th align="center" style="width: 15%;"
144144 >Centered Header</th
145145 ><th align="left" style="width: 13%;"
@@ -149,7 +149,7 @@
149149 ><th align="left" style="width: 33%;"
150150 >Default aligned</th
151151 ></tr
152− ><tr
152+ ><tr class="odd"
153153 ><td align="center"
154154 >First</td
155155 ><td align="left"
@@ -159,7 +159,7 @@
159159 ><td align="left"
160160 >Example of a row that spans multiple lines.</td
161161 ></tr
162− ><tr
162+ ><tr class="even"
163163 ><td align="center"
164164 >Second</td
165165 ><td align="left"
@@ -173,7 +173,7 @@
173173><p
174174>Multiline table without caption:</p
175175><table
176−><tr
176+><tr class="header"
177177 ><th align="center" style="width: 15%;"
178178 >Centered Header</th
179179 ><th align="left" style="width: 13%;"
@@ -183,7 +183,7 @@
183183 ><th align="left" style="width: 33%;"
184184 >Default aligned</th
185185 ></tr
186− ><tr
186+ ><tr class="odd"
187187 ><td align="center"
188188 >First</td
189189 ><td align="left"
@@ -193,7 +193,7 @@
193193 ><td align="left"
194194 >Example of a row that spans multiple lines.</td
195195 ></tr
196− ><tr
196+ ><tr class="even"
197197 ><td align="center"
198198 >Second</td
199199 ><td align="left"