@@ -12,7 +12,7 @@ import Text.Pandoc.Builder ( Inlines, Blocks, (<>)
1212import Text.Pandoc.Definition
1313import Text.Pandoc.Options
1414import Text.Pandoc.Shared (escapeURI,compactify', compactify'DL)
15−import Text.Pandoc.Parsing hiding (space, spaces, uri)
15+import Text.Pandoc.Parsing hiding (space, spaces, uri, macro)
1616import Control.Applicative ((<$>), (<$), (<*>), (<*), (*>))
1717import Data.Char (toLower)
1818import Data.List (transpose, intersperse, intercalate)
@@ -23,12 +23,14 @@ import Control.Monad (void, guard, when)
2323import Data.Default
2424import Control.Monad.Reader (Reader, runReader, asks)
2525
26−type T2T = Parser String ParserState
27−
26+import Data.Time.LocalTime (getZonedTime)
27+import System.Directory (getModificationTime)
28+import Data.Time.Format (formatTime)
29+import System.Locale (defaultTimeLocale)
30+import System.IO.Error (catchIOError)
2831
2932type T2T = ParserT String ParserState (Reader T2TMeta)
3033
31−
3234-- | An object for the T2T macros meta information
3335-- the contents of each field is simply substituted verbatim into the file
3436data T2TMeta = T2TMeta {
@@ -295,6 +297,7 @@ blockMarkupLine p f s = try (f <$> (string s *> space *> p))
295297comment :: Monoid a => T2T a
296298comment = try $ do
297299 atStart
300+ notFollowedBy macro
298301 mempty <$ (char '%' *> anyLine)
299302
300303-- Inline
@@ -306,6 +309,7 @@ inline :: T2T Inlines
306309inline = do
307310 choice
308311 [ endline
312+ , macro
309313 , commentLine
310314 , whitespace
311315 , url
@@ -405,6 +409,16 @@ imageLink = try $ do
405409 l <- manyTill (noneOf "\n\r ") (char ']')
406410 return (B.link l "" body)
407411
412+macro :: T2T Inlines
413+macro = try $ do
414+ name <- string "%%" *> oneOfStringsCI (map fst commands)
415+ optional (try $ enclosed (char '(') (char ')') anyChar)
416+ lookAhead (spaceChar <|> oneOf specialChars <|> newline)
417+ maybe (return mempty) (\f -> B.str <$> asks f) (lookup name commands)
418+ where
419+ commands = [ ("date", date), ("mtime", mtime)
420+ , ("infile", infile), ("outfile", outfile)]
421+
408422-- raw URLs in text are automatically linked
409423url :: T2T Inlines
410424url = try $ do