From 07c7cd19459da37372fc888e3e34e7feee284aec Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 24 Jul 2011 23:24:03 -0700 Subject: Docbook writer: Use CALS tables (instead of XHTML tables). Reason: Some older docbook software does not work with XHTML tables. Closes #77. --- src/Text/Pandoc/Writers/Docbook.hs | 36 +- tests/tables.docbook | 758 +++++++++++++++++++------------------ 2 files changed, 409 insertions(+), 385 deletions(-) diff --git a/src/Text/Pandoc/Writers/Docbook.hs b/src/Text/Pandoc/Writers/Docbook.hs index 9d09d46e3..1ca76bfd6 100644 --- a/src/Text/Pandoc/Writers/Docbook.hs +++ b/src/Text/Pandoc/Writers/Docbook.hs @@ -185,24 +185,24 @@ blockToDocbook _ (RawBlock "html" str) = text str -- raw XML block blockToDocbook _ (RawBlock _ _) = empty blockToDocbook _ HorizontalRule = empty -- not semantic blockToDocbook opts (Table caption aligns widths headers rows) = - let alignStrings = map alignmentToString aligns - captionDoc = if null caption + let captionDoc = if null caption then empty - else inTagsIndented "caption" + else inTagsIndented "title" (inlinesToDocbook opts caption) tableType = if isEmpty captionDoc then "informaltable" else "table" - 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 + percent w = show (truncate (100*w) :: Integer) ++ "*" + coltags = vcat $ zipWith (\w al -> selfClosingTag "colspec" + ([("colwidth", percent w) | w > 0] ++ + [("align", alignmentToString al)])) widths aligns head' = if all null headers then empty else inTagsIndented "thead" $ - tableRowToDocbook opts alignStrings "th" headers + tableRowToDocbook opts headers body' = inTagsIndented "tbody" $ - vcat $ map (tableRowToDocbook opts alignStrings "td") rows - in inTagsIndented tableType $ captionDoc $$ coltags $$ head' $$ body' + vcat $ map (tableRowToDocbook opts) rows + in inTagsIndented tableType $ captionDoc $$ + (inTags True "tgroup" [("cols", show (length headers))] $ + coltags $$ head' $$ body') alignmentToString :: Alignment -> [Char] alignmentToString alignment = case alignment of @@ -212,22 +212,16 @@ alignmentToString alignment = case alignment of AlignDefault -> "left" tableRowToDocbook :: WriterOptions - -> [String] - -> String -> [[Block]] -> Doc -tableRowToDocbook opts aligns celltype cols = - inTagsIndented "tr" $ vcat $ - zipWith (tableItemToDocbook opts celltype) aligns cols +tableRowToDocbook opts cols = + inTagsIndented "row" $ vcat $ map (tableItemToDocbook opts) cols tableItemToDocbook :: WriterOptions - -> [Char] - -> [Char] -> [Block] -> Doc -tableItemToDocbook opts tag align item = - let attrib = [("align", align)] - in inTags True tag attrib $ vcat $ map (blockToDocbook opts) item +tableItemToDocbook opts item = + inTags True "entry" [] $ vcat $ map (blockToDocbook opts) item -- | Convert a list of inline elements to Docbook. inlinesToDocbook :: WriterOptions -> [Inline] -> Doc diff --git a/tests/tables.docbook b/tests/tables.docbook index 6483a97c0..6224cf222 100644 --- a/tests/tables.docbook +++ b/tests/tables.docbook @@ -2,401 +2,431 @@ Simple table with caption: - + + + Right + + + Left + + + Center + + + Default + + + + + + + 12 + + + 12 + + + 12 + + + 12 + + + + + 123 + + + 123 + + + 123 + + + 123 + + + + + 1 + + + 1 + + + 1 + + + 1 + + + +
+ Demonstration of simple table syntax. - </caption> - <thead> - <tr> - <th align="right"> - Right - </th> - <th align="left"> - Left - </th> - <th align="center"> - Center - </th> - <th align="left"> - Default - </th> - </tr> - </thead> - <tbody> - <tr> - <td align="right"> - 12 - </td> - <td align="left"> - 12 - </td> - <td align="center"> - 12 - </td> - <td align="left"> - 12 - </td> - </tr> - <tr> - <td align="right"> - 123 - </td> - <td align="left"> - 123 - </td> - <td align="center"> - 123 - </td> - <td align="left"> - 123 - </td> - </tr> - <tr> - <td align="right"> - 1 - </td> - <td align="left"> - 1 - </td> - <td align="center"> - 1 - </td> - <td align="left"> - 1 - </td> - </tr> - </tbody> + + + + + + +
Simple table without caption: - - - - Right - - - Left - - - Center - - - Default - - - - - - - 12 - - - 12 - - - 12 - - - 12 - - - - - 123 - - - 123 - - - 123 - - - 123 - - - - - 1 - - - 1 - - - 1 - - - 1 - - - + + + + + + + + + Right + + + Left + + + Center + + + Default + + + + + + + 12 + + + 12 + + + 12 + + + 12 + + + + + 123 + + + 123 + + + 123 + + + 123 + + + + + 1 + + + 1 + + + 1 + + + 1 + + + + Simple table indented two spaces: - + + + Right + + + Left + + + Center + + + Default + + + + + + + 12 + + + 12 + + + 12 + + + 12 + + + + + 123 + + + 123 + + + 123 + + + 123 + + + + + 1 + + + 1 + + + 1 + + + 1 + + + +
+ Demonstration of simple table syntax. - </caption> - <thead> - <tr> - <th align="right"> - Right - </th> - <th align="left"> - Left - </th> - <th align="center"> - Center - </th> - <th align="left"> - Default - </th> - </tr> - </thead> - <tbody> - <tr> - <td align="right"> - 12 - </td> - <td align="left"> - 12 - </td> - <td align="center"> - 12 - </td> - <td align="left"> - 12 - </td> - </tr> - <tr> - <td align="right"> - 123 - </td> - <td align="left"> - 123 - </td> - <td align="center"> - 123 - </td> - <td align="left"> - 123 - </td> - </tr> - <tr> - <td align="right"> - 1 - </td> - <td align="left"> - 1 - </td> - <td align="center"> - 1 - </td> - <td align="left"> - 1 - </td> - </tr> - </tbody> + + + + + + +
Multiline table with caption: - + + + Centered Header + + + Left Aligned + + + Right Aligned + + + Default aligned + + + + + + + First + + + row + + + 12.0 + + + Example of a row that spans multiple lines. + + + + + Second + + + row + + + 5.0 + + + Here's another one. Note the blank line between rows. + + + +
+ Here's the caption. It may span multiple lines. - </caption> - <col width="15%" /> - <col width="13%" /> - <col width="16%" /> - <col width="33%" /> - <thead> - <tr> - <th align="center"> - Centered Header - </th> - <th align="left"> - Left Aligned - </th> - <th align="right"> - Right Aligned - </th> - <th align="left"> - Default aligned - </th> - </tr> - </thead> - <tbody> - <tr> - <td align="center"> - First - </td> - <td align="left"> - row - </td> - <td align="right"> - 12.0 - </td> - <td align="left"> - Example of a row that spans multiple lines. - </td> - </tr> - <tr> - <td align="center"> - Second - </td> - <td align="left"> - row - </td> - <td align="right"> - 5.0 - </td> - <td align="left"> - Here's another one. Note the blank line between rows. - </td> - </tr> - </tbody> + + + + + + +
Multiline table without caption: - - - - - - - - Centered Header - - - Left Aligned - - - Right Aligned - - - Default aligned - - - - - - - First - - - row - - - 12.0 - - - Example of a row that spans multiple lines. - - - - - Second - - - row - - - 5.0 - - - Here's another one. Note the blank line between rows. - - - + + + + + + + + + Centered Header + + + Left Aligned + + + Right Aligned + + + Default aligned + + + + + + + First + + + row + + + 12.0 + + + Example of a row that spans multiple lines. + + + + + Second + + + row + + + 5.0 + + + Here's another one. Note the blank line between rows. + + + + Table without column headers: - - - - 12 - - - 12 - - - 12 - - - 12 - - - - - 123 - - - 123 - - - 123 - - - 123 - - - - - 1 - - - 1 - - - 1 - - - 1 - - - + + + + + + + + + 12 + + + 12 + + + 12 + + + 12 + + + + + 123 + + + 123 + + + 123 + + + 123 + + + + + 1 + + + 1 + + + 1 + + + 1 + + + + Multiline table without column headers: - - - - - - - - First - - - row - - - 12.0 - - - Example of a row that spans multiple lines. - - - - - Second - - - row - - - 5.0 - - - Here's another one. Note the blank line between rows. - - - + + + + + + + + + First + + + row + + + 12.0 + + + Example of a row that spans multiple lines. + + + + + Second + + + row + + + 5.0 + + + Here's another one. Note the blank line between rows. + + + + -- cgit v1.2.3