Drop lots of legacy code. Support Python 3.7-3.11.
[librarian.git] / src / librarian / xslt / book2html.xslt
index 7d2d6b5..390d147 100644 (file)
@@ -2,7 +2,7 @@
 <!--
 
    This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
-   Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+   Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 
 -->
 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                                <xsl:value-of select="$css" />
                        </xsl:attribute>
                </link>
+               <style>
+                 .ilustr.prawo img {
+                 float: right;
+                 }
+                 .ilustr.lewo img {
+                 float: left;
+                 }
+                 .ilustr.srodek {
+                 text-align: center;
+                 }
+                 .ilustr .stop {
+                 clear: both;
+                 }
+                 .ilustr.oblew .stop {
+                 clear: none;
+                 }
+
+                  .ilustr.oblew img {
+                    margin-bottom: 1em;
+                  }
+                  .ilustr.oblew.lewo img {
+                    margin-right: 2em;
+                    }
+                    .ilustr.oblew.prawo img {
+                    margin-left: 2em;
+                    }
+
+
+                    .ilustr img {
+                    min-width: 200px !important;
+                    }
+                    @media screen and (max-width: 320px) {
+                    .ilustr img {
+                    width: 100% !important;
+                    min-width: auto !important;
+                    }
+                    .ilustr.lewo img {
+                    float: none;
+                    }
+                    .ilustr.prawo img {
+                    float:none;
+                    }
+                    .ilustr.oblew.prawo img {
+                    margin-left: 0;
+                    }
+                    .ilustr.oblew.lewo img{
+                    margin-right: 0;
+                    }
+                    .ilustr .stop {
+                   clear: none;
+                    }
+
+                    }
+               </style>
            </head>
             <body>
               <xsl:call-template name="book-text" />
                                 </p>
                             </xsl:when>
                             <xsl:otherwise>
-                                <xsl:apply-templates select="text()|*" mode="inline" />
+                              <xsl:apply-templates />
+                              <p>
+                                <xsl:if test="name()='pa'"> [przypis autorski]</xsl:if>
+                                <xsl:if test="name()='pt'"> [przypis tłumacza]</xsl:if>
+                                <xsl:if test="name()='pr'"> [przypis redakcyjny]</xsl:if>
+                                <xsl:if test="name()='pe'"> [przypis edytorski]</xsl:if>
+                              </p>
                             </xsl:otherwise>
                         </xsl:choose>
                     </div>
 
 <xsl:template match="motto">
     <xsl:call-template name="section-anchor"/>
-    <div class="motto"><xsl:apply-templates /></div>
+    <div class="motto">
+      <xsl:call-template name="block-args" />
+      <xsl:apply-templates />
+    </div>
 </xsl:template>
 
 <xsl:template match="ilustr" mode="inline">
 </xsl:template>
 
 <xsl:template match="ilustr">
+  <div>
+    <xsl:call-template name="block-args" />
+
+    <xsl:attribute name="class">
+      <xsl:text>ilustr </xsl:text>
+      <xsl:value-of select="@wyrownanie"/>
+      <xsl:if test="@oblew">
+        <xsl:text> oblew</xsl:text>
+      </xsl:if>
+    </xsl:attribute>
+    
     <img>
-        <xsl:attribute name="src">
-            <xsl:value-of select="$gallery" /><xsl:value-of select="@src" />
-        </xsl:attribute>
-        <xsl:attribute name="alt">
-            <xsl:value-of select="@alt" />
-        </xsl:attribute>
-        <xsl:attribute name="title">
-            <xsl:value-of select="@alt" />
+      <xsl:attribute name="src">
+        <xsl:value-of select="@src" />
+      </xsl:attribute>
+      <xsl:attribute name="srcset">
+        <xsl:value-of select="@srcset" />
+      </xsl:attribute>
+      <xsl:attribute name="sizes">
+        (min-width: 718px) 600px,
+        (min-width: 600px) calc(100vw - 118px),
+        (min-width: 320px) calc(100vw - 75px),
+        (min-width: 15em) calc(100wv - 60px),
+        calc(100wv - 40px)
+      </xsl:attribute>
+      <xsl:attribute name="alt">
+        <xsl:value-of select="@alt" />
+      </xsl:attribute>
+      <xsl:attribute name="title">
+        <xsl:value-of select="@alt" />
+      </xsl:attribute>
+
+      <xsl:if test="@szer">
+        <xsl:attribute name="style">
+          <xsl:text>width: </xsl:text>
+          <xsl:value-of select="@szer"/>
         </xsl:attribute>
