LaTeX reader: improve withRaw so it can handle cases where...

the token string is modified by a parser (e.g. accent when
it only takes part of a Word token).

Closes #5686.  Still not ideal, because we get the whole
`\t0BAR` and not just `\t0` as a raw latex inline command.
But I'm willing to let this be an edge case, since you
can easily work around this by inserting a space, braces,
or raw attribute.  The important thing is that we no longer
drop the rest of the document after a raw latex inline
command that gobbles only part of a Word token!
This commit is contained in:
John MacFarlane 2019-08-14 14:28:34 -07:00
parent e85178c32a
commit 79a3449eeb
2 changed files with 12 additions and 2 deletions

View file

@ -677,6 +677,7 @@ withRaw :: PandocMonad m => LP m a -> LP m (a, [Tok])
withRaw parser = do withRaw parser = do
inp <- getInput inp <- getInput
result <- parser result <- parser
nxt <- option (Tok (initialPos "source") Word "") (lookAhead anyTok) nxtpos <- option Nothing ((\(Tok pos' _ _) -> Just pos') <$> lookAhead anyTok)
let raw = takeWhile (/= nxt) inp let raw = takeWhile (\(Tok pos _ _) -> maybe True
(\p -> sourceName p /= sourceName pos || pos < p) nxtpos) inp
return (result, raw) return (result, raw)

9
test/command/5686.md Normal file
View file

@ -0,0 +1,9 @@
```
% pandoc -t native
FOO\t0BAR
This part does not make it to the html output.
^D
[Para [Str "FOO",RawInline (Format "tex") "\\t0BAR"]
,Para [Str "This",Space,Str "part",Space,Str "does",Space,Str "not",Space,Str "make",Space,Str "it",Space,Str "to",Space,Str "the",Space,Str "html",Space,Str "output."]]
```