@@ -195,10 +195,10 @@ untokenize = mconcat . map untoken
195195untoken :: Tok -> Text
196196untoken (Tok _ _ t) = t
197197
198−satisfyTok :: Monad m
199− => (Tok -> Bool)
200− -> ParserT [Tok] u m Tok
201−satisfyTok f = tokenPrim (T.unpack . untoken) updatePos matcher
198+-- we put withMacros in front of satisfyTok, so it works on everything
199+satisfyTok :: PandocMonad m => (Tok -> Bool) -> LP m Tok
200+satisfyTok f =
201+ doMacros *> tokenPrim (T.unpack . untoken) updatePos matcher
202202 where matcher t | f t = Just t
203203 | otherwise = Nothing
204204 updatePos :: SourcePos -> Tok -> [Tok] -> SourcePos
@@ -206,6 +206,22 @@ satisfyTok f = tokenPrim (T.unpack . untoken) updatePos matcher
206206 setSourceColumn (setSourceLine spos lin) col
207207 updatePos spos _ [] = spos
208208
209+-- TODO use something other than ParserState
210+doMacros :: PandocMonad m => LP m ()
211+doMacros = do
212+ inp <- getInput
213+ macros <- stateMacros <$> getState
214+ case inp of
215+ t@(Tok spos CtrlSeq txt) : ts
216+ | txt == "\\macro" -> do -- TODO actually check macros
217+ setInput $ map (setpos spos) (tokenize "Hi there") ++ ts
218+ -- TODO loop detection
219+ doMacros
220+ _ -> return ()
221+
222+setpos :: (Line, Column) -> Tok -> Tok
223+setpos spos (Tok _ tt txt) = Tok spos tt txt
224+
209225anyControlSeq :: PandocMonad m => LP m Tok
210226anyControlSeq = satisfyTok isCtrlSeq <* optional sp
211227 where isCtrlSeq (Tok _ CtrlSeq _) = True