diff options
-rw-r--r-- | pandoc.cabal | 4 | ||||
-rw-r--r-- | src/Text/Pandoc/Shared.hs | 17 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/Docx.hs | 7 | ||||
-rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 4 | ||||
-rw-r--r-- | tests/s5.basic.html | 2 | ||||
-rw-r--r-- | tests/s5.fancy.html | 2 | ||||
-rw-r--r-- | tests/s5.inserts.html | 2 | ||||
-rw-r--r-- | tests/writer.html | 2 |
8 files changed, 31 insertions, 9 deletions
diff --git a/pandoc.cabal b/pandoc.cabal index b12594a95..f25fceae2 100644 --- a/pandoc.cabal +++ b/pandoc.cabal @@ -203,6 +203,8 @@ Library zip-archive >= 0.1.1.7 && < 0.2, utf8-string >= 0.3 && < 0.4, old-time >= 1 && < 1.2, + old-locale >= 1 && < 1.1, + time >= 1.2 && < 1.5, HTTP >= 4000.0.5 && < 4000.3, texmath >= 0.6 && < 0.7, xml >= 1.3.5 && < 1.4, @@ -294,6 +296,8 @@ Executable pandoc zip-archive >= 0.1.1.7 && < 0.2, utf8-string >= 0.3 && < 0.4, old-time >= 1 && < 1.2, + old-locale >= 1 && < 1.1, + time >= 1.2 && < 1.5, HTTP >= 4000.0.5 && < 4000.3, texmath >= 0.6 && < 0.7, xml >= 1.3.5 && < 1.4, diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs index 952218176..7e63c2161 100644 --- a/src/Text/Pandoc/Shared.hs +++ b/src/Text/Pandoc/Shared.hs @@ -46,6 +46,8 @@ module Text.Pandoc.Shared ( toRomanNumeral, escapeURI, tabFilter, + -- * Date/time + normalizeDate, -- * Pandoc block and inline list processing orderedListMarkers, normalizeSpaces, @@ -81,9 +83,12 @@ import System.Directory import System.FilePath ( (</>) ) import Data.Generics (Typeable, Data) import qualified Control.Monad.State as S +import Control.Monad (msum) import Paths_pandoc (getDataFileName) import Text.Pandoc.Highlighting (Style, pygments) import Text.Pandoc.Pretty (charWidth) +import System.Locale (defaultTimeLocale) +import Data.Time -- -- List processing @@ -218,6 +223,18 @@ tabFilter tabStop = in go tabStop -- +-- Date/time +-- + +-- | Parse a date and convert (if possible) to "YYYY-MM-DD" format. +normalizeDate :: String -> Maybe String +normalizeDate s = fmap (formatTime defaultTimeLocale "%F") + (msum $ map (\fs -> parsetimeWith fs s) formats :: Maybe Day) + where parsetimeWith = parseTime defaultTimeLocale + formats = ["%x","%m/%d/%Y", "%D","%F", "%d %b %Y", + "%d %B %Y", "%b. %d, %Y", "%B %d, %Y"] + +-- -- Pandoc block and inline list processing -- diff --git a/src/Text/Pandoc/Writers/Docx.hs b/src/Text/Pandoc/Writers/Docx.hs index fb05c18a3..218a6e42a 100644 --- a/src/Text/Pandoc/Writers/Docx.hs +++ b/src/Text/Pandoc/Writers/Docx.hs @@ -97,7 +97,7 @@ writeDocx :: Maybe FilePath -- ^ Path specified by --reference-docx -> WriterOptions -- ^ Writer options -> Pandoc -- ^ Document to convert -> IO B.ByteString -writeDocx mbRefDocx opts doc@(Pandoc (Meta tit auths _) _) = do +writeDocx mbRefDocx opts doc@(Pandoc (Meta tit auths date) _) = do let datadir = writerUserDataDir opts refArchive <- liftM toArchive $ case mbRefDocx of @@ -161,7 +161,8 @@ writeDocx mbRefDocx opts doc@(Pandoc (Meta tit auths _) _) = do ,("xmlns:dcmitype","http://purl.org/dc/dcmitype/") ,("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance")] $ mknode "dc:title" [] (stringify tit) - : mknode "dcterms:created" [("xsi:type","dcterms:W3CDTF")] () -- put doc date here + : mknode "dcterms:created" [("xsi:type","dcterms:W3CDTF")] + (maybe "" id $ normalizeDate $ stringify date) : mknode "dcterms:modified" [("xsi:type","dcterms:W3CDTF")] () -- put current time here : map (mknode "dc:creator" [] . stringify) auths let docPropsEntry = toEntry docPropsPath epochtime $ fromString $ showTopElement' docProps @@ -653,4 +654,4 @@ inlineToOpenXML opts (Image alt (src, tit)) = do else do liftIO $ UTF8.hPutStrLn stderr $ "Could not find image `" ++ src ++ "', skipping..." - inlinesToOpenXML opts alt
\ No newline at end of file + inlinesToOpenXML opts alt diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 5530247a2..8ca7aca62 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -182,13 +182,13 @@ inTemplate :: TemplateTarget a inTemplate opts tit auths authsMeta date toc body' newvars = let title' = renderHtml tit date' = renderHtml date + dateMeta = maybe [] (\x -> [("date-meta",x)]) $ normalizeDate date' variables = writerVariables opts ++ newvars - context = variables ++ + context = variables ++ dateMeta ++ [ ("body", dropWhile (=='\n') $ renderHtml body') , ("pagetitle", stripTags title') , ("title", title') , ("date", date') - , ("date-meta", stripTags date') , ("idprefix", writerIdentifierPrefix opts) , ("slidy-url", "http://www.w3.org/Talks/Tools/Slidy2") , ("s5-url", "s5/default") ] ++ diff --git a/tests/s5.basic.html b/tests/s5.basic.html index cc1259690..6194c27a9 100644 --- a/tests/s5.basic.html +++ b/tests/s5.basic.html @@ -6,7 +6,7 @@ <meta name="generator" content="pandoc" /> <meta name="author" content="Sam Smith" /> <meta name="author" content="Jen Jones" /> - <meta name="date" content="July 15, 2006" /> + <meta name="date" content="2006-07-15" /> <title>My S5 Document</title> <!-- configuration parameters --> <meta name="defaultView" content="slideshow" /> diff --git a/tests/s5.fancy.html b/tests/s5.fancy.html index 8d40d9344..119306143 100644 --- a/tests/s5.fancy.html +++ b/tests/s5.fancy.html @@ -6,7 +6,7 @@ <meta name="generator" content="pandoc" /> <meta name="author" content="Sam Smith" /> <meta name="author" content="Jen Jones" /> - <meta name="date" content="July 15, 2006" /> + <meta name="date" content="2006-07-15" /> <title>My S5 Document</title> <!-- configuration parameters --> <meta name="defaultView" content="slideshow" /> diff --git a/tests/s5.inserts.html b/tests/s5.inserts.html index 275684e68..524c5b0ce 100644 --- a/tests/s5.inserts.html +++ b/tests/s5.inserts.html @@ -6,7 +6,7 @@ <meta name="generator" content="pandoc" /> <meta name="author" content="Sam Smith" /> <meta name="author" content="Jen Jones" /> - <meta name="date" content="July 15, 2006" /> + <meta name="date" content="2006-07-15" /> <title>My S5 Document</title> <link rel="stylesheet" href="main.css" type="text/css" /> STUFF INSERTED diff --git a/tests/writer.html b/tests/writer.html index 55d07b012..c9ef6f1f1 100644 --- a/tests/writer.html +++ b/tests/writer.html @@ -6,7 +6,7 @@ <meta name="generator" content="pandoc" /> <meta name="author" content="John MacFarlane" /> <meta name="author" content="Anonymous" /> - <meta name="date" content="July 17, 2006" /> + <meta name="date" content="2006-07-17" /> <title>Pandoc Test Suite</title> </head> <body> |