git.iko.soy/typeable/pandoc
on master help sign in
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.

commit56ceaf49dc1627ed05febcccae9899a68b3da99f authorNils Carlson <nils@nilscarlson.se> dateSat 21 Nov 2020, 00:05 (6 years ago) parent9a40976
2 files changed+44−2
src/Text/Pandoc/Readers/DocBook.hs+12−2 test/command/6791.md+32
src/Text/Pandoc/Readers/DocBook.hs+12−2
@@ -960,12 +960,22 @@ parseBlock (Elem e) =
960960 let aligns = case colspecs of
961961 [] -> replicate numrows AlignDefault
962962 cs -> map toAlignment cs
963+ let parseWidth s = safeRead (T.filter (\x -> (x >= '0' && x <= '9')
964+ || x == '.') s)
965+ let textWidth = case filterChild (named "?dbfo") e of
966+ Just d -> case attrValue "table-width" d of
967+ "" -> 1.0
968+ w -> fromMaybe 100.0 (parseWidth w) / 100.0
969+ Nothing -> 1.0
963970 let widths = case colspecs of
964971 [] -> replicate numrows ColWidthDefault
965972 cs -> let ws = map toWidth cs
966973 in case sequence ws of
967− Just ws' -> let tot = sum ws'
968− in ColWidth . (/ tot) <$> ws'
974+ Just ws' -> let colTot = sum ws'
975+ scale
976+ | textWidth == 1.0 = (/ colTot)
977+ | otherwise = (* (textWidth / colTot) )
978+ in ColWidth . scale <$> ws'
969979 Nothing -> replicate numrows ColWidthDefault
970980 let toRow = Row nullAttr
971981 toHeaderRow l = [toRow l | not (null l)]
test/command/6791.mdnew file+32
@@ -0,0 +1,32 @@
1+```
2+% pandoc -f docbook -t native --quiet
3+<informaltable frame="all" rowsep="1" colsep="1">
4+<?dbfo table-width="50%"?>
5+<tgroup cols="2">
6+<colspec colname="col_1" colwidth="6.25*"/>
7+<colspec colname="col_2" colwidth="6.25*"/>
8+<tbody>
9+<row>
10+<entry align="center" valign="top"><simpara>2</simpara></entry>
11+<entry align="center" valign="top"><simpara>1</simpara></entry>
12+</row>
13+</tbody>
14+</tgroup>
15+</informaltable>
16+^D
17+[Table ("",[],[]) (Caption Nothing
18+ [])
19+ [(AlignDefault,ColWidth 0.25)
20+ ,(AlignDefault,ColWidth 0.25)]
21+ (TableHead ("",[],[])
22+ [])
23+ [(TableBody ("",[],[]) (RowHeadColumns 0)
24+ []
25+ [Row ("",[],[])
26+ [Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1)
27+ [Para [Str "2"]]
28+ ,Cell ("",[],[]) AlignCenter (RowSpan 1) (ColSpan 1)
29+ [Para [Str "1"]]]])]
30+ (TableFoot ("",[],[])
31+ [])]
32+```