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.
This commit is contained in:
John MacFarlane 2013-01-28 10:50:58 -08:00
parent cc17c794a1
commit 8c55023d18
3 changed files with 6 additions and 6 deletions

View file

@ -148,7 +148,7 @@ where
import Text.Pandoc.Definition import Text.Pandoc.Definition
import Text.Pandoc.Options 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 qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
import Text.Parsec import Text.Parsec
import Text.Parsec.Pos (newPos) import Text.Parsec.Pos (newPos)
@ -1007,7 +1007,7 @@ nested p = do
-- --
-- | Parse a \newcommand or \renewcommand macro definition. -- | Parse a \newcommand or \renewcommand macro definition.
macro :: Parser [Char] ParserState Block macro :: Parser [Char] ParserState Blocks
macro = do macro = do
apply <- getOption readerApplyMacros apply <- getOption readerApplyMacros
inp <- getInput inp <- getInput
@ -1018,8 +1018,8 @@ macro = do
then do then do
updateState $ \st -> updateState $ \st ->
st { stateMacros = ms ++ stateMacros st } st { stateMacros = ms ++ stateMacros st }
return Null return mempty
else return $ RawBlock "latex" def' else return $ rawBlock "latex" def'
-- | Apply current macros to string. -- | Apply current macros to string.
applyMacros' :: String -> Parser [Char] ParserState String applyMacros' :: String -> Parser [Char] ParserState String

View file

@ -204,7 +204,7 @@ block :: LP Blocks
block = (mempty <$ comment) block = (mempty <$ comment)
<|> (mempty <$ ((spaceChar <|> newline) *> spaces)) <|> (mempty <$ ((spaceChar <|> newline) *> spaces))
<|> environment <|> environment
<|> mempty <$ macro <|> macro
<|> blockCommand <|> blockCommand
<|> paragraph <|> paragraph
<|> grouped block <|> grouped block

View file

@ -355,7 +355,7 @@ parseBlocks = mconcat <$> manyTill block eof
block :: MarkdownParser (F Blocks) block :: MarkdownParser (F Blocks)
block = choice [ codeBlockFenced block = choice [ codeBlockFenced
, guardEnabled Ext_latex_macros *> (mempty <$ macro) , guardEnabled Ext_latex_macros *> (macro >>= return . return)
, header , header
, lhsCodeBlock , lhsCodeBlock
, rawTeXBlock , rawTeXBlock