From f895ee2e48d06c498e8f309ce6be0aeb72352baa Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Sun, 4 Jul 2010 17:45:15 -0700 Subject: Process user-supplied EPUB metadata. Read a sequence of elements from the file. Ignore anything that's not valid Dublin Core. If title, language, uuid not supplied, supply them. --- src/Text/Pandoc/Writers/EPUB.hs | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'src/Text') diff --git a/src/Text/Pandoc/Writers/EPUB.hs b/src/Text/Pandoc/Writers/EPUB.hs index 05d9afa7c..4f8bd36f3 100644 --- a/src/Text/Pandoc/Writers/EPUB.hs +++ b/src/Text/Pandoc/Writers/EPUB.hs @@ -119,13 +119,8 @@ writeEPUB sourceDir stylesheet opts doc = do unode "package" ! [("version","2.0") ,("xmlns","http://www.idpf.org/2007/opf") ,("unique-identifier","BookId")] $ - [ unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/") - ,("xmlns:opf","http://www.idpf.org/2007/opf")] $ - [ unode "dc:title" plainTitle - , unode "dc:language" lang - , unode "dc:identifier" ! [("id","BookId")] $ show uuid - ] ++ - map (unode "dc:creator" ! [("opf:role","aut")]) plainAuthors + [ metadataElement (writerEPUBMetadata opts') + uuid lang plainTitle plainAuthors , unode "manifest" $ [ unode "item" ! [("id","ncx"), ("href","toc.ncx") ,("media-type","application/x-dtbncx+xml")] $ () @@ -172,6 +167,25 @@ writeEPUB sourceDir stylesheet opts doc = do contentsEntry : tocEntry : (picEntries ++ chapterEntries) ) return $ fromArchive archive +metadataElement :: String -> UUID -> String -> String -> [String] -> Element +metadataElement metadataXML uuid lang title authors = + let userNodes = parseXML metadataXML + elt = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/") + ,("xmlns:opf","http://www.idpf.org/2007/opf")] $ + filter isDublinCoreElement $ onlyElems userNodes + dublinElements = ["contributor","coverage","creator","date", + "description","format","identifier","language","publisher", + "relation","rights","source","subject","title","type"] + isDublinCoreElement e = qPrefix (elName e) == Just "dc" && + qName (elName e) `elem` dublinElements + contains e n = not (null (findElements (QName n Nothing (Just "dc")) e)) + newNodes = [ unode "dc:title" title | not (elt `contains` "title") ] ++ + [ unode "dc:language" lang | not (elt `contains` "language") ] ++ + [ unode "dc:identifier" ! [("id","BookId")] $ show uuid | + not (elt `contains` "identifier") ] ++ + [ unode "dc:creator" ! [("opf:role","aut")] $ a | a <- authors ] + in elt{ elContent = elContent elt ++ map Elem newNodes } + transformInline :: HTMLMathMethod -> FilePath -> IORef [Entry] -- cgit v1.2.3