+      </xsl:if>
     </img>
+
+    <div class="stop"></div>
+  </div>
 </xsl:template>
 
 <xsl:template match="animacja">
   <div class="animacja cycle-slideshow" data-cycle-pause-on-hover="true" data-cycle-next="> img" data-cycle-fx="fadeout" data-cycle-paused="true">
+    <xsl:call-template name="block-args" />
     <xsl:apply-templates/>
   </div>
 </xsl:template>
 <!-- ========================================== -->
 <!-- Title page -->
 <xsl:template match="autor_utworu" mode="header">
-    <span class="author"><xsl:apply-templates mode="inline" /></span>
+  <span class="author">
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </span>
 </xsl:template>
 
 <xsl:template match="nazwa_utworu" mode="header">
-    <span class="title"><xsl:apply-templates mode="inline" /></span>
+  <span class="title">
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </span>
 </xsl:template>
 
 <xsl:template match="dzielo_nadrzedne" mode="header">
-    <span class="collection"><xsl:apply-templates mode="inline" /></span>
+  <span class="collection">
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </span>
 </xsl:template>
 
 <xsl:template match="podtytul" mode="header">
-    <span class="subtitle"><xsl:apply-templates mode="inline" /></span>
+  <span class="subtitle">
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </span>
 </xsl:template>
 
 <!-- Section headers (included in index)-->
 <xsl:template match="naglowek_akt|naglowek_czesc|srodtytul">
   <xsl:call-template name="section-anchor"/>
-    <h2><xsl:apply-templates mode="inline" /></h2>
+  <h2>
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </h2>
 </xsl:template>
 
 <xsl:template match="podtytul_akt|podtytul_czesc">
   <div class="subtitle2">
+    <xsl:call-template name="block-args" />
     <xsl:apply-templates mode="inline" />
   </div>
 </xsl:template>
 
 <xsl:template match="naglowek_scena|naglowek_rozdzial">
     <xsl:call-template name="section-anchor"/>
-    <h3><xsl:apply-templates mode="inline" /></h3>
+    <h3>
+      <xsl:call-template name="block-args" />
+      <xsl:apply-templates mode="inline" />
+    </h3>
 </xsl:template>
 
 <xsl:template match="podtytul_scena|podtytul_rozdzial">
   <div class="subtitle3">
+    <xsl:call-template name="block-args" />
     <xsl:apply-templates mode="inline" />
   </div>
 </xsl:template>
 
 <xsl:template match="naglowek_osoba|naglowek_podrozdzial">
-      <xsl:call-template name="section-anchor"/>
-    <h4><xsl:apply-templates mode="inline" /></h4>
+  <xsl:call-template name="section-anchor"/>
+  <h4>
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </h4>
 </xsl:template>
 
 <xsl:template match="podtytul_podrozdzial">
   <div class="subtitle4">
+    <xsl:call-template name="block-args" />
     <xsl:apply-templates mode="inline" />
   </div>
 </xsl:template>
 
 <!-- Other paragraph tags -->
 <xsl:template match="miejsce_czas">
-      <xsl:call-template name="section-anchor"/>
-    <p class="place-and-time"><xsl:apply-templates mode="inline" /></p>
+  <xsl:call-template name="section-anchor"/>
+  <p class="place-and-time">
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </p>
 </xsl:template>
 
 <xsl:template match="didaskalia">
