diff options
author | Nils Carlson <nils@nilscarlson.se> | 2020-11-21 20:42:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-21 12:42:43 -0800 |
commit | ae52918faa36ad59deca3561acce79ad6d3ea0c2 (patch) | |
tree | fda9b54c36f0629c1c99b5818830b993bdd05451 /src | |
parent | 7db2cf5d2f637fc73377e32af776002e3670ef50 (diff) | |
download | pandoc-ae52918faa36ad59deca3561acce79ad6d3ea0c2.tar.gz |
OpenDocument writer: Table text width support (#6792)
Support for table width as a percentage of text width by summing
width of columns and verifying that the sum is > 0 and <= 1.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Writers/OpenDocument.hs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Writers/OpenDocument.hs b/src/Text/Pandoc/Writers/OpenDocument.hs index 8f010d766..789dbe9b0 100644 --- a/src/Text/Pandoc/Writers/OpenDocument.hs +++ b/src/Text/Pandoc/Writers/OpenDocument.hs @@ -407,13 +407,14 @@ blockToOpenDocument o bs fromWidth (ColWidth w) | w > 0 = w fromWidth _ = 0 widths = map fromWidth mwidths + textWidth = sum widths columnIds = zip genIds widths mkColumn n = selfClosingTag "table:table-column" [("table:style-name", name <> "." <> T.singleton (fst n))] columns = map mkColumn columnIds paraHStyles = paraTableStyles "Heading" pn aligns paraStyles = paraTableStyles "Contents" (pn + length (newPara paraHStyles)) aligns newPara = map snd . filter (not . isEmpty . snd) - addTableStyle $ tableStyle tn columnIds + addTableStyle $ tableStyle tn textWidth columnIds mapM_ addParaStyle . newPara $ paraHStyles ++ paraStyles captionDoc <- if null c then return empty @@ -684,14 +685,19 @@ listLevelStyle i = , ("fo:margin-left", indent <> "in") ] -tableStyle :: Int -> [(Char,Double)] -> Doc Text -tableStyle num wcs = +tableStyle :: Int -> Double -> [(Char,Double)] -> Doc Text +tableStyle num textWidth wcs = let tableId = "Table" <> tshow (num + 1) + tableWidthAttr :: [(Text,Text)] + tableWidthAttr + | textWidth <= 1 && textWidth > 0 = [("style:rel-width", + T.pack (show (round (textWidth * 100) :: Int) <> "%"))] + | otherwise = [] table = inTags True "style:style" [("style:name", tableId) ,("style:family", "table")] $ selfClosingTag "style:table-properties" - [("table:align" , "center")] + (("table:align", "center") : tableWidthAttr) colStyle (c,0) = selfClosingTag "style:style" [ ("style:name" , tableId <> "." <> T.singleton c) , ("style:family", "table-column" )] |