LaTeX reader: Simplify decision about unknown commands...

...at the start of a paragraph, taking them to be inline
only if they're followed by regular text.  This is simpler
than our previous test (checking to see that none of
the commands on the line are inline), but it is less fragile.
(The old test broke with some changes, soon to be committed,
that change tokenization of control sequences, including trailing
newlines.)
This commit is contained in:
John MacFarlane committed 2022-01-14 22:49:41 -08:00
1 parent 4214218256
commit 5b7d9ef5c2
1 file changed
+6 -21
+6 -21
View File
@@ -771,33 +771,18 @@ blockCommand :: PandocMonad m => LP m Blocks
blockCommand = try $ do
Tok _ (CtrlSeq name) txt <- anyControlSeq
guard $ name /= "begin" && name /= "end" && name /= "and"
guard $ isBlockCommand name || not (isInlineCommand name)
unless (isBlockCommand name) $
-- if it could be either inline or block, take it to be inline
-- if regular text follows:
notFollowedBy $ try $ optional whitespace >> satisfyTok isWordTok
star <- option "" ("*" <$ symbol '*' <* sp)
let name' = name <> star
let names = ordNub [name', name]
let rawDefiniteBlock = do
guard $ isBlockCommand name
let raw = do
rawcontents <- getRawCommand name (txt <> star)
(guardEnabled Ext_raw_tex >> return (rawBlock "latex" rawcontents))
<|> ignore rawcontents
-- heuristic: if it could be either block or inline, we
-- treat it if block if we have a sequence of block
-- commands followed by a newline. But we stop if we
-- hit a \startXXX, since this might start a raw ConTeXt
-- environment (this is important because this parser is
-- used by the Markdown reader).
let startCommand = try $ do
Tok _ (CtrlSeq n) _ <- anyControlSeq
guard $ "start" `T.isPrefixOf` n
let rawMaybeBlock = try $ do
guard $ not $ isInlineCommand name
rawcontents <- getRawCommand name (txt <> star)
curr <- (guardEnabled Ext_raw_tex >>
return (rawBlock "latex" rawcontents))
<|> ignore rawcontents
rest <- many $ notFollowedBy startCommand *> blockCommand
lookAhead $ blankline <|> startCommand
return $ curr <> mconcat rest
let raw = rawDefiniteBlock <|> rawMaybeBlock
lookupListDefault raw names blockCommands
closing :: PandocMonad m => LP m Blocks