inlineMacros
  :: Yesod master
  => String                                                -- ^ Magic string to introduce the macro
  -> Map String ([String] -> GHandler sub master [Inline]) -- ^ Lookup table from macro names to macro functions
  -> Pandoc
  -> GHandler sub master Pandoc
inlineMacros magic table p = processWithM (fmap concat . mapM inlineMacros') p where
  inlineMacros' (Code (splitAt (length magic) -> (magic',words -> ((flip Map.lookup table -> Just f):xs))))
    | magic == magic' = f xs
  inlineMacros' b = return [b]

-- | Convert a 'Hamlet' value to a 'Block'.
inlineMacros
  :: Yesod master
  => String                                                -- ^ Magic string to introduce the macro
  -> Map String ([String] -> GHandler sub master [Inline]) -- ^ Lookup table from macro names to macro functions
  -> Pandoc
  -> GHandler sub master Pandoc
inlineMacros magic table p = processWithM (fmap concat . mapM inlineMacros') p where
  inlineMacros' (Code (splitAt (length magic) -> (magic',words -> ((flip Map.lookup table -> Just f):xs))))
    | magic == magic' = f xs
  inlineMacros' b = return [b]

-- | Convert a 'Hamlet' value to a 'Block'.
inlineMacros magic table p = processWithM (fmap concat . mapM inlineMacros') p where
  inlineMacros' (Code (splitAt (length magic) -> (magic',words -> ((flip Map.lookup table -> Just f):xs))))
    | magic == magic' = f xs
  inlineMacros' b = return [b]

-- | Convert a 'Hamlet' value to a 'Block'.