diff options
author | Nils Carlson <nils@nilscarlson.se> | 2020-11-21 00:05:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-20 16:05:56 -0800 |
commit | 56ceaf49dc1627ed05febcccae9899a68b3da99f (patch) | |
tree | 3d1e8a8d3909cc43e086aca5e93c3f85fed9b607 /src | |
parent | 9a4097640f052468054105cde8ef342ac8a1db30 (diff) | |
download | pandoc-56ceaf49dc1627ed05febcccae9899a68b3da99f.tar.gz |
DocBook reader: Table text width support (#6791)
Table width in relation to text width is not natively supported
by docbook but is by the docbook fo stylesheets through an XML
processing instruction, <?dbfo table-width="50%"?> .
Implement support for this instruction in the DocBook reader.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index 5ba48e704..b0846e345 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -960,12 +960,22 @@ parseBlock (Elem e) = let aligns = case colspecs of [] -> replicate numrows AlignDefault cs -> map toAlignment cs + let parseWidth s = safeRead (T.filter (\x -> (x >= '0' && x <= '9') + || x == '.') s) + let textWidth = case filterChild (named "?dbfo") e of + Just d -> case attrValue "table-width" d of + "" -> 1.0 + w -> fromMaybe 100.0 (parseWidth w) / 100.0 + Nothing -> 1.0 let widths = case colspecs of [] -> replicate numrows ColWidthDefault cs -> let ws = map toWidth cs in case sequence ws of - Just ws' -> let tot = sum ws' - in ColWidth . (/ tot) <$> ws' + Just ws' -> let colTot = sum ws' + scale + | textWidth == 1.0 = (/ colTot) + | otherwise = (* (textWidth / colTot) ) + in ColWidth . scale <$> ws' Nothing -> replicate numrows ColWidthDefault let toRow = Row nullAttr toHeaderRow l = [toRow l | not (null l)] |