git.iko.soy/typeable/pandoc
on master help sign in
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.

commitf895ee2e48d06c498e8f309ce6be0aeb72352baa authorJohn MacFarlane <jgm@berkeley.edu> dateSun 4 Jul 2010, 17:45 (16 years ago) parente3dcf8e
1 file changed+21−7
src/Text/Pandoc/Writers/EPUB.hs+21−7
src/Text/Pandoc/Writers/EPUB.hs+21−7
@@ -119,13 +119,8 @@ writeEPUB sourceDir stylesheet opts doc = do
119119 unode "package" ! [("version","2.0")
120120 ,("xmlns","http://www.idpf.org/2007/opf")
121121 ,("unique-identifier","BookId")] $
122− [ unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
123− ,("xmlns:opf","http://www.idpf.org/2007/opf")] $
124− [ unode "dc:title" plainTitle
125− , unode "dc:language" lang
126− , unode "dc:identifier" ! [("id","BookId")] $ show uuid
127− ] ++
128− map (unode "dc:creator" ! [("opf:role","aut")]) plainAuthors
122+ [ metadataElement (writerEPUBMetadata opts')
123+ uuid lang plainTitle plainAuthors
129124 , unode "manifest" $
130125 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
131126 ,("media-type","application/x-dtbncx+xml")] $ ()
@@ -172,6 +167,25 @@ writeEPUB sourceDir stylesheet opts doc = do
172167 contentsEntry : tocEntry : (picEntries ++ chapterEntries) )
173168 return $ fromArchive archive
174169
170+metadataElement :: String -> UUID -> String -> String -> [String] -> Element
171+metadataElement metadataXML uuid lang title authors =
172+ let userNodes = parseXML metadataXML
173+ elt = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
174+ ,("xmlns:opf","http://www.idpf.org/2007/opf")] $
175+ filter isDublinCoreElement $ onlyElems userNodes
176+ dublinElements = ["contributor","coverage","creator","date",
177+ "description","format","identifier","language","publisher",
178+ "relation","rights","source","subject","title","type"]
179+ isDublinCoreElement e = qPrefix (elName e) == Just "dc" &&
180+ qName (elName e) `elem` dublinElements
181+ contains e n = not (null (findElements (QName n Nothing (Just "dc")) e))
182+ newNodes = [ unode "dc:title" title | not (elt `contains` "title") ] ++
183+ [ unode "dc:language" lang | not (elt `contains` "language") ] ++
184+ [ unode "dc:identifier" ! [("id","BookId")] $ show uuid |
185+ not (elt `contains` "identifier") ] ++
186+ [ unode "dc:creator" ! [("opf:role","aut")] $ a | a <- authors ]
187+ in elt{ elContent = elContent elt ++ map Elem newNodes }
188+
175189transformInline :: HTMLMathMethod
176190 -> FilePath
177191 -> IORef [Entry]