letters 24.5.3
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 17 Dec 2024 13:05:59 +0000 (14:05 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 17 Dec 2024 13:05:59 +0000 (14:05 +0100)
setup.py
src/librarian/elements/__init__.py
src/librarian/elements/letter/__init__.py [new file with mode: 0644]
src/librarian/parser.py
src/librarian/pdf/wl.cls
src/librarian/pdf/wl2tex.xslt
src/librarian/res/epub/style.css
src/librarian/xslt/book2html.xslt
src/librarian/xslt/book2txt.xslt

index 750b124..418f7bc 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_tree(prefix, path):
 
 setup(
     name='librarian',
-    version='24.5.2',
+    version='24.5.3',
     description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats',
     author="Marek StÄ™pniowski",
     author_email='marek@stepniowski.com',
index 9481190..34d3fac 100644 (file)
@@ -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, bible)
+               tools, base, bible, letter)
 
 
 WL_ELEMENTS = {
@@ -133,6 +133,13 @@ WL_ELEMENTS = {
     "wywiad_odp": blocks.WywiadOdp,
 
     "werset": bible.Werset,
+
+    "list": letter.List,
+    "adresat": letter.Adresat,
+    "miejsce_data": letter.MiejsceData,
+    "naglowek_listu": letter.NaglowekListu,
+    "pozdrowienie": letter.Pozdrowienie,
+    "podpis": letter.Podpis,
     
     # Inline MathML, should really be namespaced.
     "mrow": etree.ElementBase,
diff --git a/src/librarian/elements/letter/__init__.py b/src/librarian/elements/letter/__init__.py
new file mode 100644 (file)
index 0000000..a062377
--- /dev/null
@@ -0,0 +1,76 @@
+from ..base import WLElement
+
+
+class List(WLElement):
+    CAN_HAVE_TEXT = False
+
+    TXT_TOP_MARGIN = 3
+    TXT_BOTTOM_MARGIN = 2
+    TXT_LEGACY_TOP_MARGIN = 1
+    TXT_LEGACY_BOTTOM_MARGIN = 0
+
+    HTML_TAG = 'blockquote'
+
+    EPUB_TAG = 'div'
+    EPUB_CLASS = 'block'
+
+
+class Adresat(WLElement):
+    STRIP = True
+    SHOULD_HAVE_ID = True
+
+    TXT_TOP_MARGIN = 2
+    TXT_BOTTOM_MARGIN = 2
+    TXT_LEGACY_TOP_MARGIN = 2
+    TXT_LEGACY_BOTTOM_MARGIN = 0
+
+    EPUB_TAG = HTML_TAG = 'p'
+    EPUB_CLASS = HTML_CLASS = 'paragraph adresat'
+
+class MiejsceData(WLElement):
+    STRIP = True
+    SHOULD_HAVE_ID = True
+
+    TXT_TOP_MARGIN = 2
+    TXT_BOTTOM_MARGIN = 2
+    TXT_LEGACY_TOP_MARGIN = 2
+    TXT_LEGACY_BOTTOM_MARGIN = 0
+
+    EPUB_TAG = HTML_TAG = 'p'
+    EPUB_CLASS = HTML_CLASS = 'paragraph miejscedata'
+
+class NaglowekListu(WLElement):
+    STRIP = True
+    SHOULD_HAVE_ID = True
+
+    TXT_TOP_MARGIN = 2
+    TXT_BOTTOM_MARGIN = 2
+    TXT_LEGACY_TOP_MARGIN = 2
+    TXT_LEGACY_BOTTOM_MARGIN = 0
+
+    EPUB_TAG = HTML_TAG = 'p'
+    EPUB_CLASS = HTML_CLASS = 'paragraph nagloweklistu'
+
+class Pozdrowienie(WLElement):
+    STRIP = True
+    SHOULD_HAVE_ID = True
+
+    TXT_TOP_MARGIN = 2
+    TXT_BOTTOM_MARGIN = 2
+    TXT_LEGACY_TOP_MARGIN = 2
+    TXT_LEGACY_BOTTOM_MARGIN = 0
+
+    EPUB_TAG = HTML_TAG = 'p'
+    EPUB_CLASS = HTML_CLASS = 'paragraph pozdrowienie'
+
+class Podpis(WLElement):
+    STRIP = True
+    SHOULD_HAVE_ID = True
+
+    TXT_TOP_MARGIN = 2
+    TXT_BOTTOM_MARGIN = 2
+    TXT_LEGACY_TOP_MARGIN = 2
+    TXT_LEGACY_BOTTOM_MARGIN = 0
+
+    EPUB_TAG = HTML_TAG = 'p'
+    EPUB_CLASS = HTML_CLASS = 'paragraph podpis'
index ca9691a..1f18dbd 100644 (file)
@@ -209,7 +209,7 @@ class WLDocument:
         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):
+            if re.match(r'^[\s\u0590-\u05ff]+$', s.text or ''):
                 s.attrib['protect'] = 'true'
 
     def editors(self):
index 33efa78..a56629b 100644 (file)
@@ -828,6 +828,32 @@ Letters={Uppercase}
 {\scshape \MakeLowercase{#1}}%
 }
 
+
+\newcommand{\list}[1]{%
+\begin{quotation}%
+#1%
+\end{quotation}%
+}
+  
+\newcommand{\adresat}[1]{%
+\par{\N#1}%
+}
+\newcommand{\miejscedata}[1]{%
+\par{\raggedright\N#1}%
+}
+\newcommand{\nagloweklistu}[1]{%
+\begin{center}%
+\par{\N#1}%
+\end{center}%
+}
+\newcommand{\pozdrowienie}[1]{%
+\par{\hspace{4em}\N#1}%
+}
+\newcommand{\podpis}[1]{%
+\par{\hspace{4em}\N#1}%
+}
+
+
 \newcommand{\sekcjaswiatlo}{%
 \vspace{30pt}%
 }
index 547c61c..319f608 100644 (file)
 
 
 <xsl:template
-    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">
+    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|list|adresat|miejsce_data|naglowek_listu|pozdrowienie|podpis">
   <xsl:choose>
     <xsl:when test="@inline">
       <xsl:apply-templates mode="inline"/>
index 8325c12..5ec46c5 100644 (file)
@@ -227,6 +227,15 @@ div.didaskalia
     margin: 0;
     text-indent: 1.2em;
 }
+.paragraph.nagloweklistu {
+    text-align: center;
+    margin: .5em 0;
+    text-indent: 0;
+}
+.paragraph.miejscedata, .paragraph.pozdrowienie, .paragraph.podpis {
+    text-align: right;
+    text-indent: 0;
+}
 
 h1 + .paragraph, h2 + .paragraph
 {
index c06e41a..b128b7e 100644 (file)
     </p>
 </xsl:template>
 
+<xsl:template match="list">
+    <blockquote class="letter"><xsl:apply-templates /></blockquote>
+</xsl:template>
+<xsl:template match="adresat">
+  <p class="paragraph adresat">
+    <xsl:call-template name="block-args" />
+    <xsl:call-template name="section-anchor"/>
+    <xsl:apply-templates mode="inline" />
+  </p>
+</xsl:template>
+<xsl:template match="miejsce_data">
+  <p class="paragraph miejsce_data">
+    <xsl:call-template name="block-args" />
+    <xsl:call-template name="section-anchor"/>
+    <xsl:apply-templates mode="inline" />
+  </p>
+</xsl:template>
+<xsl:template match="naglowek_listu">
+  <p class="paragraph naglowek_listu">
+    <xsl:call-template name="block-args" />
+    <xsl:call-template name="section-anchor"/>
+    <xsl:apply-templates mode="inline" />
+  </p>
+</xsl:template>
+<xsl:template match="pozdrowienie">
+  <p class="paragraph pozdrowienie">
+    <xsl:call-template name="block-args" />
+    <xsl:call-template name="section-anchor"/>
+    <xsl:apply-templates mode="inline" />
+  </p>
+</xsl:template>
+<xsl:template match="podpis">
+  <p class="paragraph podpis">
+    <xsl:call-template name="block-args" />
+    <xsl:call-template name="section-anchor"/>
+    <xsl:apply-templates mode="inline" />
+  </p>
+</xsl:template>
+
 <xsl:template match="strofa" mode="inline">
     <xsl:apply-templates select="." />
 </xsl:template>
index 4bc919b..290a8aa 100644 (file)
 <xsl:value-of select="wl:wrap_words(wl:strip($content), $wrapping)" />
 </xsl:template>
 
+<xsl:template match="list">
+<xsl:text>
+
+
+</xsl:text>
+<xsl:apply-templates />
+<xsl:text>
+
+
+</xsl:text>
+</xsl:template>
+<xsl:template match="adesat">
+  <xsl:text>
+                </xsl:text>
+  <xsl:apply-templates select="*|text()" mode="inline" />
+  <xsl:text>
+</xsl:text>
+</xsl:template>
+<xsl:template match="miejsce_data">
+  <xsl:text>
+                </xsl:text>
+  <xsl:apply-templates select="*|text()" mode="inline" />
+  <xsl:text>
+</xsl:text>
+</xsl:template>
+<xsl:template match="naglowek_listu">
+  <xsl:text>
+
+        </xsl:text>
+  <xsl:apply-templates select="*|text()" mode="inline" />
+  <xsl:text>
+</xsl:text>
+</xsl:template>
+<xsl:template match="pozdrowienie">
+  <xsl:text>
+    </xsl:text>
+  <xsl:apply-templates select="*|text()" mode="inline" />
+  <xsl:text>
+</xsl:text>
+</xsl:template>
+<xsl:template match="podpis">
+  <xsl:text>
+        </xsl:text>
+  <xsl:apply-templates select="*|text()" mode="inline" />
+  <xsl:text>
+</xsl:text>
+</xsl:template>
+
 <xsl:template match="strofa">
 <xsl:text>
 </xsl:text>