@@ -198,7 +198,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
198198 let lang = case lookup "lang" (writerVariables opts') of
199199 Just x -> x
200200 Nothing -> localeLang
201− uuid <- getRandomUUID
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'
206+ Nothing -> fmap show getRandomUUID
202207 let chapterNode ent = unode "item" !
203208 ([("id", takeBaseName $ eRelativePath ent),
204209 ("href", eRelativePath ent),
@@ -230,7 +235,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
230235 EPUB3 -> "3.0")
231236 ,("xmlns","http://www.idpf.org/2007/opf")
232237 ,("unique-identifier","BookId")] $
233− [ metadataElement version (writerEpubMetadata opts')
238+ [ metadataElement version userNodes
234239 uuid lang plainTitle plainAuthors plainDate currentTime mbCoverImage
235240 , unode "manifest" $
236241 [ unode "item" ! [("id","ncx"), ("href","toc.ncx")
@@ -311,7 +316,7 @@ writeEPUB opts doc@(Pandoc meta _) = do
311316 ,("xmlns","http://www.daisy.org/z3986/2005/ncx/")] $
312317 [ unode "head" $
313318 [ unode "meta" ! [("name","dtb:uid")
314− ,("content", show uuid)] $ ()
319+ ,("content", uuid)] $ ()
315320 , unode "meta" ! [("name","dtb:depth")
316321 ,("content", "1")] $ ()
317322 , unode "meta" ! [("name","dtb:totalPageCount")
@@ -384,13 +389,12 @@ writeEPUB opts doc@(Pandoc meta _) = do
384389 (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries ++ fontEntries))
385390 return $ fromArchive archive
386391
387−metadataElement :: EPUBVersion -> String -> UUID -> String -> String -> [String]
392+metadataElement :: EPUBVersion -> [Element] -> String -> String -> String -> [String]
388393 -> String -> UTCTime -> Maybe a -> Element
389−metadataElement version metadataXML 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/")
394+metadataElement version userNodes uuid lang title authors date currentTime mbCoverImage =
395+ let elt = unode "metadata" ! [("xmlns:dc","http://purl.org/dc/elements/1.1/")
392396 ,("xmlns:opf","http://www.idpf.org/2007/opf")] $
393− filter isMetadataElement $ onlyElems userNodes
397+ filter isMetadataElement userNodes
394398 dublinElements = ["contributor","coverage","creator","date",
395399 "description","format","identifier","language","publisher",
396400 "relation","rights","source","subject","title","type"]
@@ -401,7 +405,7 @@ metadataElement version metadataXML uuid lang title authors date currentTime mbC
401405 contains e n = not (null (findElements (QName n Nothing (Just "dc")) e))
402406 newNodes = [ unode "dc:title" title | not (elt `contains` "title") ] ++
403407 [ unode "dc:language" lang | not (elt `contains` "language") ] ++
404− [ unode "dc:identifier" ! [("id","BookId")] $ show uuid |
408+ [ unode "dc:identifier" ! [("id","BookId")] $ uuid |
405409 not (elt `contains` "identifier") ] ++
406410 [ unode "dc:creator" ! [("opf:role","aut") | version == EPUB2]
407411 $ a | a <- authors, not (elt `contains` "creator") ] ++