@@ -229,12 +229,10 @@ writeEPUB opts doc@(Pandoc meta _) = do
229229 ,("media-type","application/x-dtbncx+xml")] $ ()
230230 , unode "item" ! [("id","style"), ("href","stylesheet.css")
231231 ,("media-type","text/css")] $ ()
232− ] ++
233− [ unode "item" ! [("id","nav")
234− ,("href","nav.xhtml")
235− ,("properties","nav")
236− ,("media-type","application/xhtml+xml")] $ ()
237− | version == EPUB3
232+ , unode "item" ! ([("id","nav")
233+ ,("href","nav.xhtml")
234+ ,("media-type","application/xhtml+xml")] ++
235+ [("properties","nav") | epub3 ]) $ ()
238236 ] ++
239237 map chapterNode (cpgEntry ++ (tpEntry : chapterEntries)) ++
240238 map pictureNode (cpicEntry ++ picEntries) ++
@@ -244,7 +242,15 @@ writeEPUB opts doc@(Pandoc meta _) = do
244242 Nothing -> []
245243 Just _ -> [ unode "itemref" !
246244 [("idref", "cover"),("linear","no")] $ () ]
247− ++ map chapterRefNode (tpEntry : chapterEntries)
245+ ++ ((unode "itemref" ! [("idref", "title_page"),("linear","yes")] $ ()) :
246+ (unode "itemref" ! [("idref", "nav")
247+ ,("linear", if writerTableOfContents opts
248+ then "yes"
249+ else "no")] $ ()) :
250+ map chapterRefNode chapterEntries)
251+ , unode "guide" $
252+ unode "reference" !
253+ [("type","toc"),("title",plainTitle),("href","nav.xhtml")] $ ()
248254 ]
249255 let contentsEntry = mkEntry "content.opf" contentsData
250256
@@ -315,16 +321,19 @@ writeEPUB opts doc@(Pandoc meta _) = do
315321 $ (unode "span" tit))
316322 : case subs of
317323 [] -> []
318− (_:_) -> [unode "ol" subs]
324+ (_:_) -> [unode "ol" ! [("class","toc")] $ subs]
319325
326+ let navtag = if epub3 then "nav" else "div"
320327 let navData = fromStringLazy $ ppTopElement $
321328 unode "html" ! [("xmlns","http://www.w3.org/1999/xhtml")
322329 ,("xmlns:epub","http://www.idpf.org/2007/ops")] $
323− [ unode "head" $ unode "title" plainTitle
330+ [ unode "head" $
331+ [ unode "title" plainTitle
332+ , unode "link" ! [("rel","stylesheet"),("type","text/css"),("href","stylesheet.css")] $ () ]
324333 , unode "body" $
325− unode "nav" ! [("epub:type","toc")] $
334+ unode navtag ! [("epub:type","toc") | epub3] $
326335 [ unode "h1" plainTitle
327− , unode "ol" $ evalState (mapM (navPointNode navXhtmlFormatter) secs) 1]
336+ , unode "ol" ! [("class","toc")] $ evalState (mapM (navPointNode navXhtmlFormatter) secs) 1]
328337 ]
329338 let navEntry = mkEntry "nav.xhtml" navData
330339
@@ -357,9 +366,8 @@ writeEPUB opts doc@(Pandoc meta _) = do
357366 -- construct archive
358367 let archive = foldr addEntryToArchive emptyArchive
359368 (mimetypeEntry : containerEntry : appleEntry : stylesheetEntry : tpEntry :
360− contentsEntry : tocEntry :
361− ([navEntry | version == EPUB3] ++ picEntries ++ cpicEntry ++ cpgEntry ++
362− chapterEntries ++ fontEntries) )
369+ contentsEntry : tocEntry : navEntry :
370+ (picEntries ++ cpicEntry ++ cpgEntry ++ chapterEntries ++ fontEntries))
363371 return $ fromArchive archive
364372
365373metadataElement :: EPUBVersion -> String -> UUID -> String -> String -> [String]
@@ -385,7 +393,7 @@ metadataElement version metadataXML uuid lang title authors date currentTime mbC
385393 $ a | a <- authors ] ++
386394 [ unode "dc:date" date | not (elt `contains` "date") ] ++
387395 [ unode "meta" ! [("property", "dcterms:modified")] $
388− (showDateTimeISO8601 currentTime) | version == EPUB3 ] ++
396+ (showDateTimeISO8601 currentTime) | version == EPUB3] ++
389397 [ unode "meta" ! [("name","cover"), ("content","cover-image")] $ () |
390398 not (isNothing mbCoverImage) ]
391399 in elt{ elContent = elContent elt ++ map Elem newNodes }