From f3e8274d0425b3bf7a2459a2d88af585b491507f Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Sat, 21 Mar 2015 22:39:07 +0300 Subject: LaTeX Reader: check for block-level newcommand aliases in blockCommand --- src/Text/Pandoc/Readers/LaTeX.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index a517f9566..4d50ec4ed 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -239,17 +239,28 @@ block = (mempty <$ comment) blocks :: LP Blocks blocks = mconcat <$> many block +getRawCommand :: String -> LP String +getRawCommand name' = do + rawargs <- withRaw (skipopts *> option "" dimenarg *> many braced) + return $ '\\' : name' ++ snd rawargs + blockCommand :: LP Blocks blockCommand = try $ do name <- anyControlSeq guard $ name /= "begin" && name /= "end" star <- option "" (string "*" <* optional sp) let name' = name ++ star + let raw = do + rawcommand <- getRawCommand name' + transformed <- applyMacros' rawcommand + if transformed /= rawcommand + then parseFromString blocks transformed + else mzero case M.lookup name' blockCommands of Just p -> p Nothing -> case M.lookup name blockCommands of Just p -> p - Nothing -> mzero + Nothing -> raw inBrackets :: Inlines -> Inlines inBrackets x = (str "[") <> x <> (str "]") @@ -385,8 +396,7 @@ inlineCommand = try $ do star <- option "" (string "*") let name' = name ++ star let raw = do - rawargs <- withRaw (skipopts *> option "" dimenarg *> many braced) - let rawcommand = '\\' : name ++ star ++ snd rawargs + rawcommand <- getRawCommand name' transformed <- applyMacros' rawcommand if transformed /= rawcommand then parseFromString inlines transformed -- cgit v1.2.3 From 6a0d500f99aef5792b97d3ecd4f72af7cc473a72 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Mon, 30 Mar 2015 06:42:15 +0300 Subject: Latex Reader: Guard against para starting with inline macro --- src/Text/Pandoc/Readers/LaTeX.hs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 4d50ec4ed..31a4c7c5c 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -253,6 +253,7 @@ blockCommand = try $ do let raw = do rawcommand <- getRawCommand name' transformed <- applyMacros' rawcommand + notFollowedBy $ parseFromString inlines transformed if transformed /= rawcommand then parseFromString blocks transformed else mzero -- cgit v1.2.3 From f1eb1ab9cf6678cabbdb5b312bbd757ed32d8a76 Mon Sep 17 00:00:00 2001 From: Nikolay Yakimov Date: Tue, 31 Mar 2015 14:32:42 +0300 Subject: Latex Reader: Block commands code cleanup --- src/Text/Pandoc/Readers/LaTeX.hs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 31a4c7c5c..2886e2f29 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -253,10 +253,9 @@ blockCommand = try $ do let raw = do rawcommand <- getRawCommand name' transformed <- applyMacros' rawcommand + guard $ transformed /= rawcommand notFollowedBy $ parseFromString inlines transformed - if transformed /= rawcommand - then parseFromString blocks transformed - else mzero + parseFromString blocks transformed case M.lookup name' blockCommands of Just p -> p Nothing -> case M.lookup name blockCommands of -- cgit v1.2.3