Skip to content

Commit

Permalink
Docx reader: ensure that table captions are counted.
Browse files Browse the repository at this point in the history
Normally these occur outside the table element itself, but they
should still be parsed as captions in this case.

Closes #9518.
  • Loading branch information
jgm committed Feb 28, 2024
1 parent 6f87c9e commit 87b07c6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
5 changes: 2 additions & 3 deletions src/Text/Pandoc/Readers/Docx/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -793,9 +793,8 @@ elemToBodyPart ns element
case pHeading parstyle of
Nothing | Just (numId, lvl) <- pNumInfo parstyle -> do
mkListItem parstyle numId lvl parparts
_ -> if isTable
then return $ TblCaption parstyle parparts
else return $ Paragraph parstyle parparts
_ -> return $ (if hasCaptionStyle then TblCaption else Paragraph)
parstyle parparts

elemToBodyPart ns element
| isElem ns "w" "tbl" element = do
Expand Down
5 changes: 2 additions & 3 deletions test/docx/table_captions_no_field.native
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[Para [Str "See",Space,Str "Table",Space,Str "5.1."]
,Para [Str "Table",Space,Str "5.1"]
,Table ("",[],[]) (Caption Nothing
[])
,Table ("",[],[])
(Caption Nothing [ Para [ Str "Table" , Space , Str "5.1" ] ])
[(AlignDefault,ColWidth 0.7605739372523825)
,(AlignDefault,ColWidth 0.11971303137380876)
,(AlignDefault,ColWidth 0.11971303137380876)]
Expand Down
8 changes: 4 additions & 4 deletions test/docx/table_captions_with_field.native
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Para [Str "See",Space,Str "Table",Space,Str "1."]
,Para [Str "Table",Space,Str "1"]
,Table ("",[],[]) (Caption Nothing [])
,Table ("",[],[])
(Caption Nothing [ Para [ Str "Table" , Space , Str "1" ] ])
[(AlignDefault,ColWidth 0.7605739372523825)
,(AlignDefault,ColWidth 0.11971303137380876)
,(AlignDefault,ColWidth 0.11971303137380876)]
Expand Down Expand Up @@ -31,7 +31,8 @@
(TableFoot ("",[],[])
[])
,Header 2 ("section", [], []) []
,Table ("",[],[]) (Caption Nothing [])
,Table ("",[],[])
(Caption Nothing [Para [Str "Table", Space, Str "2"]])
[(AlignDefault,ColWidth 0.3332963620230701)
,(AlignDefault,ColWidth 0.3332963620230701)
,(AlignDefault,ColWidth 0.3334072759538598)]
Expand All @@ -48,5 +49,4 @@
[])]
(TableFoot ("",[],[])
[])
,Para [Str "Table",Space,Str "2"]
,Para [Str "See",Space,Str "Table",Space,Str "2."]]

0 comments on commit 87b07c6

Please sign in to comment.