Skip to content

Commit b185560

Browse files
committed
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.
1 parent aaef517 commit b185560

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

src/Text/Pandoc/Readers/RTF.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -395,15 +395,15 @@ isUnderline _ = False
395395
processTok :: PandocMonad m => Blocks -> Tok -> RTFParser m Blocks
396396
processTok bs (Tok pos tok') = do
397397
setPosition pos
398-
-- ignore \* at beginning of group:
399-
let tok'' = case tok' of
400-
Grouped (Tok _ (ControlSymbol '*') : toks) -> Grouped toks
401-
_ -> tok'
402-
case tok'' of
398+
case tok' of
403399
HexVal{} -> return ()
404400
UnformattedText{} -> return ()
405401
_ -> updateState $ \s -> s{ sEatChars = 0 }
406-
case tok'' of
402+
case tok' of
403+
Grouped (Tok _ (ControlSymbol '*') : toks) ->
404+
bs <$ (do oldTextContent <- sTextContent <$> getState
405+
processTok mempty (Tok pos (Grouped toks))
406+
updateState $ \st -> st{ sTextContent = oldTextContent })
407407
Grouped (Tok _ (ControlWord "fonttbl" _) : toks) -> inGroup $ do
408408
updateState $ \s -> s{ sFontTable = processFontTable toks }
409409
pure bs
@@ -440,10 +440,10 @@ processTok bs (Tok pos tok') = do
440440
-- TODO ideally we'd put the span around bkmkstart/end, but this
441441
-- is good for now:
442442
modifyGroup (\g -> g{ gAnchor = Just $ T.strip t })
443-
addText ""
443+
pure bs
444+
Grouped (Tok _ (ControlWord "bkmkend" _) : _) -> do
444445
modifyGroup (\g -> g{ gAnchor = Nothing })
445446
pure bs
446-
Grouped (Tok _ (ControlWord "bkmkend" _) : _) -> pure bs -- TODO
447447
Grouped (Tok _ (ControlWord f _) : _) | isHeaderFooter f -> pure bs
448448
Grouped (Tok _ (ControlWord "footnote" _) : toks) -> do
449449
noteBs <- inGroup $ processDestinationToks toks

test/rtf/bookmark.native

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
Pandoc (Meta {unMeta = fromList []})
2-
[Para [Span ("bookmark_1",[],[]) [],Str "Bookmark_1"]
2+
[Para [Span ("bookmark_1",[],[]) [Str "Bookmark_1"]]
33
,Para [Link ("",[],[]) [Str "click",Space,Str "me"] ("#bookmark_1","")]]

0 commit comments

Comments
 (0)