From fc07b06851eac5c70557de101d8044494e9a2bc4 Mon Sep 17 00:00:00 2001 From: Ezwal <15009992+Ezwal@users.noreply.github.com> Date: Sun, 30 Nov 2025 13:49:58 +0100 Subject: 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... --- src/Text/Pandoc/Readers/Docx.hs | 1 + src/Text/Pandoc/Readers/Docx/Fields.hs | 12 ++++++++++++ 2 files changed, 13 insertions(+) (limited to 'src') 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 -- cgit v1.2.3