git.iko.soy/typeable/pandoc
on master help sign in
Moved 'macro' and 'applyMacros'' from markdown reader to Parsing.
fcbe1e9John MacFarlane
src/Text/Pandoc/Parsing.hs+27−2
@@ -68,7 +68,9 @@ module Text.Pandoc.Parsing ( (>>~),
68 toKey,
68 toKey,
69 fromKey,
69 fromKey,
70 lookupKeySrc,
70 lookupKeySrc,
71− smartPunctuation )
71+ smartPunctuation,
72+ macro,
73+ applyMacros' )
72where
74where
73
75
74import Text.Pandoc.Definition
76import Text.Pandoc.Definition
@@ -82,7 +84,7 @@ import Network.URI ( parseURI, URI (..), isAllowedInURI )
82import Control.Monad ( join, liftM, guard )
84import Control.Monad ( join, liftM, guard )
83import Text.Pandoc.Shared
85import Text.Pandoc.Shared
84import qualified Data.Map as M
86import qualified Data.Map as M
85−import Text.TeXMath.Macros (Macro)
87+import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
86
88
87-- | Like >>, but returns the operation on the left.
89-- | Like >>, but returns the operation on the left.
88-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
90-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
@@ -781,3 +783,26 @@ emDash = do
781 try (charOrRef "—") <|> (oneOfStrings ["---", "--"] >> return '—')
783 try (charOrRef "—") <|> (oneOfStrings ["---", "--"] >> return '—')
782 return EmDash
784 return EmDash
783
785
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
44import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
44import Text.Pandoc.CharacterReferences ( decodeCharacterReferences )
45import Text.ParserCombinators.Parsec
45import Text.ParserCombinators.Parsec
46import Control.Monad (when, liftM, guard)
46import Control.Monad (when, liftM, guard)
47−import Text.TeXMath.Macros (applyMacros, Macro, pMacroDefinition)
48import Text.HTML.TagSoup
47import Text.HTML.TagSoup
49import Text.HTML.TagSoup.Match (tagOpen)
48import Text.HTML.TagSoup.Match (tagOpen)
50
49
@@ -871,29 +870,6 @@ table = multilineTable False <|> simpleTable True <|>
871 simpleTable False <|> multilineTable True <|>
870 simpleTable False <|> multilineTable True <|>
872 gridTable False <|> gridTable True <?> "table"
871 gridTable False <|> gridTable True <?> "table"
873
872
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−
897--
873--
898-- inline
874-- inline
899--
875--