@@ -39,6 +39,9 @@ module Text.Pandoc.Readers.Org.ParserState
39 , TodoState (..)
39 , TodoState (..)
40 , activeTodoMarkers
40 , activeTodoMarkers
41 , registerTodoSequence
41 , registerTodoSequence
@@ -78,6 +81,8 @@ type OrgNoteTable = [OrgNoteRecord]
78-- | Map of functions for link transformations. The map key is refers to the
81-- | Map of functions for link transformations. The map key is refers to the
79-- link-type, the corresponding function transforms the given link string.
82-- link-type, the corresponding function transforms the given link string.
80type OrgLinkFormatters = M.Map String (String -> String)
83type OrgLinkFormatters = M.Map String (String -> String)
84+-- | Macro expander function
85+type MacroExpander = [String] -> String
82-- | The states in which a todo item can be
87-- | The states in which a todo item can be
83data TodoState = Todo | Done
88data TodoState = Todo | Done
@@ -105,6 +110,8 @@ data OrgParserState = OrgParserState
105 , orgStateLastPreCharPos :: Maybe SourcePos
110 , orgStateLastPreCharPos :: Maybe SourcePos
106 , orgStateLastStrPos :: Maybe SourcePos
111 , orgStateLastStrPos :: Maybe SourcePos
107 , orgStateLinkFormatters :: OrgLinkFormatters
112 , orgStateLinkFormatters :: OrgLinkFormatters
113+ , orgStateMacros :: M.Map String MacroExpander
114+ , orgStateMacroDepth :: Int
108 , orgStateMeta :: F Meta
115 , orgStateMeta :: F Meta
109 , orgStateNotes' :: OrgNoteTable
116 , orgStateNotes' :: OrgNoteTable
110 , orgStateOptions :: ReaderOptions
117 , orgStateOptions :: ReaderOptions
@@ -156,6 +163,8 @@ defaultOrgParserState = OrgParserState
156 , orgStateLastPreCharPos = Nothing
163 , orgStateLastPreCharPos = Nothing
157 , orgStateLastStrPos = Nothing
164 , orgStateLastStrPos = Nothing
158 , orgStateLinkFormatters = M.empty
165 , orgStateLinkFormatters = M.empty
166+ , orgStateMacros = M.empty
167+ , orgStateMacroDepth = 0
159 , orgStateMeta = return nullMeta
168 , orgStateMeta = return nullMeta
160 , orgStateNotes' = []
169 , orgStateNotes' = []
161 , orgStateOptions = def
170 , orgStateOptions = def
@@ -185,6 +194,15 @@ activeTodoSequences st =
185activeTodoMarkers :: OrgParserState -> TodoSequence
194activeTodoMarkers :: OrgParserState -> TodoSequence
186activeTodoMarkers = concat . activeTodoSequences
195activeTodoMarkers = concat . activeTodoSequences
197+lookupMacro :: String -> OrgParserState -> Maybe MacroExpander
198+lookupMacro macroName = M.lookup macroName . orgStateMacros
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 }
190-- Export Settings
208-- Export Settings