@@ -168,25 +168,22 @@ blockToDocbook _ HorizontalRule = empty -- not semantic
168168blockToDocbook opts (Table caption aligns widths headers rows) =
169169 let alignStrings = map alignmentToString aligns
170170 captionDoc = if null caption
171− then empty
172− else inTagsIndented "caption"
173− (inlinesToDocbook opts caption)
171+ then empty
172+ else inTagsIndented "caption"
173+ (inlinesToDocbook opts caption)
174174 tableType = if isEmpty captionDoc then "informaltable" else "table"
175− in inTagsIndented tableType $ captionDoc $$
176− (colHeadsToDocbook opts alignStrings widths headers) $$
177− (vcat $ map (tableRowToDocbook opts alignStrings) rows)
178−
179−colHeadsToDocbook :: WriterOptions
180− -> [[Char]]
181− -> [Double]
182− -> [[Block]]
183− -> Doc
184−colHeadsToDocbook _ _ _ hs | all null hs = empty
185−colHeadsToDocbook opts alignStrings widths headers =
186− let heads = zipWith3 (\align width item ->
187− tableItemToDocbook opts "th" align width item)
188− alignStrings widths headers
189− in inTagsIndented "tr" $ vcat heads
175+ percent w = show (truncate (100*w) :: Integer) ++ "%"
176+ coltags = if all (== 0.0) widths
177+ then empty
178+ else vcat $ map (\w ->
179+ selfClosingTag "col" [("width", percent w)]) widths
180+ head' = if all null headers
181+ then empty
182+ else inTagsIndented "thead" $
183+ tableRowToDocbook opts alignStrings "th" headers
184+ body' = inTagsIndented "tbody" $
185+ vcat $ map (tableRowToDocbook opts alignStrings "td") rows
186+ in inTagsIndented tableType $ captionDoc $$ coltags $$ head' $$ body'
190187
191188alignmentToString :: Alignment -> [Char]
192189alignmentToString alignment = case alignment of
@@ -195,22 +192,22 @@ alignmentToString alignment = case alignment of
195192 AlignCenter -> "center"
196193 AlignDefault -> "left"
197194
198−tableRowToDocbook :: WriterOptions -> [[Char]] -> [[Block]] -> Doc
199−tableRowToDocbook opts aligns cols = inTagsIndented "tr" $
200− vcat $ zipWith3 (tableItemToDocbook opts "td") aligns (repeat 0) cols
195+tableRowToDocbook :: WriterOptions
196+ -> [String]
197+ -> String
198+ -> [[Block]]
199+ -> Doc
200+tableRowToDocbook opts aligns celltype cols =
201+ inTagsIndented "tr" $ vcat $
202+ zipWith (tableItemToDocbook opts celltype) aligns cols
201203
202204tableItemToDocbook :: WriterOptions
203205 -> [Char]
204206 -> [Char]
205− -> Double
206207 -> [Block]
207208 -> Doc
208−tableItemToDocbook opts tag align width item =
209− let attrib = [("align", align)] ++
210− if width /= 0
211− then [("style", "{width: " ++
212− show (truncate (100*width) :: Integer) ++ "%;}")]
213− else []
209+tableItemToDocbook opts tag align item =
210+ let attrib = [("align", align)]
214211 in inTags True tag attrib $ vcat $ map (blockToDocbook opts) item
215212
216213-- | Take list of inline elements and return wrapped doc.