aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-07-21 23:27:54 +0200
committerJohn MacFarlane <jgm@berkeley.edu>2017-07-21 23:27:54 +0200
commitf9309bc46e4bf24b3a1d53663297851394a89a3f (patch)
tree975a59f0b56ac9c5e90559e0f8d79c710323cc7b /src/Text
parent2ae75e23dd740e968245269d8765d5b5af3a5f35 (diff)
downloadpandoc-f9309bc46e4bf24b3a1d53663297851394a89a3f.tar.gz
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).
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 58a48c655..1215187b7 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -1639,9 +1639,25 @@ blockCommand = try $ do
star <- option "" ("*" <$ symbol '*' <* optional sp)
let name' = name <> star
let names = ordNub [name', name]
- let raw = do
- guard $ isBlockCommand name || not (isInlineCommand name)
+ let rawDefiniteBlock = do
+ guard $ isBlockCommand name
rawBlock "latex" <$> getRawCommand (txt <> star)
+ -- 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
+ curr <- rawBlock "latex" <$> getRawCommand (txt <> star)
+ 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