[yelp-xsl] Added support for line numbering in Mallard code blocks
- From: Shaun McCance <shaunm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [yelp-xsl] Added support for line numbering in Mallard code blocks
- Date: Fri, 3 Dec 2010 16:56:54 +0000 (UTC)
commit 0da30ce50a6b5019cbec481dc570656193345cde
Author: Shaun McCance <shaunm gnome org>
Date: Fri Dec 3 11:56:25 2010 -0500
Added support for line numbering in Mallard code blocks
xslt/common/html.xsl | 2 +-
xslt/common/utils.xsl | 42 ++++++++++++++++++++++++++++++++++
xslt/docbook/common/db-common.xsl | 42 ----------------------------------
xslt/docbook/html/db2html-block.xsl | 4 +-
xslt/mallard/html/mal2html-block.xsl | 6 +++++
5 files changed, 51 insertions(+), 45 deletions(-)
---
diff --git a/xslt/common/html.xsl b/xslt/common/html.xsl
index 6199c6e..a31ff79 100644
--- a/xslt/common/html.xsl
+++ b/xslt/common/html.xsl
@@ -636,7 +636,7 @@ div.sectionlinks div.sectionlinks {
div.sectionlinks div.sectionlinks li {
padding-</xsl:text><xsl:value-of select="$left"/><xsl:text>: 1.44em;
}
-pre.linenumbering {
+pre.numbered {
margin: 0;
padding: 0.5em;
float: </xsl:text><xsl:value-of select="$left"/><xsl:text>;
diff --git a/xslt/common/utils.xsl b/xslt/common/utils.xsl
index 03c5d8b..8e8e61f 100644
--- a/xslt/common/utils.xsl
+++ b/xslt/common/utils.xsl
@@ -83,4 +83,46 @@ trailing newlines are ignored to make source formatting easier for authors.
</xsl:choose>
</xsl:template>
+<!--**==========================================================================
+utils.linenumbering
+Number each line in a verbatim environment.
+:Revision:version="1.0" date="2010-12-03" status="final"
+$node: The verbatim element to create the line numbering for.
+$number: The starting line number.
+
+This template outputs a string with line numbers for each line in a verbatim
+elements. Each line number is on its own line, allowing the output string to
+be placed to the side of the verbatim output.
+-->
+<xsl:template name="utils.linenumbering">
+ <xsl:param name="node" select="."/>
+ <xsl:param name="number" select="1"/>
+ <xsl:param name="string">
+ <xsl:choose>
+ <xsl:when test="$node/node()[1]/self::text() and starts-with($node/node()[1], '
')">
+ <xsl:value-of select="substring-after(string($node), '
')"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="string($node)"/>
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:param>
+ <xsl:choose>
+ <xsl:when test="contains($string, '
')">
+ <xsl:number value="$number"/>
+ <xsl:text>
</xsl:text>
+ <xsl:call-template name="utils.linenumbering">
+ <xsl:with-param name="node" select="$node"/>
+ <xsl:with-param name="number" select="$number + 1"/>
+ <xsl:with-param name="string"
+ select="substring-after($string, '
')"/>
+ </xsl:call-template>
+ </xsl:when>
+ <xsl:when test="string-length($string) != 0">
+ <xsl:number value="$number"/>
+ <xsl:text>
</xsl:text>
+ </xsl:when>
+ </xsl:choose>
+</xsl:template>
+
</xsl:stylesheet>
diff --git a/xslt/docbook/common/db-common.xsl b/xslt/docbook/common/db-common.xsl
index 9348fb1..b81721c 100644
--- a/xslt/docbook/common/db-common.xsl
+++ b/xslt/docbook/common/db-common.xsl
@@ -68,48 +68,6 @@ notice, beginning with the copyright symbol "©".
<!--**==========================================================================
-db.linenumbering
-Numbers each line in a verbatim environment
-$node: The verbatim element to create the line numbering for
-$number: The starting line number
-
-This template outputs a string with line numbers for each line in a verbatim
-elements. Each line number is on its own line, allowing the output string to
-be placed to the side of the verbatim output.
--->
-<xsl:template name="db.linenumbering">
- <xsl:param name="node" select="."/>
- <xsl:param name="number" select="1"/>
- <xsl:param name="string">
- <xsl:choose>
- <xsl:when test="$node/node()[1]/self::text() and starts-with($node/node()[1], '
')">
- <xsl:value-of select="substring-after(string($node), '
')"/>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="string($node)"/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:param>
- <xsl:choose>
- <xsl:when test="contains($string, '
')">
- <xsl:number value="$number"/>
- <xsl:text>
</xsl:text>
- <xsl:call-template name="db.linenumbering">
- <xsl:with-param name="node" select="$node"/>
- <xsl:with-param name="number" select="$number + 1"/>
- <xsl:with-param name="string"
- select="substring-after($string, '
')"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="string-length($string) != 0">
- <xsl:number value="$number"/>
- <xsl:text>
</xsl:text>
- </xsl:when>
- </xsl:choose>
-</xsl:template>
-
-
-<!--**==========================================================================
db.linenumbering.start
Determines the starting line number for a verbatim element
$node: The verbatim element to determine the starting line number for
diff --git a/xslt/docbook/html/db2html-block.xsl b/xslt/docbook/html/db2html-block.xsl
index af317af..4253738 100644
--- a/xslt/docbook/html/db2html-block.xsl
+++ b/xslt/docbook/html/db2html-block.xsl
@@ -285,7 +285,7 @@ This template uses the parameters to construct the #{class} attribute, which
is then used by the CSS for styling.
If ${node} has the #{linenumbering} attribute set to #{"numbered"}, then this
-template will create line numbers for each line, using the *{db.linenumbering}
+template will create line numbers for each line, using the *{utils.linenumbering}
template.
-->
<xsl:template name="db2html.pre">
@@ -336,7 +336,7 @@ template.
<xsl:otherwise>1</xsl:otherwise>
</xsl:choose>
</xsl:variable>
- <pre class="linenumbering"><xsl:call-template name="db.linenumbering">
+ <pre class="numbered"><xsl:call-template name="utils.linenumbering">
<xsl:with-param name="node" select="$node"/>
<xsl:with-param name="number" select="$number"/>
</xsl:call-template></pre>
diff --git a/xslt/mallard/html/mal2html-block.xsl b/xslt/mallard/html/mal2html-block.xsl
index d46bb61..e32ecdd 100644
--- a/xslt/mallard/html/mal2html-block.xsl
+++ b/xslt/mallard/html/mal2html-block.xsl
@@ -45,6 +45,7 @@ automatically strip leading and trailing newlines using *{utils.strip_newlines}.
-->
<xsl:template name="mal2html.pre">
<xsl:param name="node" select="."/>
+ <xsl:param name="numbered" select="contains(concat(' ', @style, ' '), 'numbered')"/>
<xsl:variable name="first" select="$node/node()[1]/self::text()"/>
<xsl:variable name="last" select="$node/node()[last()]/self::text()"/>
<div>
@@ -52,6 +53,11 @@ automatically strip leading and trailing newlines using *{utils.strip_newlines}.
<xsl:attribute name="class">
<xsl:value-of select="local-name($node)"/>
</xsl:attribute>
+ <xsl:if test="$numbered">
+ <pre class="numbered"><xsl:call-template name="utils.linenumbering">
+ <xsl:with-param name="node" select="$node"/>
+ </xsl:call-template></pre>
+ </xsl:if>
<pre class="contents">
<xsl:if test="$first">
<xsl:call-template name="utils.strip_newlines">
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]