git.iko.soy/typeable/pandoc
on master help sign in
Moved 'macro' and 'applyMacros'' from markdown reader to Parsing.
commitfcbe1e95ebe170aadc6eadd6797ddf7fbb286ef2 authorJohn MacFarlane <jgm@berkeley.edu> dateTue 4 Jan 2011, 19:12 (16 years ago) parent3e61333
2 files changed+27−26
src/Text/Pandoc/Parsing.hs+27−2 src/Text/Pandoc/Readers/Markdown.hs−24
src/Text/Pandoc/Parsing.hs+27−2
@@ -68,7 +68,9 @@ module Text.Pandoc.Parsing ( (>>~),
6868 toKey,
6969 fromKey,
7070 lookupKeySrc,
71− smartPunctuation )
71+ smartPunctuation,
72+ macro,
73+ applyMacros' )
7274where
7375
7476import Text.Pandoc.Definition
@@ -82,7 +84,7 @@ import Network.URI ( parseURI, URI (..), isAllowedInURI )
8284import Control.Monad ( join, liftM, guard )
8385import Text.Pandoc.Shared
8486import qualified Data.Map as M
85−import Text.TeXMath.Macros (Macro)
87+import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
8688
8789-- | Like >>, but returns the operation on the left.
8890-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
@@ -781,3 +783,26 @@ emDash = do
781783 try (charOrRef "—") <|> (oneOfStrings ["---", "--"] >> return '—')
782784 return EmDash
783785
786+--
787+-- Macros
788+--
789+
790+-- | Parse a \newcommand or \renewcommand macro definition.
791+macro :: GenParser Char ParserState Block
792+macro = getState >>= guard . stateApplyMacros >>
793+ pMacroDefinition >>= addMacro >> blanklines >> return Null
794+
795+-- | Add a macro to the list of macros in state.
796+addMacro :: Macro -> GenParser Char ParserState ()
797+addMacro m = do
798+ updateState $ \st -> st{ stateMacros = m : stateMacros st }
799+
800+-- | Apply current macros to string.
801+applyMacros' :: String -> GenParser Char ParserState String
802+applyMacros' target = do
803+ apply <- liftM stateApplyMacros getState
804+ if apply
805+ then do macros <- liftM stateMacros getState
806+ return $ applyMacros macros target
807+ else return target
808+
src/Text/Pandoc/Readers/Markdown.hs−24
@@ -44,7 +44,6 @@ import Text.Pandoc.Readers.HTML ( htmlTag, htmlInBalanced, isInlineTag, isBlockT
4444import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
4545import Text.ParserCombinators.Parsec
4646import Control.Monad (when, liftM, guard)
47−import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
4847import Text.HTML.TagSoup
4948import Text.HTML.TagSoup.Match (tagOpen)
5049
@@ -871,29 +870,6 @@ table = multilineTable False <|> simpleTable True <|>
871870 simpleTable False <|> multilineTable True <|>
872871 gridTable False <|> gridTable True <?> "table"
873872
874−--
875−-- Macros
876−--
877−
878−-- | Parse a \newcommand or \renewcommand macro definition.
879−macro :: GenParser Char ParserState Block
880−macro = getState >>= guard . stateApplyMacros >>
881− pMacroDefinition >>= addMacro >> blanklines >> return Null
882−
883−-- | Add a macro to the list of macros in state.
884−addMacro :: Macro -> GenParser Char ParserState ()
885−addMacro m = do
886− updateState $ \st -> st{ stateMacros = m : stateMacros st }
887−
888−-- | Apply current macros to string.
889−applyMacros' :: String -> GenParser Char ParserState String
890−applyMacros' target = do
891− apply <- liftM stateApplyMacros getState
892− if apply
893− then do macros <- liftM stateMacros getState
894− return $ applyMacros macros target
895− else return target
896−
897873--
898874-- inline
899875--