]> git.draconx.ca Git - homepage.git/commitdiff
Tweak whitespace-preserving templates.
authorNick Bowler <nbowler@draconx.ca>
Thu, 10 Jan 2019 03:28:53 +0000 (22:28 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 10 Jan 2019 03:28:53 +0000 (22:28 -0500)
We don't want to add whitespace to span-level elements which were
empty to start with, which is normal for e.g. img elements.

Also, if an element contains _only_ whitespace, it was probably put
there on purpose so let's preserve it.

layouts/default.xsl

index 5a01d79cfcf870176fbc94052b4fa7c1765f3a73..bfe9101a6bb4c55444dd5171d5b39366f566220a 100644 (file)
   <xsl:call-template name='glue-preceding-span' />
   <xsl:copy>
     <xsl:apply-templates select='node()|@*' />
-    <xsl:text>&#x2060;</xsl:text> <!-- avoid breaking within a span element -->
+    <xsl:if test='*'>
+      <!-- avoid breaking within a span element -->
+      <xsl:text>&#x2060;</xsl:text>
+    </xsl:if>
   </xsl:copy>
 </xsl:template>
 
     </xsl:when>
     <!-- preserve anything under <pre> -->
     <xsl:when test='ancestor::xhtml:pre'><xsl:copy /></xsl:when>
+    <!-- preserve whitespace which is the only child node of an element -->
+    <xsl:when test='count(../node()) = 1'><xsl:copy /></xsl:when>
   </xsl:choose>
 </xsl:template>