X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/86becb1ae4d215dd782dfc054471d724f6dcd1d7..ba9a8ba0da6fcf7e89b75774cd07aac9706215da:/src/librarian/builders/epub.py diff --git a/src/librarian/builders/epub.py b/src/librarian/builders/epub.py index 8544846..e009d4a 100644 --- a/src/librarian/builders/epub.py +++ b/src/librarian/builders/epub.py @@ -1,13 +1,16 @@ +# This file is part of Librarian, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. +# from datetime import date +import io import os +import re import tempfile from ebooklib import epub from lxml import etree -import six from librarian import functions, OutputFile, get_resource, XHTMLNS from librarian.cover import make_cover from librarian.embeds.mathml import MathML -import librarian.epub from librarian.fonts import strip_font @@ -78,9 +81,11 @@ class EpubBuilder(Builder): isbn_field = 'isbn_epub' orphans = True - def __init__(self, *args, **kwargs): + def __init__(self, *args, debug=False, **kwargs): self.chars = set() self.fundr = 0 + self.debug = debug + self.splits = [] super().__init__(*args, **kwargs) def build(self, document, **kwargs): @@ -235,7 +240,7 @@ class EpubBuilder(Builder): p = etree.XML("""
Ta lektura, podobnie jak tysiÄ ce innych, jest dostÄpna on-line na stronie - wolnelektury.pl. + wolnelektury.pl.
""") p[0].attrib['href'] = str(self.document.meta.url) tp.append(p) @@ -245,7 +250,7 @@ class EpubBuilder(Builder): tp.append(etree.XML("""- Utwór opracowany zostaÅ w ramach projektu Wolne Lektury przez fundacjÄ Nowoczesna Polska. + Utwór opracowany zostaÅ w ramach projektu Wolne Lektury przez fundacjÄ Wolne Lektury.
""")) @@ -253,7 +258,7 @@ class EpubBuilder(Builder): etree.SubElement(tp, 'p', **{"class": "info"}).text = getattr(self.document.meta, self.isbn_field) tp.append(etree.XML(""" """)) self.add_html( @@ -280,13 +285,13 @@ class EpubBuilder(Builder): for i, author in enumerate(self.document.meta.authors): self.output.add_author( author.readable(), - file_as=six.text_type(author), + file_as=str(author), uid='creator{}'.format(i) ) for translator in self.document.meta.translators: self.output.add_author( translator.readable(), - file_as=six.text_type(translator), + file_as=str(translator), role='trl', uid='translator{}'.format(i) ) @@ -317,7 +322,7 @@ class EpubBuilder(Builder): def add_support_page(self): self.add_file( - get_resource('epub/support.xhtml'), + get_resource('res/epub/support.xhtml'), spine=True, toc='Wesprzyj Wolne Lektury' ) @@ -327,7 +332,7 @@ class EpubBuilder(Builder): media_type='image/png' ) self.add_file( - get_resource('epub/style.css'), + get_resource('res/epub/style.css'), media_type='text/css' ) @@ -379,8 +384,6 @@ class EpubBuilder(Builder): doctype='' ) - html = librarian.epub.squeeze_whitespace(html) - self.add_file( content=html, **kwargs @@ -556,7 +559,7 @@ class EpubBuilder(Builder): p[-1].tail = '.' etree.SubElement(p, "br") p[-1].tail = ( - "Fundacja Nowoczesna Polska zastrzega sobie prawa do wydania " + "Fundacja Wolne Lektury zastrzega sobie prawa do wydania " "krytycznego zgodnie z art. Art.99(2) Ustawy o prawach autorskich " "i prawach pokrewnych. WykorzystujÄ c zasoby z Wolnych Lektur, " "należy pamiÄtaÄ o zapisach licencji oraz zasadach, które " @@ -587,9 +590,11 @@ class EpubBuilder(Builder): newp().text = m.description - if m.editors: + editors = self.document.editors() + if editors: newp().text = 'Opracowanie redakcyjne i przypisy: %s.' % ( - ', '.join(e.readable() for e in sorted(self.document.editors()))) + ', '.join(e.readable() for e in sorted(editors)) + ) if m.funders: etree.SubElement(d, 'p', {'class': 'minor-info'}).text = '''PublikacjÄ wsparli i wsparÅy: @@ -664,7 +669,7 @@ class EpubBuilder(Builder): cover_maker = self.make_cover - cover_file = six.BytesIO() + cover_file = io.BytesIO() cover = cover_maker(self.document.meta, width=600) cover.save(cover_file) cover_name = 'cover.%s' % cover.ext() @@ -705,3 +710,8 @@ class EpubBuilder(Builder): file_name=name ) return name + + def process_comment(self, comment): + m = re.match(r'TRIM:(\d+)', comment.text) + if m is not None: + self.splits.append(comment.sourceline - int(m.group(1)))