diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-10-18 23:14:59 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2008-10-18 23:14:59 +0000 |
commit | 5b422262d3889c6b303b7942505ac164bd245546 (patch) | |
tree | eda2781cf181a74ac943cebe6fda701079b37c7e | |
parent | 2122aa5359ada1ea7f56bb4280b004e55ea587d9 (diff) | |
download | pandoc-5b422262d3889c6b303b7942505ac164bd245546.tar.gz |
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
-rw-r--r-- | Text/Pandoc/Writers/HTML.hs | 9 | ||||
-rw-r--r-- | tests/tables.html | 36 |
2 files changed, 23 insertions, 22 deletions
diff --git a/Text/Pandoc/Writers/HTML.hs b/Text/Pandoc/Writers/HTML.hs index 0870c7e18..628e784ed 100644 --- a/Text/Pandoc/Writers/HTML.hs +++ b/Text/Pandoc/Writers/HTML.hs @@ -375,7 +375,7 @@ blockToHtml opts (Table capt aligns widths headers rows') = do else inlineListToHtml opts capt >>= return . caption colHeads <- colHeadsToHtml opts alignStrings widths headers - rows'' <- mapM (tableRowToHtml opts alignStrings) rows' + rows'' <- zipWithM (tableRowToHtml opts alignStrings) (cycle ["odd", "even"]) rows' return $ table $ captionDoc +++ colHeads +++ rows'' colHeadsToHtml :: WriterOptions @@ -387,7 +387,7 @@ colHeadsToHtml opts alignStrings widths headers = do heads <- sequence $ zipWith3 (\alignment columnwidth item -> tableItemToHtml opts th alignment columnwidth item) alignStrings widths headers - return $ tr $ toHtmlFromList heads + return $ tr ! [theclass "header"] $ toHtmlFromList heads alignmentToString :: Alignment -> [Char] alignmentToString alignment = case alignment of @@ -398,11 +398,12 @@ alignmentToString alignment = case alignment of tableRowToHtml :: WriterOptions -> [[Char]] + -> String -> [[Block]] -> State WriterState Html -tableRowToHtml opts aligns columns = +tableRowToHtml opts aligns rowclass columns = (sequence $ zipWith3 (tableItemToHtml opts td) aligns (repeat 0) columns) >>= - return . tr . toHtmlFromList + return . (tr ! [theclass rowclass]) . toHtmlFromList tableItemToHtml :: WriterOptions -> (Html -> Html) diff --git a/tests/tables.html b/tests/tables.html index 7ae87b024..7626b326d 100644 --- a/tests/tables.html +++ b/tests/tables.html @@ -3,7 +3,7 @@ ><table ><caption >Demonstration of simple table syntax.</caption - ><tr + ><tr class="header" ><th align="right" style="width: 15%;" >Right</th ><th align="left" style="width: 8%;" @@ -13,7 +13,7 @@ ><th align="left" style="width: 12%;" >Default</th ></tr - ><tr + ><tr class="odd" ><td align="right" >12</td ><td align="left" @@ -23,7 +23,7 @@ ><td align="left" >12</td ></tr - ><tr + ><tr class="even" ><td align="right" >123</td ><td align="left" @@ -33,7 +33,7 @@ ><td align="left" >123</td ></tr - ><tr + ><tr class="odd" ><td align="right" >1</td ><td align="left" @@ -47,7 +47,7 @@ ><p >Simple table without caption:</p ><table -><tr +><tr class="header" ><th align="right" style="width: 15%;" >Right</th ><th align="left" style="width: 8%;" @@ -57,7 +57,7 @@ ><th align="left" style="width: 12%;" >Default</th ></tr - ><tr + ><tr class="odd" ><td align="right" >12</td ><td align="left" @@ -67,7 +67,7 @@ ><td align="left" >12</td ></tr - ><tr + ><tr class="even" ><td align="right" >123</td ><td align="left" @@ -77,7 +77,7 @@ ><td align="left" >123</td ></tr - ><tr + ><tr class="odd" ><td align="right" >1</td ><td align="left" @@ -93,7 +93,7 @@ ><table ><caption >Demonstration of simple table syntax.</caption - ><tr + ><tr class="header" ><th align="right" style="width: 15%;" >Right</th ><th align="left" style="width: 8%;" @@ -103,7 +103,7 @@ ><th align="left" style="width: 12%;" >Default</th ></tr - ><tr + ><tr class="odd" ><td align="right" >12</td ><td align="left" @@ -113,7 +113,7 @@ ><td align="left" >12</td ></tr - ><tr + ><tr class="even" ><td align="right" >123</td ><td align="left" @@ -123,7 +123,7 @@ ><td align="left" >123</td ></tr - ><tr + ><tr class="odd" ><td align="right" >1</td ><td align="left" @@ -139,7 +139,7 @@ ><table ><caption >Here's the caption. It may span multiple lines.</caption - ><tr + ><tr class="header" ><th align="center" style="width: 15%;" >Centered Header</th ><th align="left" style="width: 13%;" @@ -149,7 +149,7 @@ ><th align="left" style="width: 33%;" >Default aligned</th ></tr - ><tr + ><tr class="odd" ><td align="center" >First</td ><td align="left" @@ -159,7 +159,7 @@ ><td align="left" >Example of a row that spans multiple lines.</td ></tr - ><tr + ><tr class="even" ><td align="center" >Second</td ><td align="left" @@ -173,7 +173,7 @@ ><p >Multiline table without caption:</p ><table -><tr +><tr class="header" ><th align="center" style="width: 15%;" >Centered Header</th ><th align="left" style="width: 13%;" @@ -183,7 +183,7 @@ ><th align="left" style="width: 33%;" >Default aligned</th ></tr - ><tr + ><tr class="odd" ><td align="center" >First</td ><td align="left" @@ -193,7 +193,7 @@ ><td align="left" >Example of a row that spans multiple lines.</td ></tr - ><tr + ><tr class="even" ><td align="center" >Second</td ><td align="left" |