From eae370b75207e1dc15f5f3f7ee7a402c7721d9a8 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Mon, 20 Dec 2021 11:50:38 +0100 Subject: [PATCH] New mobi builder. --- src/librarian/builders/__init__.py | 2 + src/librarian/builders/epub.py | 21 ++++----- src/librarian/builders/mobi.py | 45 +++++++++++++++++++ src/librarian/elements/__init__.py | 1 - src/librarian/elements/base.py | 27 +++++++---- src/librarian/elements/styles/tytul_dziela.py | 4 +- src/librarian/hyphenator.py | 8 ++-- 7 files changed, 82 insertions(+), 26 deletions(-) create mode 100644 src/librarian/builders/mobi.py diff --git a/src/librarian/builders/__init__.py b/src/librarian/builders/__init__.py index e359cd6..d8acb82 100644 --- a/src/librarian/builders/__init__.py +++ b/src/librarian/builders/__init__.py @@ -4,6 +4,7 @@ from .html import HtmlBuilder, StandaloneHtmlBuilder, DaisyHtmlBuilder from .sanitize import Sanitizer from .daisy import DaisyBuilder from .epub import EpubBuilder +from .mobi import MobiBuilder from .pdf import PdfBuilder @@ -16,5 +17,6 @@ builders = OrderedDict([ ("sanitizer", Sanitizer), ("epub", EpubBuilder), + ("mobi", MobiBuilder), ("pdf", PdfBuilder), ]) diff --git a/src/librarian/builders/epub.py b/src/librarian/builders/epub.py index 4471e30..401136f 100644 --- a/src/librarian/builders/epub.py +++ b/src/librarian/builders/epub.py @@ -29,10 +29,11 @@ class Xhtml: class Builder: file_extension = None - def __init__(self, base_url=None, fundraising=None): + def __init__(self, base_url=None, fundraising=None, cover=None): self._base_url = base_url or 'file:///home/rczajka/for/fnp/librarian/temp~/maly/img/' self.fundraising = fundraising self.footnotes = etree.Element('div', id='footnotes') + self.make_cover = cover or make_cover self.cursors = { # None: None, @@ -78,6 +79,7 @@ class Builder: class EpubBuilder(Builder): file_extension = 'epub' + isbn_field = 'isbn_epub' def __init__(self, *args, **kwargs): self.chars = set() @@ -109,7 +111,6 @@ class EpubBuilder(Builder): self.set_metadata() - self.add_cover() self.add_title_page() @@ -212,10 +213,10 @@ class EpubBuilder(Builder): e = self.document.tree.find('//autor_utworu') if e is not None: - etree.SubElement(tp, 'h2', **{'class': 'author'}).text = e.raw_printable_text() + etree.SubElement(tp, 'h2', **{'class': 'author'}).text = e.raw_printable_text(self) e = self.document.tree.find('//nazwa_utworu') if e is not None: - etree.SubElement(tp, 'h1', **{'class': 'title'}).text = e.raw_printable_text() + etree.SubElement(tp, 'h1', **{'class': 'title'}).text = e.raw_printable_text(self) if not len(tp): for author in self.document.meta.authors: @@ -251,8 +252,8 @@ class EpubBuilder(Builder):

""")) - if self.document.meta.isbn_epub: - etree.SubElement(tp, 'p', **{"class": "info"}).text = self.document.meta.isbn_epub + if getattr(self.document.meta, self.isbn_field): + etree.SubElement(tp, 'p', **{"class": "info"}).text = getattr(self.document.meta, self.isbn_field) tp.append(etree.XML("""