@@ -39,6 +39,9 @@ module Text.Pandoc.Readers.Org.ParserState
3939 , TodoState (..)
4040 , activeTodoMarkers
4141 , registerTodoSequence
42+ , MacroExpander
43+ , lookupMacro
44+ , registerMacro
4245 , F
4346 , askF
4447 , asksF
@@ -78,6 +81,8 @@ type OrgNoteTable = [OrgNoteRecord]
7881-- | Map of functions for link transformations. The map key is refers to the
7982-- link-type, the corresponding function transforms the given link string.
8083type OrgLinkFormatters = M.Map String (String -> String)
84+-- | Macro expander function
85+type MacroExpander = [String] -> String
8186
8287-- | The states in which a todo item can be
8388data TodoState = Todo | Done
@@ -105,6 +110,8 @@ data OrgParserState = OrgParserState
105110 , orgStateLastPreCharPos :: Maybe SourcePos
106111 , orgStateLastStrPos :: Maybe SourcePos
107112 , orgStateLinkFormatters :: OrgLinkFormatters
113+ , orgStateMacros :: M.Map String MacroExpander
114+ , orgStateMacroDepth :: Int
108115 , orgStateMeta :: F Meta
109116 , orgStateNotes' :: OrgNoteTable
110117 , orgStateOptions :: ReaderOptions
@@ -156,6 +163,8 @@ defaultOrgParserState = OrgParserState
156163 , orgStateLastPreCharPos = Nothing
157164 , orgStateLastStrPos = Nothing
158165 , orgStateLinkFormatters = M.empty
166+ , orgStateMacros = M.empty
167+ , orgStateMacroDepth = 0
159168 , orgStateMeta = return nullMeta
160169 , orgStateNotes' = []
161170 , orgStateOptions = def
@@ -185,6 +194,15 @@ activeTodoSequences st =
185194activeTodoMarkers :: OrgParserState -> TodoSequence
186195activeTodoMarkers = concat . activeTodoSequences
187196
197+lookupMacro :: String -> OrgParserState -> Maybe MacroExpander
198+lookupMacro macroName = M.lookup macroName . orgStateMacros
199+
200+registerMacro :: (String, MacroExpander) -> OrgParserState -> OrgParserState
201+registerMacro (name, expander) st =
202+ let curMacros = orgStateMacros st
203+ in st{ orgStateMacros = M.insert name expander curMacros }
204+
205+
188206
189207--
190208-- Export Settings