-      <xsl:call-template name="section-anchor"/>
-    <div class="didaskalia"><xsl:apply-templates mode="inline" /></div>
+  <xsl:call-template name="section-anchor"/>
+  <div class="didaskalia">
+    <xsl:call-template name="block-args" />
+    <xsl:apply-templates mode="inline" />
+  </div>
 </xsl:template>
 
 <xsl:template match="lista_osoba">
 
 <xsl:template match="akap|akap_dialog|akap_cd">
     <p class="paragraph">
+      <xsl:call-template name="block-args" />
       <xsl:call-template name="section-anchor"/>
        <xsl:apply-templates mode="inline" />
     </p>
 </xsl:template>
 
 <xsl:template match="strofa">
-    <div class="stanza">
+  <div class="stanza">
+    <xsl:call-template name="block-args" />
       <xsl:call-template name="section-anchor"/>
         <xsl:choose>
             <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:template match="motto_podpis">
     <xsl:call-template name="section-anchor"/>
-    <p class="motto_podpis"><xsl:apply-templates mode="inline" /></p>
+    <p class="motto_podpis">
+      <xsl:call-template name="block-args" />
+      <xsl:apply-templates mode="inline" />
+    </p>
 </xsl:template>
 
 <xsl:template match="tabela|tabelka">
     <xsl:call-template name="section-anchor"/>
     <xsl:choose>
         <xsl:when test="@ramka = '1'">
-            <table class="border"><xsl:apply-templates /></table>
+          <table class="border">
+            <xsl:call-template name="block-args" />
+            <xsl:apply-templates />
+          </table>
         </xsl:when>
         <xsl:otherwise>
-            <table><xsl:apply-templates /></table>
+          <table>
+            <xsl:call-template name="block-args" />
+            <xsl:apply-templates />
+          </table>
         </xsl:otherwise>
     </xsl:choose>
 </xsl:template>
     <a href="{concat('#footnote-', generate-id(.))}" class="annotation">[<xsl:number value="count(preceding::*[self::pa or self::pe or self::pr or self::pt]) + 1" />]</a>
 </xsl:template>
 
+<xsl:template match="ref" mode="inline">
+  <a class="reference" data-uri="">
+    <xsl:attribute name="data-uri">
+      <xsl:value-of select="@href"/>
+    </xsl:attribute>
+  </a>
+</xsl:template>
+
 <!-- Other inline tags -->
 <xsl:template match="mat" mode="inline">
-    <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*" /></math>
+    <math xmlns="http://www.w3.org/1998/Math/MathML"><xsl:copy-of select="*|text()" /></math>
 </xsl:template>
 
 <xsl:template match="didask_tekst" mode="inline">
     <em class="person"><xsl:apply-templates mode="inline" /></em>
 </xsl:template>
 
+<xsl:template match="www" mode="inline">
+    <a target="_blank">
+        <xsl:attribute name="href">
+            <xsl:value-of select="text()"/>
+        </xsl:attribute>
+        <xsl:apply-templates mode="inline" />
+    </a>
+</xsl:template>
 
 <!-- ============================================== -->
 <!-- = STANDALONE TAGS                            = -->
     <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 = -->
         <a name="{concat('sec', count(ancestor-or-self::*[last()-2]/preceding-sibling::*) + 1)}" />
 </xsl:template>
 
+<xsl:template name="block-args">
+  <xsl:if test="@id">
+    <xsl:attribute name="id">
+      <xsl:text>wl-</xsl:text>
+      <xsl:value-of select="@id"/>
+    </xsl:attribute>
+  </xsl:if>
+</xsl:template>
+
+<xsl:template match="numeracja">
+       <span class="numeracja">
+               <xsl:attribute name="data-start">
+                       <xsl:value-of select="@start" />
+               </xsl:attribute>
+       </span>
+</xsl:template>
+
 </xsl:stylesheet>