tabs and centered verses 2.4.10
authorRadek Czajka <rczajka@rczajka.pl>
Tue, 10 Jan 2023 14:54:18 +0000 (15:54 +0100)
committerRadek Czajka <rczajka@rczajka.pl>
Tue, 10 Jan 2023 15:17:02 +0000 (16:17 +0100)
setup.py
src/librarian/elements/__init__.py
src/librarian/elements/poetry/__init__.py
src/librarian/elements/poetry/wers_srodek.py [new file with mode: 0644]
src/librarian/elements/tools/__init__.py
src/librarian/epub/style.css
src/librarian/xslt/book2html.xslt

index 91cf6a0..cdeb58f 100755 (executable)
--- a/setup.py
+++ b/setup.py
@@ -22,7 +22,7 @@ def whole_tree(prefix, path):
 
 setup(
     name='librarian',
-    version='2.4.8',
+    version='2.4.10',
     description='Converter from WolneLektury.pl XML-based language to XHTML, TXT and other formats',
     author="Marek StÄ™pniowski",
     author_email='marek@stepniowski.com',
index 6efd725..c715e3a 100644 (file)
@@ -23,6 +23,8 @@ WL_ELEMENTS = {
     "opowiadanie": masters.Master,
     "powiesc": masters.Master,
 
+    "blok": tools.WLElement,
+    
     "autor_utworu": front.AutorUtworu,
     "dzielo_nadrzedne": front.DzieloNadrzedne,
     "nazwa_utworu": front.NazwaUtworu,
@@ -67,6 +69,7 @@ WL_ELEMENTS = {
     "wers_akap": poetry.WersAkap,
     "zastepnik_wersu": poetry.ZastepnikWersu,
     "wers_do_prawej": poetry.WersDoPrawej,
+    "wers_srodek": poetry.WersSrodek,
     
     "pa": footnotes.PA,
     "pe": footnotes.PE,
@@ -117,6 +120,8 @@ WL_ELEMENTS = {
     "ilustr": figures.Ilustr,
 
     "numeracja": tools.Numeracja,
+    "rownolegle": tools.Rownolegle,
+    "tab": tools.Tab,
 
     # Section
     "wywiad_pyt": blocks.WywiadPyt,
index 4784ad0..6eeee4a 100644 (file)
@@ -2,6 +2,7 @@ from .strofa import Strofa
 from .wers_akap import WersAkap
 from .wers_cd import WersCd
 from .wers_do_prawej import WersDoPrawej
+from .wers_srodek import WersSrodek
 from .wers import Wers
 from .wers_wciety import WersWciety
 from .zastepnik_wersu import ZastepnikWersu
diff --git a/src/librarian/elements/poetry/wers_srodek.py b/src/librarian/elements/poetry/wers_srodek.py
new file mode 100644 (file)
index 0000000..2e95db3
--- /dev/null
@@ -0,0 +1,9 @@
+from .wers import Wers
+
+
+class WersSrodek(Wers):
+    TXT_PREFIX = '           '
+
+    EPUB_ATTR = HTML_ATTR = {
+        "style": "text-align: center",
+    }
index 1e9d53f..ad0ab97 100644 (file)
@@ -4,3 +4,32 @@ from ..base import WLElement
 class Numeracja(WLElement):
     pass
 
+
+class Rownolegle(WLElement):
+    def build_epub(self, builder):
+        for i, block in enumerate(self):
+            attr = {"class": "rownolegly-blok"}
+            if not i:
+                attr['class'] += ' first'
+            if i == len(self) - 1:
+                attr['class'] += ' last'
+            builder.start_element('div', attr)
+            self.build_epub(block, builder)
+            builder.end_element()
+
+
+class Tab(WLElement):
+    EPUB_TAG = HTML_TAG = 'span'
+
+    def get_html_attr(self, builder):
+        try:
+            szer = int(self.get('szer', 1))
+        except:
+            szer = 1
+        return {
+            "display": "inline-block",
+            "width": f"{szer}em",
+        }
+
+    get_epub_attr = get_html_attr
+
index dfd9fe7..8325c12 100644 (file)
@@ -402,3 +402,14 @@ th, td {
        font-size: 1.3em;
        line-height: 1.4em;
 }
+
+.rownolegly-blok {
+    border-left: 2px solid red;
+    padding-left: .5em;
+}
+.rownolegly-blok.first {
+    border-radius: 0 0 0 .75em;
+}
+.rownolegly-blok.last {
+    border-radius: .75em 0 0 0;
+}
index f540b49..2057326 100644 (file)
             <xsl:when test="count(br) > 0">
                 <xsl:call-template name="verse">
                     <xsl:with-param name="verse-content" select="br[1]/preceding-sibling::text() | br[1]/preceding-sibling::node()" />
-                    <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej'][1]" />
+                    <xsl:with-param name="verse-type" select="br[1]/preceding-sibling::*[name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej' or name() = 'wers_srodek'][1]" />
                 </xsl:call-template>
                 <xsl:for-each select="br">             
                                <!-- Each BR tag "consumes" text after it -->
                     <xsl:call-template name="verse">
                         <xsl:with-param name="verse-content"
                             select="following-sibling::text()[count(preceding-sibling::br) = $lnum+1] | following-sibling::node()[count(preceding-sibling::br) = $lnum+1]" />
-                        <xsl:with-param name="verse-type" select="following-sibling::*[count(preceding-sibling::br) = $lnum+1 and (name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej')][1]" />
+                        <xsl:with-param name="verse-type" select="following-sibling::*[count(preceding-sibling::br) = $lnum+1 and (name() = 'wers_wciety' or name() = 'wers_akap' or name() = 'wers_cd' or name() = 'wers_do_prawej' or name() = 'wers_srodek')][1]" />
                     </xsl:call-template>
                 </xsl:for-each>
             </xsl:when>
             <xsl:otherwise>
                 <xsl:call-template name="verse">
                     <xsl:with-param name="verse-content" select="text() | node()" />
-                    <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej[1]" />
+                    <xsl:with-param name="verse-type" select="wers_wciety|wers_akap|wers_cd|wers_do_prawej|wers_srodek[1]" />
                  </xsl:call-template>
             </xsl:otherwise>
         </xsl:choose>
             <xsl:when test="name($verse-type) = 'wers_do_prawej'">
                 <xsl:attribute name="style">text-align: right</xsl:attribute>
             </xsl:when>
+            <xsl:when test="name($verse-type) = 'wers_srodek'">
+                <xsl:attribute name="style">text-align: center</xsl:attribute>
+            </xsl:when>
         </xsl:choose>
         <xsl:apply-templates select="$verse-content" mode="inline" />
     </div>
     <xsl:value-of select="wl:person_name(.)" />
 </xsl:template>
 
+<xsl:template match="rownolegle">
+    <xsl:apply-templates mode="rownolegle" />
+</xsl:template>
+<xsl:template match="*" mode="rownolegle">
+  <!-- is it last? -->
+  <div>
+    <xsl:attribute name="class">
+      <xsl:text>rownolegly-blok</xsl:text>
+      <xsl:if test="not(following-sibling::*)">
+        <xsl:text> last</xsl:text>
+      </xsl:if>
+      <xsl:if test="not(preceding-sibling::*)">
+        <xsl:text> first</xsl:text>
+      </xsl:if>
+    </xsl:attribute>
+    <xsl:attribute name="style">
+      <xsl:text>border-left: 2px solid red; padding-left: .5em;</xsl:text>
+      <xsl:if test="not(following-sibling::*)">
+        <xsl:text> border-radius: 0 0 0 .75em;</xsl:text>
+      </xsl:if>
+      <xsl:if test="not(preceding-sibling::*)">
+        <xsl:text> border-radius: .75em 0 0 0;</xsl:text>
+      </xsl:if>
+    </xsl:attribute>
+    <xsl:apply-templates match="." />
+  </div>
+</xsl:template>
+
+<xsl:template match="tab" mode="inline">
+  <span>
+    <xsl:choose>
+      <xsl:when test="@szer">
+        <xsl:attribute name="style">display: inline-block; width: <xsl:value-of select="@szer" />em</xsl:attribute>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:attribute name="style">display: inline-block; width: 1em</xsl:attribute>
+      </xsl:otherwise>
+    </xsl:choose>
+  </span>
+</xsl:template>
+
 
 <!-- ================ -->
 <!-- = IGNORED TAGS = -->