aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Writers/Docbook.hs
diff options
context:
space:
mode:
authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-09 04:34:07 +0000
committerfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b>2010-03-09 04:34:07 +0000
commit0cf4652ad6cb59f5c10058f1dfc03cb2b2ab620d (patch)
tree2fdbca67f26c64b681c14a781f4f81d601702f5d /src/Text/Pandoc/Writers/Docbook.hs
parentb15fccd364cb5f8a472729109eb6faab1b3e435b (diff)
downloadpandoc-0cf4652ad6cb59f5c10058f1dfc03cb2b2ab620d.tar.gz
Docbook writer: handle headerless tables.
In addition, use cols, thead, and tbody. git-svn-id: https://pandoc.googlecode.com/svn/trunk@1874 788f1e2b-df1e-0410-8736-df70ead52e1b
Diffstat (limited to 'src/Text/Pandoc/Writers/Docbook.hs')
-rw-r--r--src/Text/Pandoc/Writers/Docbook.hs53
1 files changed, 25 insertions, 28 deletions
diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs
index 996e50e6b..153f93391 100644
--- a/src/Text/Pandoc/Writers/Docbook.hs
+++ b/src/Text/Pandoc/Writers/Docbook.hs
@@ -168,25 +168,22 @@ blockToDocbook _ HorizontalRule = empty -- not semantic
blockToDocbook opts (Table caption aligns widths headers rows) =
let alignStrings = map alignmentToString aligns
captionDoc = if null caption
- then empty
- else inTagsIndented "caption"
- (inlinesToDocbook opts caption)
+ then empty
+ else inTagsIndented "caption"
+ (inlinesToDocbook opts caption)
tableType = if isEmpty captionDoc then "informaltable" else "table"
- in inTagsIndented tableType $ captionDoc $$
- (colHeadsToDocbook opts alignStrings widths headers) $$
- (vcat $ map (tableRowToDocbook opts alignStrings) rows)
-
-colHeadsToDocbook :: WriterOptions
- -> [[Char]]
- -> [Double]
- -> [[Block]]
- -> Doc
-colHeadsToDocbook _ _ _ hs | all null hs = empty
-colHeadsToDocbook opts alignStrings widths headers =
- let heads = zipWith3 (\align width item ->
- tableItemToDocbook opts "th" align width item)
- alignStrings widths headers
- in inTagsIndented "tr" $ vcat heads
+ percent w = show (truncate (100*w) :: Integer) ++ "%"
+ coltags = if all (== 0.0) widths
+ then empty
+ else vcat $ map (\w ->
+ selfClosingTag "col" [("width", percent w)]) widths
+ head' = if all null headers
+ then empty
+ else inTagsIndented "thead" $
+ tableRowToDocbook opts alignStrings "th" headers
+ body' = inTagsIndented "tbody" $
+ vcat $ map (tableRowToDocbook opts alignStrings "td") rows
+ in inTagsIndented tableType $ captionDoc $$ coltags $$ head' $$ body'
alignmentToString :: Alignment -> [Char]
alignmentToString alignment = case alignment of
@@ -195,22 +192,22 @@ alignmentToString alignment = case alignment of
AlignCenter -> "center"
AlignDefault -> "left"
-tableRowToDocbook :: WriterOptions -> [[Char]] -> [[Block]] -> Doc
-tableRowToDocbook opts aligns cols = inTagsIndented "tr" $
- vcat $ zipWith3 (tableItemToDocbook opts "td") aligns (repeat 0) cols
+tableRowToDocbook :: WriterOptions
+ -> [String]
+ -> String
+ -> [[Block]]
+ -> Doc
+tableRowToDocbook opts aligns celltype cols =
+ inTagsIndented "tr" $ vcat $
+ zipWith (tableItemToDocbook opts celltype) aligns cols
tableItemToDocbook :: WriterOptions
-> [Char]
-> [Char]
- -> Double
-> [Block]
-> Doc
-tableItemToDocbook opts tag align width item =
- let attrib = [("align", align)] ++
- if width /= 0
- then [("style", "{width: " ++
- show (truncate (100*width) :: Integer) ++ "%;}")]
- else []
+tableItemToDocbook opts tag align item =
+ let attrib = [("align", align)]
in inTags True tag attrib $ vcat $ map (blockToDocbook opts) item
-- | Take list of inline elements and return wrapped doc.