diff options
author | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-01-15 19:52:42 +0000 |
---|---|---|
committer | fiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> | 2007-01-15 19:52:42 +0000 |
commit | 60989d0637780787fb337b94af212f1ee9e1ae22 (patch) | |
tree | 95b5caa1e7e304a47739532a9c4d3767ce54435c /src/Text/Pandoc/Writers/HTML.hs | |
parent | 4224d913880e4f77a358cda868c9d1ca75820506 (diff) | |
download | pandoc-60989d0637780787fb337b94af212f1ee9e1ae22.tar.gz |
Added support for tables in markdown reader and in LaTeX,
DocBook, and HTML writers. The syntax is documented in
README. Tests have been added to the test suite.
git-svn-id: https://pandoc.googlecode.com/svn/trunk@493 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Writers/HTML.hs')
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index e119a5c87..d38a57556 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -186,6 +186,38 @@ blockToHtml opts (Header level lst) = if ((level > 0) && (level <= 6)) then inTagsSimple ("h" ++ show level) contents else inTagsSimple "p" contents +blockToHtml opts (Table caption aligns widths headers rows) = + let alignStrings = map alignmentToString aligns + captionDoc = if null caption + then empty + else inTagsSimple "caption" + (inlineListToHtml opts caption) in + inTagsIndented "table" $ captionDoc $$ + (colHeadsToHtml opts alignStrings widths headers) $$ + (vcat $ map (tableRowToHtml opts alignStrings) rows) + +colHeadsToHtml opts alignStrings widths headers = + let heads = zipWith3 + (\align width item -> tableItemToHtml opts "th" align width item) + alignStrings widths headers in + inTagsIndented "tr" $ vcat heads + +alignmentToString alignment = case alignment of + AlignLeft -> "left" + AlignRight -> "right" + AlignCenter -> "center" + AlignDefault -> "left" + +tableRowToHtml opts aligns cols = + inTagsIndented "tr" $ vcat $ zipWith3 (tableItemToHtml opts "td") aligns (repeat 0) cols + +tableItemToHtml opts tag align width item = + let attrib = [("align", align)] ++ + if (width /= 0) + then [("style", "{width: " ++ + show (truncate (100*width)) ++ "%;}")] + else [] in + inTags False tag attrib $ vcat $ map (blockToHtml opts) item listItemToHtml :: WriterOptions -> [Block] -> Doc listItemToHtml opts list = |