@@ -56,7 +56,7 @@ import Text.XML.Light hiding (ppTopElement)
5656import Text.Pandoc.UUID
5757import Text.Pandoc.Writers.HTML
5858import Text.Pandoc.Writers.Markdown ( writePlain )
59−import Data.Char ( toLower )
59+import Data.Char ( toLower, isDigit )
6060import Network.URI ( unEscapeString )
6161import Text.Pandoc.MIME (getMimeType)
6262#if MIN_VERSION_base(4,6,0)
@@ -171,7 +171,8 @@ addMetadataFromXML e@(Element (QName name _ (Just "dc")) attrs _ _) md
171171 , titleFileAs = getAttr "file-as"
172172 , titleType = getAttr "type"
173173 } : epubTitle md }
174− | name == "date" = md{ epubDate = maybe "" id $ normalizeDate $ strContent e }
174+ | name == "date" = md{ epubDate = maybe "" id $ normalizeDate'
175+ $ strContent e }
175176 | name == "language" = md{ epubLanguage = strContent e }
176177 | name == "creator" = md{ epubCreator =
177178 Creator{ creatorText = strContent e
@@ -265,7 +266,7 @@ metadataFromMeta opts meta = EPUBMetadata{
265266 where identifiers = getIdentifier meta
266267 titles = getTitle meta
267268 date = maybe "" id $
268− (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate
269+ (metaValueToString <$> lookupMeta "date" meta) >>= normalizeDate'
269270 language = maybe "" metaValueToString $
270271 lookupMeta "language" meta `mplus` lookupMeta "lang" meta
271272 creators = getCreator "creator" meta
@@ -799,6 +800,16 @@ replaceRefs refTable = walk replaceOneRef
799800 Nothing -> x
800801 replaceOneRef x = x
801802
803+-- Variant of normalizeDate that allows partial dates: YYYY, YYYY-MM
804+normalizeDate' :: String -> Maybe String
805+normalizeDate' xs =
806+ let xs' = trim xs in
807+ case xs' of
808+ [y1,y2,y3,y4] | all isDigit [y1,y2,y3,y4] -> Just xs' -- YYYY
809+ [y1,y2,y3,y4,'-',m1,m2] | all isDigit [y1,y2,y3,y4,m1,m2] -- YYYY-MM
810+ -> Just xs'
811+ _ -> normalizeDate xs'
812+
802813toRelator :: String -> Maybe String
803814toRelator x
804815 | x `elem` relators = Just x