mirror of
https://github.com/jgm/pandoc.git
synced 2026-09-21 05:43:39 +08:00
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:
committed by
John MacFarlane
parent
1443e7dc8f
commit
a5576317c9
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user