aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-07-04 17:45:15 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2010-07-05 00:06:27 -0700
commitf895ee2e48d06c498e8f309ce6be0aeb72352baa (patch)
tree2c6a69a1ee9a25efaf2b91952e0b957584cd5776 /src/Text
parente3dcf8e3bf438371961b6cc18e98f1637c30c97f (diff)
downloadpandoc-f895ee2e48d06c498e8f309ce6be0aeb72352baa.tar.gz
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.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Writers/EPUB.hs28
1 files changed, 21 insertions, 7 deletions
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]