aboutsummaryrefslogtreecommitdiff
path: root/src/Text/Pandoc
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2014-07-20 17:00:38 +0100
committerMatthew Pickering <matthewtpickering@gmail.com>2014-07-27 00:12:56 +0100
commit43304d6bd6ab920a150b0e27d24239151015ddb2 (patch)
tree0b20281aa0f2aed7c5588c456dc5dc60c4fd2ea1 /src/Text/Pandoc
parentab3589ff0bc2c66c711e7a92021edd79bf52046a (diff)
downloadpandoc-43304d6bd6ab920a150b0e27d24239151015ddb2.tar.gz
Txt2Tags Reader: Added recognition of macros
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r--src/Text/Pandoc/Readers/Txt2Tags.hs22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/Text/Pandoc/Readers/Txt2Tags.hs b/src/Text/Pandoc/Readers/Txt2Tags.hs
index 145c13fb8..363ab086c 100644
--- a/src/Text/Pandoc/Readers/Txt2Tags.hs
+++ b/src/Text/Pandoc/Readers/Txt2Tags.hs
@@ -12,7 +12,7 @@ import Text.Pandoc.Builder ( Inlines, Blocks, (<>)
import Text.Pandoc.Definition
import Text.Pandoc.Options
import Text.Pandoc.Shared (escapeURI,compactify', compactify'DL)
-import Text.Pandoc.Parsing hiding (space, spaces, uri)
+import Text.Pandoc.Parsing hiding (space, spaces, uri, macro)
import Control.Applicative ((<$>), (<$), (<*>), (<*), (*>))
import Data.Char (toLower)
import Data.List (transpose, intersperse, intercalate)
@@ -23,12 +23,14 @@ import Control.Monad (void, guard, when)
import Data.Default
import Control.Monad.Reader (Reader, runReader, asks)
-type T2T = Parser String ParserState
-
+import Data.Time.LocalTime (getZonedTime)
+import System.Directory (getModificationTime)
+import Data.Time.Format (formatTime)
+import System.Locale (defaultTimeLocale)
+import System.IO.Error (catchIOError)
type T2T = ParserT String ParserState (Reader T2TMeta)
-
-- | An object for the T2T macros meta information
-- the contents of each field is simply substituted verbatim into the file
data T2TMeta = T2TMeta {
@@ -295,6 +297,7 @@ blockMarkupLine p f s = try (f <$> (string s *> space *> p))
comment :: Monoid a => T2T a
comment = try $ do
atStart
+ notFollowedBy macro
mempty <$ (char '%' *> anyLine)
-- Inline
@@ -306,6 +309,7 @@ inline :: T2T Inlines
inline = do
choice
[ endline
+ , macro
, commentLine
, whitespace
, url
@@ -405,6 +409,16 @@ imageLink = try $ do
l <- manyTill (noneOf "\n\r ") (char ']')
return (B.link l "" body)
+macro :: T2T Inlines
+macro = try $ do
+ name <- string "%%" *> oneOfStringsCI (map fst commands)
+ optional (try $ enclosed (char '(') (char ')') anyChar)
+ lookAhead (spaceChar <|> oneOf specialChars <|> newline)
+ maybe (return mempty) (\f -> B.str <$> asks f) (lookup name commands)
+ where
+ commands = [ ("date", date), ("mtime", mtime)
+ , ("infile", infile), ("outfile", outfile)]
+
-- raw URLs in text are automatically linked
url :: T2T Inlines
url = try $ do