[gnome-doc-utils/mallard: 59/87] Fixing newline stripping



commit c32da3bed14f8fe6c9dfc3131e8b53990c17d17e
Author: Shaun McCance <shaunm gnome org>
Date:   Tue Dec 2 09:16:39 2008 -0600

    Fixing newline stripping
---
 xslt/mallard/html/mal2html-block.xsl |    6 ++--
 xslt/mallard/html/util.xsl           |   38 ++++-----------------------------
 2 files changed, 8 insertions(+), 36 deletions(-)

diff --git a/xslt/mallard/html/mal2html-block.xsl b/xslt/mallard/html/mal2html-block.xsl
index d79c74d..34166ec 100644
--- a/xslt/mallard/html/mal2html-block.xsl
+++ b/xslt/mallard/html/mal2html-block.xsl
@@ -166,12 +166,12 @@ div.title {
       <xsl:call-template name="util.strip_newlines">
         <xsl:with-param name="string" select="$first"/>
         <xsl:with-param name="leading" select="true()"/>
-        <xsl:with-param name="trailing" select="$first = $last"/>
+        <xsl:with-param name="trailing" select="count(node()) = 1"/>
       </xsl:call-template>
     </xsl:if>
     <xsl:apply-templates mode="mal2html.inline.mode"
-                         select="node()[not(. = $first or . = $last)]"/>
-    <xsl:if test="$last and ($first != $last)">
+                         select="node()[not(self::text() and (position() = 1 or position() = last()))]"/>
+    <xsl:if test="$last and (count(node()) != 1)">
       <xsl:call-template name="util.strip_newlines">
         <xsl:with-param name="string" select="$last"/>
         <xsl:with-param name="leading" select="false()"/>
diff --git a/xslt/mallard/html/util.xsl b/xslt/mallard/html/util.xsl
index c71b5b7..2816d06 100644
--- a/xslt/mallard/html/util.xsl
+++ b/xslt/mallard/html/util.xsl
@@ -33,11 +33,9 @@ $string: The string to strip newlines from
 $leading: Whether to strip leading newlines
 $trailing: Whether to strip trailing newlines
 
-This template strips at most one leading and one trailing newline from ${string}.
-The newline may come in four different forms: U+000D U+000A (CR LF), U+000D (CR),
-U+000A (LF), and U+0085 (NEL).  This is useful for preformatted block elements
-where leading and trailing newlines are ignored to make source formatting easier
-for authors.
+This template strips at most one leading and one trailing newline from
+${string}.  This is useful for preformatted block elements where leading and
+trailing newlines are ignored to make source formatting easier for authors.
 -->
 <xsl:template name="util.strip_newlines">
   <xsl:param name="string"/>
@@ -47,21 +45,8 @@ for authors.
     <xsl:when test="$leading">
       <xsl:variable name="new">
         <xsl:choose>
-          <!-- CR LF -->
-          <xsl:when test="starts-with($string, '&#x000D;&#x000A;')">
-            <xsl:value-of select="substring-after($string, '&#x000D;&#x000A;')"/>
-          </xsl:when>
-          <!-- CR -->
-          <xsl:when test="starts-with($string, '&#x000D;')">
-            <xsl:value-of select="substring-after($string, '&#x000D;')"/>
-          </xsl:when>
-          <!-- LF -->
           <xsl:when test="starts-with($string, '&#x000A;')">
-            <xsl:value-of select="substring-after($string, '&#x000A;')"/>
-          </xsl:when>
-          <!-- NEL -->
-          <xsl:when test="starts-with($string, '&#x0085;')">
-            <xsl:value-of select="substring-after($string, '&#x0085;')"/>
+            <xsl:value-of select="substring($string, 2)"/>
           </xsl:when>
           <xsl:otherwise>
             <xsl:value-of select="$string"/>
@@ -83,20 +68,7 @@ for authors.
     </xsl:when>
     <xsl:when test="$trailing">
       <xsl:choose>
-        <!-- CR LF -->
-        <xsl:when test="substring($string, -2) = '&#x000D;&#x000A;'">
-          <xsl:value-of select="substring($string, 1, string-length($string) - 2 )"/>
-        </xsl:when>
-        <!-- CR -->
-        <xsl:when test="substring($string, -1) = '&#x000D;'">
-          <xsl:value-of select="substring($string, 1, string-length($string) - 1 )"/>
-        </xsl:when>
-        <!-- LF -->
-        <xsl:when test="substring($string, -1) = '&#x000A;'">
-          <xsl:value-of select="substring($string, 1, string-length($string) - 1 )"/>
-        </xsl:when>
-        <!-- NEL -->
-        <xsl:when test="substring($string, -1) = '&#x0085;'">
+        <xsl:when test="substring($string, string-length($string)) = '&#x000A;'">
           <xsl:value-of select="substring($string, 1, string-length($string) - 1 )"/>
         </xsl:when>
         <xsl:otherwise>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]