From b185560a8ec1fd8a0b578de4d94ea72a3d3e2943 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sat, 4 Sep 2021 10:02:38 -0700 Subject: RTF reader: better handling of `\*` and bookmarks. We now ensure that groups starting with `\*` never cause text to be added to the document. In addition, bookmarks now create a span between the start and end of the bookmark, rather than an empty span. --- src/Text/Pandoc/Readers/RTF.hs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Text/Pandoc/Readers/RTF.hs b/src/Text/Pandoc/Readers/RTF.hs index 26a132758..4eeab1312 100644 --- a/src/Text/Pandoc/Readers/RTF.hs +++ b/src/Text/Pandoc/Readers/RTF.hs @@ -395,15 +395,15 @@ isUnderline _ = False processTok :: PandocMonad m => Blocks -> Tok -> RTFParser m Blocks processTok bs (Tok pos tok') = do setPosition pos - -- ignore \* at beginning of group: - let tok'' = case tok' of - Grouped (Tok _ (ControlSymbol '*') : toks) -> Grouped toks - _ -> tok' - case tok'' of + case tok' of HexVal{} -> return () UnformattedText{} -> return () _ -> updateState $ \s -> s{ sEatChars = 0 } - case tok'' of + case tok' of + Grouped (Tok _ (ControlSymbol '*') : toks) -> + bs <$ (do oldTextContent <- sTextContent <$> getState + processTok mempty (Tok pos (Grouped toks)) + updateState $ \st -> st{ sTextContent = oldTextContent }) Grouped (Tok _ (ControlWord "fonttbl" _) : toks) -> inGroup $ do updateState $ \s -> s{ sFontTable = processFontTable toks } pure bs @@ -440,10 +440,10 @@ processTok bs (Tok pos tok') = do -- TODO ideally we'd put the span around bkmkstart/end, but this -- is good for now: modifyGroup (\g -> g{ gAnchor = Just $ T.strip t }) - addText "" + pure bs + Grouped (Tok _ (ControlWord "bkmkend" _) : _) -> do modifyGroup (\g -> g{ gAnchor = Nothing }) pure bs - Grouped (Tok _ (ControlWord "bkmkend" _) : _) -> pure bs -- TODO Grouped (Tok _ (ControlWord f _) : _) | isHeaderFooter f -> pure bs Grouped (Tok _ (ControlWord "footnote" _) : toks) -> do noteBs <- inGroup $ processDestinationToks toks -- cgit v1.2.3