@@ -198,7 +198,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
198 let lang = case lookup "lang" (writerVariables opts') of
198 let lang = case lookup "lang" (writerVariables opts') of
199 Just x -> x
199 Just x -> x
200 Nothing -> localeLang
200 Nothing -> localeLang
201+ let userNodes = onlyElems $ parseXML $ writerEpubMetadata opts'
202+ let mbIdent = findElement (QName "identifier" Nothing (Just "dc"))
203+ $ unode "dummy" ! [] $ userNodes
204+ uuid <- case mbIdent of
205+ Just id' -> return $ trim $ strContent id'
201− uuid <- getRandomUUID
206+ Nothing -> fmap show getRandomUUID
202 let chapterNode ent = unode "item" !
207 let chapterNode ent = unode "item" !
203 ([("id", takeBaseName $ eRelativePath ent),
208 ([("id", takeBaseName $ eRelativePath ent),
204 ("href", eRelativePath ent),
209 ("href", eRelativePath ent),
@@ -230,7 +235,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
230 EPUB3 -> "3.0")
235 EPUB3 -> "3.0")
231 ,("xmlns","http://www.idpf.org/2007/opf")
236 ,("xmlns","http://www.idpf.org/2007/opf")
232 ,("unique-identifier","BookId")] $
237 ,("unique-identifier","BookId")] $
233− [ metadataElement version (writerEpubMetadata opts')
238+ [ metadataElement version userNodes
234 uuid lang plainTitle plainAuthors plainDate currentTime mbCoverImage
239 uuid lang plainTitle plainAuthors plainDate currentTime mbCoverImage
235 , unode "manifest" $
240 , unode "manifest" $
236 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
241 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
@@ -311,7 +316,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
311 ,("xmlns","http://www.daisy.org/z3986/2005/ncx/")] $
316 ,("xmlns","http://www.daisy.org/z3986/2005/ncx/")] $
312 [ unode "head" $
317 [ unode "head" $
313 [ unode "meta" ! [("name","dtb:uid")
318 [ unode "meta" ! [("name","dtb:uid")
314− ,("content", show uuid)] $ ()
319+ ,("content", uuid)] $ ()
315 , unode "meta" ! [("name","dtb:depth")
320 , unode "meta" ! [("name","dtb:depth")
316 ,("content", "1")] $ ()
321 ,("content", "1")] $ ()
317 , unode "meta" ! [("name","dtb:totalPageCount")
322 , unode "meta" ! [("name","dtb:totalPageCount")
@@ -384,13 +389,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
384 (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries ++ fontEntries))
389 (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries ++ fontEntries))
385 return $ fromArchive archive
390 return $ fromArchive archive
387−metadataElement :: EPUBVersion -> String -> UUID -> String -> String -> [String]
392+metadataElement :: EPUBVersion -> [Element] -> String -> String -> String -> [String]
388 -> String -> UTCTime -> Maybe a -> Element
393 -> String -> UTCTime -> Maybe a -> Element
389−metadataElement version metadataXML uuid lang title authors date currentTime mbCoverImage =
394+metadataElement version userNodes uuid lang title authors date currentTime mbCoverImage =
390− let userNodes = parseXML metadataXML
391− elt = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
395+ let elt = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
392 ,("xmlns:opf","http://www.idpf.org/2007/opf")] $
396 ,("xmlns:opf","http://www.idpf.org/2007/opf")] $
393− filter isMetadataElement $ onlyElems userNodes
397+ filter isMetadataElement userNodes
394 dublinElements = ["contributor","coverage","creator","date",
398 dublinElements = ["contributor","coverage","creator","date",
395 "description","format","identifier","language","publisher",
399 "description","format","identifier","language","publisher",
396 "relation","rights","source","subject","title","type"]
400 "relation","rights","source","subject","title","type"]
@@ -401,7 +405,7 @@ metadataElement version metadataXML uuid lang title authors date currentTime mbC
401 contains e n = not (null (findElements (QName n Nothing (Just "dc")) e))
405 contains e n = not (null (findElements (QName n Nothing (Just "dc")) e))
402 newNodes = [ unode "dc:title" title | not (elt `contains` "title") ] ++
406 newNodes = [ unode "dc:title" title | not (elt `contains` "title") ] ++
403 [ unode "dc:language" lang | not (elt `contains` "language") ] ++
407 [ unode "dc:language" lang | not (elt `contains` "language") ] ++
404− [ unode "dc:identifier" ! [("id","BookId")] $ show uuid |
408+ [ unode "dc:identifier" ! [("id","BookId")] $ uuid |
405 not (elt `contains` "identifier") ] ++
409 not (elt `contains` "identifier") ] ++
406 [ unode "dc:creator" ! [("opf:role","aut") | version == EPUB2]
410 [ unode "dc:creator" ! [("opf:role","aut") | version == EPUB2]
407 $ a | a <- authors, not (elt `contains` "creator") ] ++
411 $ a | a <- authors, not (elt `contains` "creator") ] ++