From 25e29292e9cfecc260478aa9b094b8d37ff98eb5 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 3 Dec 2024 15:54:33 +0100 Subject: [PATCH] content --- setup.py | 2 +- src/librarian/builders/epub.py | 3 ++- src/librarian/covers/widgets/author.py | 24 +++++++++++++++++ src/librarian/dcparser.py | 3 ++- src/librarian/elements/__init__.py | 5 +++- src/librarian/elements/tools/__init__.py | 3 ++- src/librarian/fb2/footnotes.xslt | 11 +++++--- src/librarian/fb2/paragraphs.xslt | 6 +++++ src/librarian/html.py | 15 +++++++---- src/librarian/parser.py | 11 ++++++-- src/librarian/pdf/wl.cls | 4 +++ src/librarian/pdf/wl2tex.xslt | 2 +- src/librarian/xslt/book2html.xslt | 34 +++++++++++++++++++----- src/librarian/xslt/book2txt.xslt | 4 +-- 14 files changed, 102 insertions(+), 25 deletions(-) diff --git a/setup.py b/setup.py index 42cf475..750b124 100755 --- a/setup.py +++ b/setup.py @@ -22,7 +22,7 @@ def whole_tree(prefix, path): setup( name='librarian', - version='24.5.1', + version='24.5.2', description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats', author="Marek Stępniowski", author_email='marek@stepniowski.com', diff --git a/src/librarian/builders/epub.py b/src/librarian/builders/epub.py index e009d4a..1e57583 100644 --- a/src/librarian/builders/epub.py +++ b/src/librarian/builders/epub.py @@ -82,6 +82,7 @@ class EpubBuilder(Builder): orphans = True def __init__(self, *args, debug=False, **kwargs): + self.numbering = 0 self.chars = set() self.fundr = 0 self.debug = debug @@ -288,7 +289,7 @@ class EpubBuilder(Builder): file_as=str(author), uid='creator{}'.format(i) ) - for translator in self.document.meta.translators: + for i, translator in enumerate(self.document.meta.translators): self.output.add_author( translator.readable(), file_as=str(translator), diff --git a/src/librarian/covers/widgets/author.py b/src/librarian/covers/widgets/author.py index 381b7af..db35949 100644 --- a/src/librarian/covers/widgets/author.py +++ b/src/librarian/covers/widgets/author.py @@ -134,6 +134,30 @@ class AuthorBox(Widget): self.textboxes = [author_box] + elif translators: + translators_shortened = False + translator_box = None + while translator_box is None: + translator_str = 'tłum. ' + ', '.join(translators) + if translators_shortened: + translator_str += ' i in.' + try: + translator_box = TextBox( + self.width, + self.m.leading * 2, + [translator_str], + translator_font, + 1, + self.m.leading, + 0, + 1, 0 + ) + except DoesNotFit: + translators.pop() + translators_shortened = True + + self.textboxes = [translator_box] + if self.textboxes: self.margin_top = self.textboxes[0].margin_top diff --git a/src/librarian/dcparser.py b/src/librarian/dcparser.py index 910f5e1..629411e 100644 --- a/src/librarian/dcparser.py +++ b/src/librarian/dcparser.py @@ -106,7 +106,7 @@ class DCInfo(type): class WorkInfo(metaclass=DCInfo): FIELDS = ( Field(DCNS('creator'), 'authors', Person, salias='author', - multiple=True), + multiple=True, required=False), Field(DCNS('title'), 'title'), Field(DCNS('type'), 'type', required=False, multiple=True), @@ -140,6 +140,7 @@ class WorkInfo(metaclass=DCInfo): Field(WLNS('contentWarning'), 'content_warnings', multiple=True, required=False), Field(WLNS('developmentStage'), 'stage', required=False), + Field(WLNS('original'), 'original', required=False), ) @classmethod diff --git a/src/librarian/elements/__init__.py b/src/librarian/elements/__init__.py index b08c3e1..9481190 100644 --- a/src/librarian/elements/__init__.py +++ b/src/librarian/elements/__init__.py @@ -4,7 +4,7 @@ from lxml import etree from . import (blocks, comments, drama, figures, footnotes, front, headers, masters, paragraphs, poetry, ref, root, separators, styles, themes, - tools, base) + tools, base, bible) WL_ELEMENTS = { @@ -17,6 +17,7 @@ WL_ELEMENTS = { "coverLogoUrl": etree.ElementBase, "contentWarning": etree.ElementBase, "endnotes": etree.ElementBase, + "original": etree.ElementBase, "utwor": root.Utwor, "dramat_wierszowany_l": masters.Master, @@ -131,6 +132,8 @@ WL_ELEMENTS = { "wywiad_pyt": blocks.WywiadPyt, "wywiad_odp": blocks.WywiadOdp, + "werset": bible.Werset, + # Inline MathML, should really be namespaced. "mrow": etree.ElementBase, "mi": etree.ElementBase, diff --git a/src/librarian/elements/tools/__init__.py b/src/librarian/elements/tools/__init__.py index 99f81d9..0da3599 100644 --- a/src/librarian/elements/tools/__init__.py +++ b/src/librarian/elements/tools/__init__.py @@ -5,7 +5,8 @@ from ..base import WLElement class Numeracja(WLElement): - pass + def build_epub(self, builder): + builder.numbering = 0 class Rownolegle(WLElement): diff --git a/src/librarian/fb2/footnotes.xslt b/src/librarian/fb2/footnotes.xslt index 6d396fc..566de4c 100644 --- a/src/librarian/fb2/footnotes.xslt +++ b/src/librarian/fb2/footnotes.xslt @@ -12,9 +12,9 @@ xmlns:l="http://www.w3.org/1999/xlink"> - + - + fn @@ -31,14 +31,17 @@ [przypis edytorski] + + + [przypis tradycyjny]

- - + + note #fn diff --git a/src/librarian/fb2/paragraphs.xslt b/src/librarian/fb2/paragraphs.xslt index 13d3482..1ac9064 100644 --- a/src/librarian/fb2/paragraphs.xslt +++ b/src/librarian/fb2/paragraphs.xslt @@ -19,6 +19,12 @@

+ + + +

+
+ diff --git a/src/librarian/html.py b/src/librarian/html.py index 2919498..456f281 100644 --- a/src/librarian/html.py +++ b/src/librarian/html.py @@ -115,6 +115,7 @@ def transform(wldoc, stylesheet='legacy', options=None, flags=None, css=None, ga document.clean_ed_note() document.clean_ed_note('abstrakt') document.fix_pa_akap() + document.hebr_protect() if not options: options = {} @@ -311,7 +312,8 @@ def any_ancestor(element, test): def add_anchors(root): - counter = 1 + link_prefix = "f" + counter = {"f": 1} visible_counter = 1 for element in root.iterdescendants(): def f(e): @@ -329,18 +331,21 @@ def add_anchors(root): visible_counter = int(element.get('data-start')) except ValueError: visible_counter = 1 + if element.get("data-link"): + link_prefix = element.get("data-link") + counter[link_prefix] = 1 if any_ancestor(element, f): continue if element.tag == 'div' and 'verse' in element.get('class', ''): if visible_counter == 1 or visible_counter % 5 == 0: - add_anchor(element, "f%d" % counter, link_text=visible_counter) - counter += 1 + add_anchor(element, "%s%d" % (link_prefix, counter[link_prefix]), link_text=visible_counter) + counter[link_prefix] += 1 visible_counter += 1 elif 'paragraph' in element.get('class', ''): - add_anchor(element, "f%d" % counter, link_text=visible_counter) - counter += 1 + add_anchor(element, "%s%d" % (link_prefix, counter[link_prefix]), link_text=visible_counter) + counter[link_prefix] += 1 visible_counter += 1 diff --git a/src/librarian/parser.py b/src/librarian/parser.py index b4e4c5c..ca9691a 100644 --- a/src/librarian/parser.py +++ b/src/librarian/parser.py @@ -192,19 +192,26 @@ class WLDocument: for node in self.edoc.xpath('|'.join( '//%s//%s' % (note_tag, tag) for tag in - ('pa', 'pe', 'pr', 'pt', 'begin', 'end', 'motyw'))): + ('pa', 'pe', 'pr', 'pt', 'ptrad', 'begin', 'end', 'motyw'))): tail = node.tail node.clear() node.tag = 'span' node.tail = tail def fix_pa_akap(self): - for pa in ('pa','pe','pr','pt'): + for pa in ('pa','pe','pr','pt', 'ptrad'): for akap in self.edoc.findall(f'//{pa}/akap'): akap.getparent().set('blocks', 'true') if not akap.getparent().index(akap): akap.set('inline', 'true') + def hebr_protect(self): + for s in self.edoc.findall('//slowo_obce'): + if not s.text and len(s) == 1 and s[0].tag == 'slowo_obce': + continue + if re.match(r'^[\s\u0590-\u05ff]+$', s.text): + s.attrib['protect'] = 'true' + def editors(self): """Returns a set of all editors for book and its children. diff --git a/src/librarian/pdf/wl.cls b/src/librarian/pdf/wl.cls index d2eac63..33efa78 100644 --- a/src/librarian/pdf/wl.cls +++ b/src/librarian/pdf/wl.cls @@ -751,6 +751,10 @@ Letters={Uppercase} \par{\N#1}% } +\newcommand{\werset}[1]{% +\par{\noindent{\ignorespaces#1\vspace{1em}}}% +} + \newcommand{\mottopodpis}[1]{% \begin{em}% \begin{flushright}% diff --git a/src/librarian/pdf/wl2tex.xslt b/src/librarian/pdf/wl2tex.xslt index ab189e0..547c61c 100644 --- a/src/librarian/pdf/wl2tex.xslt +++ b/src/librarian/pdf/wl2tex.xslt @@ -348,7 +348,7 @@ + match="naglowek_osoba|naglowek_podrozdzial|podtytul_podrozdzial|miejsce_czas|didaskalia|lista_osoba|akap|akap_dialog|akap_cd|motto_podpis|naglowek_listy|srodtytul|podtytul_czesc|podtytul_rozdzial|podtytul_akt|podtytul_scena|werset"> diff --git a/src/librarian/xslt/book2html.xslt b/src/librarian/xslt/book2html.xslt index b009345..c06e41a 100644 --- a/src/librarian/xslt/book2html.xslt +++ b/src/librarian/xslt/book2html.xslt @@ -96,14 +96,14 @@
- +

Przypisy

- +
fn- - [] + []

@@ -111,6 +111,7 @@ [przypis tłumacza] [przypis redakcyjny] [przypis edytorski] + [przypis tradycyjny]

@@ -120,6 +121,7 @@ [przypis tłumacza] [przypis redakcyjny] [przypis edytorski] + [przypis tradycyjny]

@@ -464,9 +466,9 @@ - + - [] + [] @@ -487,7 +489,15 @@ - + + + foreign-word + + foreign-word-protected + + + + @@ -625,6 +635,15 @@ + +

+ + + +

+
+ + @@ -671,6 +690,9 @@ + + +
diff --git a/src/librarian/xslt/book2txt.xslt b/src/librarian/xslt/book2txt.xslt index d43c7d4..4bc919b 100644 --- a/src/librarian/xslt/book2txt.xslt +++ b/src/librarian/xslt/book2txt.xslt @@ -177,7 +177,7 @@ - + @@ -275,7 +275,7 @@ - + -- 2.20.1