Docx reader: check recursively for caption styles.

The docx reader uses caption styles to identify figures and captioned
tables. It now checks for known caption styles in the full styles
hierarchy of a paragraph instead of just checking the style directly.
This allows to recognize caption styles that are built on top of the
basic *caption* style, as is sometimes the case in sophisticated styles.
This commit is contained in:
Albert Krewinkel
2025-11-12 23:12:01 +01:00
committed by John MacFarlane
parent 1443e7dc8f
commit a5576317c9
+7 -1
View File
@@ -1361,14 +1361,20 @@ findBlip el = do
-- return svg if present:
filterElementName (\(QName tag _ _) -> tag == "svgBlip") el `mplus` pure blip
-- | Checks if any style in the style hierarchy is a caption style.
hasCaptionStyle :: ParagraphStyle -> Bool
hasCaptionStyle parstyle = any (isCaptionStyleName . pStyleName) (pStyle parstyle)
hasCaptionStyle =
any (isCaptionStyleName . pStyleName) . concatMap nestedStyles . pStyle
where -- note that these are case insensitive:
isCaptionStyleName "caption" = True
isCaptionStyleName "table caption" = True
isCaptionStyleName "image caption" = True
isCaptionStyleName _ = False
-- Gets all the style names in the style hierarchy
nestedStyles :: ParStyle -> [ParStyle]
nestedStyles ps = ps : maybe [] nestedStyles (psParentStyle ps)
stripCaptionLabel :: [Element] -> [Element]
stripCaptionLabel els =
if any isNumberElt els