From 8c55023d188bb159b5309d817ba6d834a69e7b9c Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Mon, 28 Jan 2013 10:50:58 -0800 Subject: Fixed latex macro parsing. Now latex macro definitions are preserved when output is latex, and applied when it is another format, as originally intended. Partially addresses #730. \providecommand is still not supported. For this we need changes to texmath. --- src/Text/Pandoc/Parsing.hs | 8 ++++---- src/Text/Pandoc/Readers/LaTeX.hs | 2 +- src/Text/Pandoc/Readers/Markdown.hs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs index 0ab4c0694..002bc18de 100644 --- a/src/Text/Pandoc/Parsing.hs +++ b/src/Text/Pandoc/Parsing.hs @@ -148,7 +148,7 @@ where import Text.Pandoc.Definition import Text.Pandoc.Options -import Text.Pandoc.Builder (Blocks, Inlines) +import Text.Pandoc.Builder (Blocks, Inlines, rawBlock) import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn) import Text.Parsec import Text.Parsec.Pos (newPos) @@ -1007,7 +1007,7 @@ nested p = do -- -- | Parse a \newcommand or \renewcommand macro definition. -macro :: Parser [Char] ParserState Block +macro :: Parser [Char] ParserState Blocks macro = do apply <- getOption readerApplyMacros inp <- getInput @@ -1018,8 +1018,8 @@ macro = do then do updateState $ \st -> st { stateMacros = ms ++ stateMacros st } - return Null - else return $ RawBlock "latex" def' + return mempty + else return $ rawBlock "latex" def' -- | Apply current macros to string. applyMacros' :: String -> Parser [Char] ParserState String diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 05a71bd2b..253e50ef2 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -204,7 +204,7 @@ block :: LP Blocks block = (mempty <$ comment) <|> (mempty <$ ((spaceChar <|> newline) *> spaces)) <|> environment - <|> mempty <$ macro + <|> macro <|> blockCommand <|> paragraph <|> grouped block diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 9113cb75e..b67a30853 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -355,7 +355,7 @@ parseBlocks = mconcat <$> manyTill block eof block :: MarkdownParser (F Blocks) block = choice [ codeBlockFenced - , guardEnabled Ext_latex_macros *> (mempty <$ macro) + , guardEnabled Ext_latex_macros *> (macro >>= return . return) , header , lhsCodeBlock , rawTeXBlock -- cgit v1.2.3