<!--
Nick's web site: XHTML output stage
- Copyright © 2018-2020 Nick Bowler
+ Copyright © 2018-2021 Nick Bowler
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
xmlns:xhtml='http://www.w3.org/1999/xhtml'
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
xmlns:func='http://exslt.org/functions'
+ xmlns:exslt='http://exslt.org/common'
xmlns:f='http://draconx.ca/my-functions'
- extension-element-prefixes='func f'
+ extension-element-prefixes='exslt func f'
exclude-result-prefixes='xhtml'>
<xsl:import href='layouts/functions.xsl' />
-
-<xsl:output method='xml' encoding='UTF-8' indent='yes'
- doctype-public='-//W3C//DTD XHTML 1.1//EN'
- doctype-system='http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd'
- cdata-section-elements='style script' />
+<xsl:output cdata-section-elements='style script' />
<xsl:param name='source-uri'
select='"//git.draconx.ca/gitweb/homepage.git/"' />
<xsl:copy><xsl:apply-templates select='node()|@*' /></xsl:copy>
</xsl:template>
+<xsl:template name='notransform' mode='notransform' match='node()|@*'>
+ <xsl:copy>
+ <xsl:apply-templates mode='notransform' select='node()|@*' />
+ </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-
<pre>⁠<code><xsl:value-of select='f:strip-leading(.)' /></code></pre>
</xsl:template>
+<!--
+ Attempt to wrap the first bit of linked email addresses to allow
+ linewrapping to occur after the '@'.
+-->
+<xsl:template match='xhtml:a[starts-with(@href,"mailto:")]/text()'>
+ <xsl:variable name='addr' select='substring-after(../@href, "mailto:")' />
+
+ <xsl:variable name='wrap'
+ select='concat(substring-before($addr, "@"), "@")' />
+
+ <xsl:choose>
+ <xsl:when test='contains(., $wrap)'>
+ <xsl:value-of select='substring-before(., $wrap)' />
+ <span class='wbr'>
+ <xsl:value-of select='$wrap' />
+ </span>
+ <xsl:value-of select='substring-after(., $wrap)' />
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:copy />
+ </xsl:otherwise>
+ </xsl:choose>
+</xsl:template>
+
<!--
Add a simple way to reference a document node by ID and include the XHTML
code listing directly in the document.
</code></pre>
</xsl:template>
+<!-- For paragraphs containing only kbd elements, wrap in blockquote. -->
+<xsl:template match='xhtml:p[*[last()=count(../xhtml:kbd)]]'>
+ <blockquote>
+ <xsl:copy>
+ <xsl:apply-templates select='node()|@*' />
+ </xsl:copy>
+ </blockquote>
+</xsl:template>
+
+<!--
+ Wrap each word of text in kbd elements in spans, so they can be styled
+ to avoid linebreaks in the middle of option names and other bad places.
+-->
+<xsl:template name='spanify-text' match='xhtml:kbd/text()'>
+ <xsl:param name='text' select='normalize-space(.)' />
+ <xsl:variable name='firstword' select='substring-before($text, " ")' />
+ <xsl:choose>
+ <xsl:when test='$firstword'>
+ <span><xsl:value-of select='$firstword' /></span>
+ <xsl:text> </xsl:text>
+ </xsl:when>
+ <xsl:when test='$text'>
+ <span><xsl:value-of select='$text' /></span>
+ </xsl:when>
+ </xsl:choose>
+ <xsl:if test='$firstword'>
+ <xsl:call-template name='spanify-text'>
+ <xsl:with-param name='text' select='substring-after($text, " ")' />
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
+
<xsl:template match='copyright'>
<p>
<xsl:text>Copyright © </xsl:text>
</xsl:template>
<xsl:template match='license'>
+ <xsl:variable name='node' select='.' />
<p>
- <xsl:text>Copying and distribution of this material</xsl:text>
+ <xsl:choose>
+ <xsl:when test='/document/image[license != $node]'>
+ <xsl:text>Except as otherwise noted, copying</xsl:text>
+ </xsl:when>
+ <xsl:otherwise>Copying</xsl:otherwise>
+ </xsl:choose>
+ <xsl:text> and distribution of this material</xsl:text>
<xsl:if test='normalize-space(modification-allowed)="yes"'>
<xsl:text>, with or without modification,</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name='image-attribution'>
-<!--
- <xsl:variable name='x' select='/document/image[copyright-holder="Nick Bowler"][1]' />
- <xsl:variable name='y' select='/document/image[copyright-holder="Nick Bowler"][4]' />
--->
<xsl:variable name='images-fragment'>
<xsl:for-each select='/document/image'>
<xsl:sort select='number(copyright-holder = /document/copyright-holder)'
</xsl:if>
</xsl:template>
+<xsl:template match='xhtml:p[count(*)=1 and normalize-space(text())=""
+ and descendant::xhtml:img]'>
+ <xsl:copy>
+ <xsl:apply-templates select='@*[local-name() != "class"]' />
+ <xsl:attribute name='class'>
+ <xsl:if test='@class'>
+ <xsl:value-of select='concat(@class, " ")' />
+ </xsl:if>
+ <xsl:text>img</xsl:text>
+ </xsl:attribute>
+ <xsl:apply-templates select='node()' />
+ </xsl:copy>
+</xsl:template>
+
<xsl:template match='/'>
<html>
<head>
<div id='footer'>
<xsl:apply-templates select='/document/copyright' />
<xsl:apply-templates select='/document/license' />
+ <xsl:if test='/document/image'>
+ <xsl:call-template name='image-attribution' />
+ </xsl:if>
<xsl:apply-templates select='/document/source' />
</div>
</body>
</html>
</xsl:template>
+<xsl:include href='layouts/clickytable.xsl' />
+
</xsl:stylesheet>