git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: improved heuristic for raw block/inline.

An unknown command at the beginning of the line that could be either block or inline is treated as block if we have a sequence of block commands followed by a newline or a `\startXXX` command (which might start a raw ConTeXt environment).

commitf9309bc46e4bf24b3a1d53663297851394a89a3f authorJohn MacFarlane <jgm@berkeley.edu> dateFri 21 Jul 2017, 23:27 (9 years ago) parent2ae75e2
1 file changed+18−2
src/Text/Pandoc/Readers/LaTeX.hs+18−2
src/Text/Pandoc/Readers/LaTeX.hs+18−2
@@ -1639,9 +1639,25 @@ blockCommand = try $ do
16391639 star <- option "" ("*" <$ symbol '*' <* optional sp)
16401640 let name' = name <> star
16411641 let names = ordNub [name', name]
1642− let raw = do
1643− guard $ isBlockCommand name || not (isInlineCommand name)
1642+ let rawDefiniteBlock = do
1643+ guard $ isBlockCommand name
16441644 rawBlock "latex" <$> getRawCommand (txt <> star)
1645+ -- heuristic: if it could be either block or inline, we
1646+ -- treat it if block if we have a sequence of block
1647+ -- commands followed by a newline. But we stop if we
1648+ -- hit a \startXXX, since this might start a raw ConTeXt
1649+ -- environment (this is important because this parser is
1650+ -- used by the Markdown reader).
1651+ let startCommand = try $ do
1652+ Tok _ (CtrlSeq n) _ <- anyControlSeq
1653+ guard $ "start" `T.isPrefixOf` n
1654+ let rawMaybeBlock = try $ do
1655+ guard $ not $ isInlineCommand name
1656+ curr <- rawBlock "latex" <$> getRawCommand (txt <> star)
1657+ rest <- many $ notFollowedBy startCommand *> blockCommand
1658+ lookAhead $ blankline <|> startCommand
1659+ return $ curr <> mconcat rest
1660+ let raw = rawDefiniteBlock <|> rawMaybeBlock
16451661 lookupListDefault raw names blockCommands
16461662
16471663closing :: PandocMonad m => LP m Blocks