]> git.draconx.ca Git - homepage.git/blobdiff - layouts/default.xsl
cdecl99-1.3 bash-5 hotfix
[homepage.git] / layouts / default.xsl
index 768193376d53c73156211540a26460a28e9e9b7a..aa22e8f23460062220cba346f2b7468de96bf1ef 100644 (file)
 <xsl:param name='site-title' select='"The Citrine Citadel"' />
 <xsl:param name='section-links' select='//document/section-links' />
 
-<func:function name='f:ends-with'>
-  <xsl:param name='a' />
-  <xsl:param name='b' />
-  <func:result
-    select='substring($a, string-length($a)-string-length($b)+1)=$b' />
-</func:function>
-
 <xsl:template match='node()|@*'>
   <xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
 </xsl:template>
   </xsl:copy>
 </xsl:template>
 
-<!--
-  Nokogiri's pretty-printer is a bit weird.  Regardless of the indentation
-  setting, if an element has no child text nodes then it will be pretty-
-  printed.  This works by adding arbitrary whitespace to that element, and
-  then all of its children are eligible to be pretty-printed.
-
-  If an element has any text nodes at all, then it is not pretty-printed and
-  neither are any of its descendents.
-
-  Adding arbitrary whitespace to <pre> is bad, so we inject zero-width non-
-  breaking spaces to prevent this.  This will render fine but the spaces
-  should be removed before final output to avoid problems with copy+paste.
--->
-<xsl:template match='xhtml:pre'>
-  <xsl:copy>
-    <xsl:apply-templates select='node()|@*' />
-    <xsl:text>&#x2060;</xsl:text>
-  </xsl:copy>
-</xsl:template>
-
-<!--
-  Likewise, adding spaces between consecutive span-level elements where
-  none existed before won't go over well.
--->
-<xsl:template name='glue-preceding-span'>
-  <xsl:if test='f:element-is-span(preceding-sibling::node()[1])'>
-    <xsl:text>&#x2060;</xsl:text>
-  </xsl:if>
-</xsl:template>
-
-<xsl:template match='*[f:element-is-span()]'>
-  <xsl:call-template name='glue-preceding-span' />
-  <xsl:copy>
-    <xsl:apply-templates select='node()|@*' />
-    <xsl:if test='*'>
-      <!-- avoid breaking within a span element -->
-      <xsl:text>&#x2060;</xsl:text>
-    </xsl:if>
-  </xsl:copy>
-</xsl:template>
-
-<!--
-  Manually strip whitespace-only text nodes so the pretty printer can do its
-  thing on remaining elements.
--->
-<xsl:template match='text()[normalize-space(.) = ""]'>
-  <xsl:choose>
-    <!-- preserve anything according to xml:space -->
-    <xsl:when test='ancestor::*[@xml:space][1][@xml:space="preserve"]'>
-      <xsl:copy />
-    </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>
-    <!-- preserve whitespace between consecutive span-level elements
-         which have at least one non-whitespace sibling text element -->
-    <xsl:when test='f:element-is-span(preceding-sibling::node()[1])
-                    and f:element-is-span(following-sibling::node()[1])
-                    and ../text()[normalize-space(.) != ""]'>
-      <xsl:copy />
-    </xsl:when>
-  </xsl:choose>
-</xsl:template>
-
-<!-- Clean up whitespace where harmless to do so -->
-<xsl:template match='xhtml:p/node()[1][self::text()]'>
-  <xsl:value-of select='f:strip-leading()' />
-</xsl:template>
-<xsl:template match='xhtml:p/node()[position()=last()][self::text()]'>
-  <xsl:value-of select='f:strip-trailing()' />
-</xsl:template>
-
 <!-- Add rel attributes to external links -->
 <xsl:template match='xhtml:a[starts-with(@href,"http://")
                           or starts-with(@href,"https://")
   </xsl:copy>
 </xsl:template>
 
+<!--
+  Allow abbr to apply to document titles too, since these are generated
+  and kramdown's abbr support won't influence them. We do this by just
+  checking each word of the heading to see if is identical to an existing
+  abbr tag, and just substituting that in its place.
+  -->
+<xsl:key name='abbr' match='xhtml:abbr' use='string(.)' />
+<xsl:template name='insert-abbr' match='xhtml:h1/text()'>
+  <xsl:param name='string' select='normalize-space(.)' />
+
+  <xsl:variable name='head'
+    select='substring-before(concat($string, " "), " ")' />
+  <xsl:variable name='tail' select='substring-after($string, " ")' />
+  <xsl:variable name='match' select='key("abbr", $head)[1]' />
+
+  <xsl:choose>
+    <xsl:when test='$match'><xsl:apply-templates select='$match' /></xsl:when>
+    <xsl:otherwise><xsl:value-of select='$head' /></xsl:otherwise>
+  </xsl:choose>
+  <xsl:if test='$tail'>
+    <xsl:text> </xsl:text>
+    <xsl:call-template name='insert-abbr'>
+      <xsl:with-param name='string' select='$tail' />
+    </xsl:call-template>
+  </xsl:if>
+</xsl:template>
+
 <!--
   Convert caption attribute on tables into proper caption elements, to allow
   a simple way to add captions to kramdown tables.
     <xsl:text>Posted </xsl:text>
     <xsl:value-of select='/document/article/published' />
     <xsl:if test='/document/article/updated'>
-      <xsl:text>, last updated </xsl:text>
-      <xsl:value-of select='/document/article/updated' />
+      <xsl:if test='/document/article/updated != /document/article/published'>
+        <xsl:text>, last updated </xsl:text>
+        <xsl:value-of select='/document/article/updated' />
+      </xsl:if>
     </xsl:if>
   </p>
 </xsl:template>
   </html>
 </xsl:template>
 
+<xsl:include href='layouts/whitespace.xsl' />
 <xsl:include href='layouts/clickytable.xsl' />
 
 </xsl:stylesheet>