aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEzwal <[email protected]>2025-11-30 13:49:58 +0100
committerGitHub <[email protected]>2025-11-30 13:49:58 +0100
commitfc07b06851eac5c70557de101d8044494e9a2bc4 (patch)
tree8146fbecf7dbcefc0a707c0102e53cbdafbecafd /src
parent094061d946f12961b9af0b400befbb798f980be7 (diff)
Docx reader: Handle REF link instruction (#11296)
This PR aims to handle a common run field instruction (fieldInstr) from docx format : REF, specifically those with the "link" switch \h. In word software, you can create REF field instruction with the Cross-reference button. You can create cross-reference to many things such as Equation, Table, Title...
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Docx.hs1
-rw-r--r--src/Text/Pandoc/Readers/Docx/Fields.hs12
2 files changed, 13 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Readers/Docx.hs b/src/Text/Pandoc/Readers/Docx.hs
index 2852defc7..8f70fe7a6 100644
--- a/src/Text/Pandoc/Readers/Docx.hs
+++ b/src/Text/Pandoc/Readers/Docx.hs
@@ -482,6 +482,7 @@ parPartToInlines' (Field info children) =
++ [("bold","") | entryBold ie]
++ [("italic","") | entryItalic ie])) mempty
PagerefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children
+ CrossrefField fieldAnchor True -> parPartToInlines' $ InternalHyperLink fieldAnchor children
EndNoteCite t -> do
formattedCite <- smushInlines <$> mapM parPartToInlines' children
opts <- asks docxOptions
diff --git a/src/Text/Pandoc/Readers/Docx/Fields.hs b/src/Text/Pandoc/Readers/Docx/Fields.hs
index 8b1837394..89bba8814 100644
--- a/src/Text/Pandoc/Readers/Docx/Fields.hs
+++ b/src/Text/Pandoc/Readers/Docx/Fields.hs
@@ -35,6 +35,7 @@ data IndexEntry = IndexEntry
data FieldInfo = HyperlinkField URL
-- The boolean indicates whether the field is a hyperlink.
| PagerefField Anchor Bool
+ | CrossrefField Anchor Bool
| IndexrefField IndexEntry
| CslCitation T.Text
| CslBibliography
@@ -57,6 +58,8 @@ fieldInfo = do
<|>
indexref
<|>
+ crossref
+ <|>
addIn
<|>
return UnknownField
@@ -141,6 +144,15 @@ pageref = do
let isLink = any ((== 'h') . fst) switches
return $ PagerefField farg isLink
+crossref :: Parser FieldInfo
+crossref = do
+ string "REF"
+ spaces
+ farg <- fieldArgument
+ switches <- many fieldSwitch
+ let isLink = any ((== 'h') . fst) switches
+ return $ CrossrefField farg isLink
+
-- second element of tuple is optional "see".
indexref :: Parser FieldInfo
indexref = do