Skip to content

Commit

Permalink
Parse id, class, and tabstyle on tables in DocBook Reader
Browse files Browse the repository at this point in the history
Add parsing of id (xml:id), class, and tabstyle XML attributes
for table and informaltable in the DocBook reader.
The tabstyle value is put in the 'custom-style' attribute.

fixes #10181
  • Loading branch information
lifeunleaded authored and jgm committed Sep 14, 2024
1 parent fe9459c commit 1cdf267
Show file tree
Hide file tree
Showing 4 changed files with 196 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Text/Pandoc/Readers/DocBook.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,11 @@ parseBlock (Elem e) =
items' <- mapM getBlocks items
return (mconcat $ intersperse (str "; ") terms', items')
parseTable = do
let elId = attrValue "id" e
let attrs = case attrValue "tabstyle" e of
"" -> []
x -> [("custom-style", x)]
let classes = T.words $ attrValue "class" e
let isCaption x = named "title" x || named "caption" x
capt <- case filterChild isCaption e of
Just t -> getInlines t
Expand Down Expand Up @@ -1075,7 +1080,8 @@ parseBlock (Elem e) =
Nothing -> replicate numrows ColWidthDefault
let toRow = Row nullAttr
toHeaderRow l = [toRow l | not (null l)]
return $ table (simpleCaption $ plain capt)
return $ tableWith (elId,classes,attrs)
(simpleCaption $ plain capt)
(zip aligns widths)
(TableHead nullAttr $ toHeaderRow headrows)
[TableBody nullAttr 0 [] $ map toRow bodyrows]
Expand Down
69 changes: 69 additions & 0 deletions test/docbook-reader.docbook
Original file line number Diff line number Diff line change
Expand Up @@ -1405,6 +1405,75 @@ or here: &lt;http://example.com/&gt;
</tbody>
</tgroup>
</table>
<para>
Table with attributes
</para>
<table xml:id="mytableid1" class="mytableclass1 mytableclass2" tabstyle="mytabstyle1">
<title>
Attribute table caption
</title>
<tgroup>
<thead>
<th>
<para>
header cell 1
</para>
</th>
<th>
<para>
header cell 2
</para>
</th>
</thead>
<tbody>
<tr>
<td>
<para>
body cell 1
</para>
</td>
<td>
<para>
body cell 2
</para>
</td>
</tr>
</tbody>
</tgroup>
</table>
<para>
Table with attributes, without caption
</para>
<informaltable xml:id="mytableid2" class="mytableclass3 mytableclass4" tabstyle="mytabstyle2">
<tgroup>
<thead>
<th>
<para>
header cell 1
</para>
</th>
<th>
<para>
header cell 2
</para>
</th>
</thead>
<tbody>
<tr>
<td>
<para>
body cell 1
</para>
</td>
<td>
<para>
body cell 2
</para>
</td>
</tr>
</tbody>
</tgroup>
</informaltable>
<para>
Multiline table without caption:
</para>
Expand Down
119 changes: 119 additions & 0 deletions test/docbook-reader.native
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,125 @@ Pandoc
]
]
(TableFoot ( "" , [] , [] ) [])
, Para
[ Str "Table"
, Space
, Str "with"
, Space
, Str "attributes"
]
, Table
( "mytableid1"
, [ "mytableclass1" , "mytableclass2" ]
, [ ( "custom-style" , "mytabstyle1" ) ]
)
(Caption
Nothing
[ Plain
[ Str "Attribute"
, Space
, Str "table"
, Space
, Str "caption"
]
])
[ ( AlignDefault , ColWidthDefault )
, ( AlignDefault , ColWidthDefault )
]
(TableHead ( "" , [] , [] ) [])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para
[ Str "body"
, Space
, Str "cell"
, Space
, Str "1"
]
]
, Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para
[ Str "body"
, Space
, Str "cell"
, Space
, Str "2"
]
]
]
]
]
(TableFoot ( "" , [] , [] ) [])
, Para
[ Str "Table"
, Space
, Str "with"
, Space
, Str "attributes,"
, Space
, Str "without"
, Space
, Str "caption"
]
, Table
( "mytableid2"
, [ "mytableclass3" , "mytableclass4" ]
, [ ( "custom-style" , "mytabstyle2" ) ]
)
(Caption Nothing [])
[ ( AlignDefault , ColWidthDefault )
, ( AlignDefault , ColWidthDefault )
]
(TableHead ( "" , [] , [] ) [])
[ TableBody
( "" , [] , [] )
(RowHeadColumns 0)
[]
[ Row
( "" , [] , [] )
[ Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para
[ Str "body"
, Space
, Str "cell"
, Space
, Str "1"
]
]
, Cell
( "" , [] , [] )
AlignDefault
(RowSpan 1)
(ColSpan 1)
[ Para
[ Str "body"
, Space
, Str "cell"
, Space
, Str "2"
]
]
]
]
]
(TableFoot ( "" , [] , [] ) [])
, Para
[ Str "Multiline"
, Space
Expand Down
2 changes: 1 addition & 1 deletion test/docbook-xref.native
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ Pandoc
]
]
, Table
( "" , [] , [] )
( "table01" , [] , [] )
(Caption
Nothing
[ Plain
Expand Down

0 comments on commit 1cdf267

Please sign in to comment.