From 9e4ab00dca15599a016b0621cdaae623bc8a723e Mon Sep 17 00:00:00 2001 From: Jan Szejko Date: Thu, 13 Oct 2016 16:48:10 +0200 Subject: [PATCH] epub download stub --- librarian/formats/epub/__init__.py | 50 ++++++++++++++---------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/librarian/formats/epub/__init__.py b/librarian/formats/epub/__init__.py index 38778ac..b7cf539 100644 --- a/librarian/formats/epub/__init__.py +++ b/librarian/formats/epub/__init__.py @@ -44,18 +44,18 @@ class EpubFormat(Format): mime.compress_type = zipfile.ZIP_STORED mime.extra = '' zip.writestr(mime, 'application/epub+zip') - zip.writestr('META-INF/container.xml', '' \ - '' \ - '') - - toc_file = etree.fromstring('' \ - '' \ - '') - nav_map = toc_file[-1] + zip.writestr('META-INF/container.xml', '' + '' + '') + + toc_file = etree.fromstring('' + '' + '') + # nav_map = toc_file[-1] if self.cover is not None: cover = self.cover(self.doc) @@ -71,9 +71,9 @@ class EpubFormat(Format): if cover.uses_dc_cover: if self.doc.meta.get_one('cover_by'): - document.edoc.getroot().set('data-cover-by', self.doc.meta.get_one('cover_by')) + self.doc.edoc.getroot().set('data-cover-by', self.doc.meta.get_one('cover_by')) if self.doc.meta.get_one('cover_source'): - document.edoc.getroot().set('data-cover-source', self.doc.meta.get_one('cover_source')) + self.doc.edoc.getroot().set('data-cover-source', self.doc.meta.get_one('cover_source')) manifest.append(etree.fromstring( '')) @@ -83,7 +83,6 @@ class EpubFormat(Format): opf.getroot()[0].append(etree.fromstring('')) guide.append(etree.fromstring('')) - ctx = Context(format=self) ctx.toc = TOC() ctx.toc_level = 0 @@ -110,18 +109,17 @@ class EpubFormat(Format): if len(ctx.footnotes.output): ctx.toc.add("Przypisy", "footnotes.html") - manifest.append(etree.Element(OPFNS('item'), - id='footnotes', href='footnotes.html', - **{'media-type': "application/xhtml+xml"})) + manifest.append(etree.Element( + OPFNS('item'), id='footnotes', href='footnotes.html', + **{'media-type': "application/xhtml+xml"})) spine.append(etree.Element('itemref', idref='footnotes')) wrap = etree.parse(get_resource('formats/epub/res/footnotes.html')) extend_element(wrap.find('//*[@id="footnotes"]'), ctx.footnotes.output) - #chars = chars.union(used_chars(html_tree.getroot())) + # chars = chars.union(used_chars(html_tree.getroot())) zip.writestr('OPS/footnotes.html', etree.tostring( wrap, method="html", pretty_print=True)) - zip.writestr('OPS/content.opf', etree.tostring(opf, pretty_print=True)) ctx.toc.render(toc_file[-1]) zip.writestr('OPS/toc.ncx', etree.tostring(toc_file, pretty_print=True)) @@ -180,8 +178,8 @@ class Footnotes(object): def append(self, items): self.counter += 1 - e = etree.Element("a", - href="part%d.html#footnote-anchor-%d" % (int(items[0].get('part_no')), self.counter), + e = etree.Element( + "a", href="part%d.html#footnote-anchor-%d" % (int(items[0].get('part_no')), self.counter), id="footnote-%d" % self.counter, style="float:left;margin-right:1em") e.text = "[%d]" % self.counter @@ -189,9 +187,8 @@ class Footnotes(object): self.output.append(e) for item in items: extend_element(self.output, item) - anchor = etree.Element("a", - id="footnote-anchor-%d" % self.counter, - href="footnotes.html#footnote-%d" % self.counter) + anchor = etree.Element( + "a", href="footnotes.html#footnote-%d" % self.counter, id="footnote-anchor-%d" % self.counter) anchor.text = "[%d]" % self.counter return anchor @@ -239,7 +236,7 @@ class AsideR(EpubRenderer): def render(self, element, ctx): outputs = list(super(AsideR, self).render(element, ctx)) anchor = ctx.footnotes.append(outputs) - wrapper, inside = self.text_container() #etree.Element('_', part_no=str(ctx.part_no)) + wrapper, inside = self.text_container() # etree.Element('_', part_no=str(ctx.part_no)) inside.append(anchor) yield wrapper EpubFormat.renderers.register(core.Aside, None, AsideR('div')) @@ -276,4 +273,3 @@ EpubFormat.renderers.register(core.Section, None, SectionR()) class SpanR(EpubRenderer): pass EpubFormat.renderers.register(core.Span, None, SpanR('span')) - -- 2.20.1