diff options
| -rw-r--r-- | src/Text/Pandoc/Readers/DocBook.hs | 24 | ||||
| -rw-r--r-- | test/docbook-reader.docbook | 33 | ||||
| -rw-r--r-- | test/docbook-reader.native | 122 |
3 files changed, 171 insertions, 8 deletions
diff --git a/src/Text/Pandoc/Readers/DocBook.hs b/src/Text/Pandoc/Readers/DocBook.hs index a73e46ce0..0e6e083bd 100644 --- a/src/Text/Pandoc/Readers/DocBook.hs +++ b/src/Text/Pandoc/Readers/DocBook.hs @@ -53,6 +53,7 @@ import Text.TeXMath (readMathML, writeTeX) import qualified Data.Map as M import Text.Pandoc.XML.Light import Text.Pandoc.Walk (query) +import Text.Read (readMaybe) {- @@ -1055,9 +1056,8 @@ parseBlock (Elem e) = cs -> mapMaybe (findAttr (unqual "colname" )) cs let isRow x = named "row" x || named "tr" x headrows <- case filterChild (named "thead") e' of - Just h -> case filterChild isRow h of - Just x -> parseRow colnames x - Nothing -> return [] + Just h -> mapM (parseRow colnames) + $ filterChildren isRow h Nothing -> return [] bodyrows <- case filterChild (named "tbody") e' of Just b -> mapM (parseRow colnames) @@ -1071,7 +1071,7 @@ parseBlock (Elem e) = || x == '.') w if n > 0 then Just n else Nothing let numrows = maybe 0 maximum $ nonEmpty - $ map length bodyrows + $ map length (bodyrows ++ headrows) let aligns = case colspecs of [] -> replicate numrows AlignDefault cs -> map toAlignment cs @@ -1093,11 +1093,10 @@ parseBlock (Elem e) = in ColWidth . scale <$> ws' Nothing -> replicate numrows ColWidthDefault let toRow = Row nullAttr - toHeaderRow l = [toRow l | not (null l)] return $ tableWith (elId,classes,attrs) (simpleCaption $ plain capt) (zip aligns widths) - (TableHead nullAttr $ toHeaderRow headrows) + (TableHead nullAttr $ map toRow headrows) [TableBody nullAttr 0 [] $ map toRow bodyrows] (TableFoot nullAttr []) sect n = sectWith(attrValue "id" e) [] [] n @@ -1171,7 +1170,7 @@ parseMixed container conts = do parseRow :: PandocMonad m => [Text] -> Element -> DB m [Cell] parseRow cn = do - let isEntry x = named "entry" x || named "td" x || named "th" x + let isEntry x = named "entry" x || named "td" x || named "th" x mapM (parseEntry cn) . filterChildren isEntry parseEntry :: PandocMonad m => [Text] -> Element -> DB m Cell @@ -1188,9 +1187,18 @@ parseEntry cn el = do case (mStrt, mEnd) of (Just start, Just end) -> colDistance start end _ -> 1 + let rowDistance mr = do + case readMaybe $ T.unpack mr :: Maybe Int of + Just moreRow -> RowSpan $ moreRow + 1 + _ -> 1 + let toRowSpan en = do + case findAttr (unqual "morerows") en of + Just moreRow -> rowDistance moreRow + _ -> 1 let colSpan = toColSpan el + let rowSpan = toRowSpan el let align = toAlignment el - (fmap (cell align 1 colSpan) . parseMixed plain . elContent) el + (fmap (cell align rowSpan colSpan) . parseMixed plain . elContent) el getInlines :: PandocMonad m => Element -> DB m Inlines getInlines e' = trimInlines . mconcat <$> diff --git a/test/docbook-reader.docbook b/test/docbook-reader.docbook index 5c3b52787..6b7e7e1bc 100644 --- a/test/docbook-reader.docbook +++ b/test/docbook-reader.docbook @@ -1627,6 +1627,39 @@ or here: <http://example.com/> </tbody> </tgroup> </informaltable> + <para> + Multiline table with cells spanning multiple columns and rows without caption. + </para> + <informaltable> + <tgroup cols="3"> + <colspec align="left" colname="c1" /> + <colspec align="left" colname="c2" /> + <colspec align="left" colname="c3" /> + <colspec align="left" colname="c4" /> + <thead> + <tr> + <th namest="c1" nameend="c3">Columns</th> + </tr> + <tr> + <th>A</th> + <th>B</th> + <th>C</th> + </tr> + </thead> + <tbody> + <tr> + <td namest="c1" nameend="c2">A1 + B1</td> + <td morerows="1">C1 + C2</td> + </tr> + <tr> + <td namest="c1" nameend="c2" morerows="1">A2 + B2 + A3 + B3</td> + </tr> + <tr> + <td>C3</td> + </tr> + </tbody> + </tgroup> + </informaltable> <procedure><title>An Example Procedure</title> <step> <para> diff --git a/test/docbook-reader.native b/test/docbook-reader.native index 13f5c49fc..6d0f72811 100644 --- a/test/docbook-reader.native +++ b/test/docbook-reader.native @@ -3046,6 +3046,128 @@ Pandoc ] ] (TableFoot ( "" , [] , [] ) []) + , Para + [ Str "Multiline" + , Space + , Str "table" + , Space + , Str "with" + , Space + , Str "cells" + , Space + , Str "spanning" + , Space + , Str "multiple" + , Space + , Str "columns" + , Space + , Str "and" + , Space + , Str "rows" + , Space + , Str "without" + , Space + , Str "caption." + ] + , Table + ( "" , [] , [] ) + (Caption Nothing []) + [ ( AlignLeft , ColWidthDefault ) + , ( AlignLeft , ColWidthDefault ) + , ( AlignLeft , ColWidthDefault ) + ] + (TableHead + ( "" , [] , [] ) + [ Row + ( "" , [] , [] ) + [ Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 3) + [ Plain [ Str "Columns" ] ] + ] + , Row + ( "" , [] , [] ) + [ Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 1) + [ Plain [ Str "A" ] ] + , Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 1) + [ Plain [ Str "B" ] ] + , Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 1) + [ Plain [ Str "C" ] ] + ] + ]) + [ TableBody + ( "" , [] , [] ) + (RowHeadColumns 0) + [] + [ Row + ( "" , [] , [] ) + [ Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 2) + [ Plain + [ Str "A1" , Space , Str "+" , Space , Str "B1" ] + ] + , Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 2) + (ColSpan 1) + [ Plain + [ Str "C1" , Space , Str "+" , Space , Str "C2" ] + ] + ] + , Row + ( "" , [] , [] ) + [ Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 2) + (ColSpan 2) + [ Plain + [ Str "A2" + , Space + , Str "+" + , Space + , Str "B2" + , Space + , Str "+" + , Space + , Str "A3" + , Space + , Str "+" + , Space + , Str "B3" + ] + ] + ] + , Row + ( "" , [] , [] ) + [ Cell + ( "" , [] , [] ) + AlignDefault + (RowSpan 1) + (ColSpan 1) + [ Plain [ Str "C3" ] ] + ] + ] + ] + (TableFoot ( "" , [] , [] ) []) , OrderedList ( 1 , DefaultStyle , DefaultDelim ) [ [ Para [ Str "A" , Space , Str "Step" ] ] |
