diff --git a/fanficfare/writers/writer_epub.py b/fanficfare/writers/writer_epub.py
index dfb90c09..49b7baed 100644
--- a/fanficfare/writers/writer_epub.py
+++ b/fanficfare/writers/writer_epub.py
@@ -327,6 +327,11 @@ div { margin: 0pt; padding: 0pt; }
return retval
+ ## in case it needs more complexity later.
+ def write_to_epub(self, outputepub, href, data):
+ outputepub.writestr(href,data)
+ self.svg_files[href] = b'
|
)\n*',r'\1\n',fullhtml)
# logger.debug("write OEBPS/file%s.xhtml"%chap['index04'])
- outputepub.writestr("OEBPS/file%s.xhtml"%chap['index04'],fullhtml.encode('utf-8'))
+ self.write_to_epub(outputepub,"OEBPS/file%s.xhtml"%chap['index04'],fullhtml.encode('utf-8'))
del fullhtml
if self.story.calibrebookmark:
- outputepub.writestr("META-INF/calibre_bookmarks.txt",self.story.calibrebookmark)
+ self.write_to_epub(outputepub,"META-INF/calibre_bookmarks.txt",self.story.calibrebookmark)
+
+ manifest = contentdom.createElement("manifest")
+ package.appendChild(manifest)
+ for item in items:
+ (id,href,type,title)=item
+ attrs = {'id':id,
+ 'href':href,
+ 'media-type':type}
+ if epub3:
+ props = []
+ if id=='cover':
+ ## Flag the cover *page*--epub3 only flags cover *img*
+ props.append('calibre:title-page')
+ if type == 'application/xhtml+xml' and self.svg_files[href]:
+ ## epub3 wants content files containing tags
+ ## flagged in the metadata.
+ props.append('svg')
+ if props:
+ attrs['properties'] = ' '.join(props)
+ manifest.appendChild(newTag(contentdom, "item", attrs=attrs))
+ if epub3:
+ # epub3 nav
+ #
+ manifest.appendChild(newTag(contentdom,"item",
+ attrs={'href':'nav.xhtml',
+ 'id':'nav',
+ 'media-type':'application/xhtml+xml',
+ 'properties':'nav'
+ }))
+
+
+ spine = newTag(contentdom,"spine",attrs={"toc":"ncx"})
+ package.appendChild(spine)
+ for itemref in itemrefs:
+ spine.appendChild(newTag(contentdom,"itemref",
+ attrs={"idref":itemref,
+ "linear":"yes"}))
+ # guide only exists if there's a cover.
+ if guide:
+ package.appendChild(guide)
+
+ # write content.opf to zip.
+ contentxml = contentdom.toxml(encoding='utf-8')
+ # tweak for brain damaged Nook STR. Nook insists on name before content.
+ contentxml = contentxml.replace(ensure_binary(''%coverimgid),
+ ensure_binary(''%coverimgid))
+
+ # write_to_epub used, but already passed using svg_files
+ self.write_to_epub(outputepub,"content.opf",contentxml)
+
+ contentdom.unlink()
+ del contentdom
+
+ ## create toc.ncx file
+ tocncxdom = getDOMImplementation().createDocument(None, "ncx", None)
+ ncx = tocncxdom.documentElement
+ ncx.setAttribute("version","2005-1")
+ ncx.setAttribute("xmlns","http://www.daisy.org/z3986/2005/ncx/")
+ head = tocncxdom.createElement("head")
+ ncx.appendChild(head)
+ head.appendChild(newTag(tocncxdom,"meta",
+ attrs={"name":"dtb:uid", "content":uniqueid}))
+ head.appendChild(newTag(tocncxdom,"meta",
+ attrs={"name":"dtb:depth", "content":"1"}))
+ head.appendChild(newTag(tocncxdom,"meta",
+ attrs={"name":"dtb:totalPageCount", "content":"0"}))
+ head.appendChild(newTag(tocncxdom,"meta",
+ attrs={"name":"dtb:maxPageNumber", "content":"0"}))
+
+ docTitle = tocncxdom.createElement("docTitle")
+ docTitle.appendChild(newTag(tocncxdom,"text",text=self.getMetadata('title')))
+ ncx.appendChild(docTitle)
+
+ tocnavMap = tocncxdom.createElement("navMap")
+ ncx.appendChild(tocnavMap)
+
+ #
+ #
+ #
+ #
+ #
+ #
+ index=0
+ for item in items:
+ (id,href,type,title)=item
+ # only items to be skipped, cover.xhtml, images, toc.ncx, stylesheet.css, should have no title.
+ if title :
+ navPoint = newTag(tocncxdom,"navPoint",
+ attrs={'id':id,
+ 'playOrder':unicode(index)})
+ tocnavMap.appendChild(navPoint)
+ navLabel = newTag(tocncxdom,"navLabel")
+ navPoint.appendChild(navLabel)
+ ## the xml library will re-escape as needed.
+ navLabel.appendChild(newTag(tocncxdom,"text",text=stripHTML(title)))
+ navPoint.appendChild(newTag(tocncxdom,"content",attrs={"src":href}))
+ index=index+1
+
+ # write_to_epub used, but already passed using svg_files
+ self.write_to_epub(outputepub,"toc.ncx",tocncxdom.toxml(encoding='utf-8'))
+ tocncxdom.unlink()
+ del tocncxdom
+
+ if epub3:
+ ## create nav.xhtml file
+ tocnavdom = getDOMImplementation().createDocument(None, "html", None)
+ navxhtml = tocnavdom.documentElement
+ navxhtml.setAttribute("xmlns","http://www.w3.org/1999/xhtml")
+ navxhtml.setAttribute("xmlns:epub","http://www.idpf.org/2007/ops")
+ navxhtml.setAttribute("lang",langcode)
+ navxhtml.setAttribute("xml:lang",langcode)
+ head = tocnavdom.createElement("head")
+ navxhtml.appendChild(head)
+ head.appendChild(newTag(tocnavdom,"title",text="Navigation"))
+ #
+ head.appendChild(newTag(tocnavdom,"meta",
+ attrs={"http-equiv":"Content-Type",
+ "content":"text/html; charset=utf-8"}))
+
+ body = tocnavdom.createElement("body")
+ navxhtml.appendChild(body)
+ nav = newTag(tocnavdom,"nav",
+ attrs={"epub:type":"toc"})
+ body.appendChild(nav)
+ ol = newTag(tocnavdom,"ol")
+ nav.appendChild(ol)
+
+ for item in items:
+ (id,href,type,title)=item
+ # only items to be skipped, cover.xhtml, images, toc.nav,
+ # stylesheet.css, should have no title.
+ if title:
+ li = newTag(tocnavdom,"li")
+ ol.appendChild(li)
+ atag = newTag(tocnavdom,"a",
+ attrs={"href":href},
+ text=stripHTML(title))
+ li.appendChild(atag)
+
+ if self.story.cover and not self.use_oldcover:
+ #
+ nav = newTag(tocnavdom,"nav",
+ attrs={"epub:type":"landmarks",
+ "hidden":""})
+ body.appendChild(nav)
+ ol = newTag(tocnavdom,"ol")
+ nav.appendChild(ol)
+ li = newTag(tocnavdom,"li")
+ ol.appendChild(li)
+ atag = newTag(tocnavdom,"a",
+ attrs={"href":"OEBPS/cover.xhtml",
+ "epub:type":"cover"},
+ text="Cover")
+ li.appendChild(atag)
+
+ # write_to_epub used, but already passed using svg_files
+ self.write_to_epub(outputepub,"nav.xhtml",tocnavdom.toxml(encoding='utf-8'))
+ tocnavdom.unlink()
+ del tocnavdom
# declares all the files created by Windows. otherwise, when
# it runs in appengine, windows unzips the files as 000 perms.