aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTuong Nguyen Manh <[email protected]>2026-01-02 17:43:15 +0100
committerGitHub <[email protected]>2026-01-02 11:43:15 -0500
commit2327e302cb08a34a7326a89c35a12362e016d4b2 (patch)
treecf814cb44367d005e82fe6f02d60fb9400d1d2f2 /src
parent8f8ea44d02b6a3ca0c3e80eaf78e926889f29c9b (diff)
RTF reader: Improve hyperlink parsing more (#11370)
Both the field instruction and its result may be ungrouped. Closes #10942.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/RTF.hs25
1 files changed, 16 insertions, 9 deletions
diff --git a/src/Text/Pandoc/Readers/RTF.hs b/src/Text/Pandoc/Readers/RTF.hs
index fde444854..cb6b99e2b 100644
--- a/src/Text/Pandoc/Readers/RTF.hs
+++ b/src/Text/Pandoc/Readers/RTF.hs
@@ -790,22 +790,29 @@ handleField bs ts = do
let isFieldMod (Tok _ (ControlWord w _)) =
w `elem` ["flddirty", "fldedit", "fldlock", "fldpriv"]
isFieldMod _ = False
+
+ let instructionTokens (Tok _ (Grouped toks)) = Just toks
+ instructionTokens unformattedTok@(Tok _ (UnformattedText _)) = Just [unformattedTok]
+ instructionTokens _ = Nothing
case dropWhile isFieldMod ts of
[Tok _ (Grouped
(Tok _ (ControlSymbol '*')
:Tok _ (ControlWord "fldinst" Nothing)
- :Tok _ (Grouped instrtoks)
+ :instrtoks
:_)),
Tok _ (Grouped
(Tok _ (ControlWord "fldrslt" Nothing)
- :Tok _ (Grouped resulttoks) : _))] -> do
- case getHyperlink instrtoks of
- Just linkdest -> do
- modifyGroup $ \g -> g{ gHyperlink = Just linkdest }
- result <- foldM processTok bs resulttoks
- modifyGroup $ \g -> g{ gHyperlink = Nothing }
- return result
- Nothing -> foldM processTok bs resulttoks
+ :resulttoks))] -> do
+ case instructionTokens instrtoks of
+ Nothing -> pure bs
+ Just instrtoks' ->
+ case getHyperlink instrtoks' of
+ Just linkdest -> do
+ modifyGroup $ \g -> g{ gHyperlink = Just linkdest }
+ result <- foldM processTok bs resulttoks
+ modifyGroup $ \g -> g{ gHyperlink = Nothing }
+ return result
+ Nothing -> foldM processTok bs resulttoks
_ -> pure bs
getHyperlink :: [Tok] -> Maybe Text