]> granicus.if.org Git - docbook-dsssl/commitdiff
Verbatim environment "Grand Unification" fix.
authorMichael Smith <xmldoc@users.sourceforge.net>
Fri, 20 May 2005 09:08:59 +0000 (09:08 +0000)
committerMichael Smith <xmldoc@users.sourceforge.net>
Fri, 20 May 2005 09:08:59 +0000 (09:08 +0000)
Attempte to fix handling of verbatim environments (literallayout,
programlisting, screen) and, in a related way, text nodes.
Particularly in mixed-content blocks. I think I got it working...

Closes #1167995, #975243, #935833, #763861, #728932, #628393, #595213.

Thanks to Hendrik Sattler, Tobias Reif, Tommi Virtanen, Dennis
Grace, and Matthias Andree for reporting the problems.

Sorry it took so long for the fix.

xsl/manpages/docbook.xsl
xsl/manpages/lists.xsl
xsl/manpages/synop.xsl

index 5f9988979cd03f354d5cd7b5e2e5e89f694c8249..43e81c470f7e4c0455a0549b3dc3b95b6ccd9351 100644 (file)
   <xsl:apply-templates/>
 </xsl:template>
 
-<xsl:template match="para">
-  <xsl:text>.PP&#10;</xsl:text>
+<xsl:template name="mixed-block">
+  <!-- jump through a few hoops to deal with mixed-content blocks, so that -->
+  <!-- we don't end up munging verbatim environments or lists and so that we -->
+  <!-- don't gobble up whitespace when we shouldn't -->
   <xsl:for-each select="node()">
     <xsl:choose>
-      <xsl:when test="self::literallayout|self::informaltable|self::screen|
-                     self::programlisting|self::itemizedlist|
-                     self::orderedlist|self::variablelist|self::simplelist">
-        <xsl:text>&#10;</xsl:text>
+      <xsl:when test="self::address|self::literallayout|self::programlisting|
+                     self::screen|self::synopsis">
+       <!-- Check to see if this node is a verbatim environment. -->
+       <!-- If so, put line breaks before and after it. -->
+       
+       <!-- Yes, address and synopsis are vertabim environments. -->
+       
+       <!-- The code here previously also treated informaltable as a -->
+       <!-- verbatim, presumably to support some kludge; I removed it -->
+       <xsl:text> &#10;</xsl:text>
         <xsl:apply-templates select="."/>
+       <!-- we don't need an extra line break after verbatim environments
+        <xsl:text> &#10;</xsl:text>
+       -->
+      </xsl:when>
+      <xsl:when test="self::itemizedlist|self::orderedlist|
+                     self::variablelist|self::simplelist">
+       <!-- Check to see if this node is a list; if so, -->
+       <!-- put line breaks before and after it. -->
+        <xsl:text> &#10;</xsl:text>
+        <xsl:apply-templates select="."/>
+       <!-- we don't need an extra line break after lists
+        <xsl:text> &#10;</xsl:text>
+       -->
       </xsl:when>
       <xsl:when test="self::text()">
-       <xsl:if test="starts-with(translate(.,'&#10;',' '), ' ') and
-                     preceding-sibling::node()[name(.)!='']">
-         <xsl:text> </xsl:text>
+       <!-- Check to see if this is a text node. -->
+       
+       <!-- If so, take any multiple whitespace at the beginning or end of -->
+       <!-- it, and replace it with a space plus a linebreak. -->
+       
+       <!-- This hack results in some ugliness in the generated roff -->
+       <!-- source. But it ensures the whitespace around text nodes in mixed -->
+       <!-- content gets preserved; without the hack, that whitespace -->
+       <!-- effectively gets gobbled. -->
+       <xsl:if test="starts-with(translate(.,'&#9;&#10;&#13; ','    '),
+                     ' ') and preceding-sibling::node()[name(.)!='']">
+         <xsl:text> &#10;</xsl:text>
        </xsl:if>
         <xsl:variable name="content">
          <xsl:apply-templates select="."/>
        </xsl:variable>
        <xsl:value-of select="normalize-space($content)"/>
        <xsl:if
-        test="translate(substring(., string-length(.), 1),'&#10;',' ') = ' ' and
-              following-sibling::node()[name(.)!='']">
-         <xsl:text> </xsl:text>
+           test="translate(substring(., string-length(.), 1),'&#x9;&#10;&#13; ','    ')
+                 = ' ' and following-sibling::node()[name(.)!='']">
+         <xsl:text> &#10;</xsl:text>
        </xsl:if>
       </xsl:when>
       <xsl:otherwise>
-        <xsl:variable name="content">
+       <!-- At this point, we know that this node is not a verbatim -->
+       <!-- environment, list, or text node; so we can safely -->
+       <!-- normailize-space() it. -->
+       <xsl:variable name="content">
           <xsl:apply-templates select="."/>
         </xsl:variable>
         <xsl:value-of select="normalize-space($content)"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:for-each>
+</xsl:template>
+
+<xsl:template match="para">
+  <xsl:text>.PP&#10;</xsl:text>
+  <xsl:call-template name="mixed-block"/>
   <xsl:text>&#10;</xsl:text>
 </xsl:template>
 
     <xsl:apply-templates/>
   </xsl:variable>
   <xsl:value-of select="normalize-space($content)"/>
-  <xsl:text>
-</xsl:text>
+  <xsl:text>&#10;</xsl:text>
 </xsl:template>
-
   
 <xsl:template match="refentry">
 
   <xsl:text>''</xsl:text>
 </xsl:template>
 
-<xsl:template match="programlisting|literallayout">
+<xsl:template match="address|literallayout|programlisting|screen|synopsis">
+  <!-- Yes, address and synopsis are verbatim environments. -->
+
+  <xsl:choose>
+    <!-- Check to see if this vertbatim item is within a parent element that -->
+    <!-- allows mixed content. -->
+    
+    <!-- If it is within a mixed-content parent, then a line break is -->
+    <!-- already added before it by the mixed-block template, so we don't -->
+    <!-- need to add one here. -->
+    
+    <!-- If it is not within a mixed-content parent, then we need to add a -->
+    <!-- line break before it. -->
+    <xsl:when test="parent::caption|parent::entry|parent::para|
+                   parent::td|parent::th" /> <!-- do nothing -->
+    <xsl:otherwise>
+      <xsl:text>&#10;</xsl:text>
+    </xsl:otherwise>
+  </xsl:choose>
   <xsl:text>.nf&#10;</xsl:text>
   <xsl:apply-templates/>
+  <xsl:text>&#10;</xsl:text>
   <xsl:text>.fi&#10;</xsl:text>
 </xsl:template>
 
index 249e9c940fdbb2e16e62d9f209f99f7991c4dfb4..694a5f3e48c002b525a54cb4a0119297628adf63 100644 (file)
@@ -6,37 +6,7 @@
 <xsl:template match="para[ancestor::listitem or ancestor::step]|
                     simpara[ancestor::listitem or ancestor::step]|
                     remark[ancestor::listitem or ancestor::step]">
-  <xsl:for-each select="node()">
-    <xsl:choose>
-      <xsl:when test="self::literallayout|self::screen|self::programlisting|
-                     self::itemizedlist|self::orderedlist|self::variablelist|
-                     self::simplelist">
-        <xsl:text>&#10;</xsl:text>
-        <xsl:apply-templates select="."/>
-      </xsl:when>
-      <xsl:when test="self::text()">
-       <xsl:if test="starts-with(translate(.,'&#10;',' '), ' ') and
-                     preceding-sibling::node()[name(.)!='']">
-         <xsl:text> </xsl:text>
-       </xsl:if>
-        <xsl:variable name="content">
-         <xsl:apply-templates select="."/>
-       </xsl:variable>
-       <xsl:value-of select="normalize-space($content)"/>
-       <xsl:if
-        test="translate(substring(., string-length(.), 1),'&#10;',' ') = ' '
-             and following-sibling::node()[name(.)!='']">
-         <xsl:text> </xsl:text>
-       </xsl:if>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:variable name="content">
-          <xsl:apply-templates select="."/>
-        </xsl:variable>
-        <xsl:value-of select="normalize-space($content)"/>
-      </xsl:otherwise>
-    </xsl:choose>
-  </xsl:for-each>
+  <xsl:call-template name="mixed-block"/>
   <xsl:text>&#10;</xsl:text>
 
   <xsl:if test="following-sibling::para or
   </xsl:if>
 </xsl:template>
 
+<xsl:template match="simpara[ancestor::listitem or ancestor::step]|
+                    remark[ancestor::listitem or ancestor::step]">
+  <xsl:variable name="content">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:value-of select="normalize-space($content)"/>
+  <xsl:text>&#10;</xsl:text>
+  <xsl:if test="following-sibling::para or
+               following-sibling::simpara or
+               following-sibling::remark">
+    <!-- Make sure multiple paragraphs within a list item don't -->
+    <!-- merge together.                                        -->
+    <xsl:text>&#10;</xsl:text>
+  </xsl:if>
+</xsl:template>
+
 <xsl:template match="varlistentry|glossentry">
   <xsl:text>.TP&#10;</xsl:text>
   <xsl:apply-templates/>
index 940b73c1eea92dfc2149e860b6391409fd623d93..4910f7a3e50fc462c58be98fd82af9b205402c4c 100644 (file)
@@ -1,14 +1,16 @@
 <?xml version='1.0'?>
-<!-- vim:set sts=2 shiftwidth=2 syntax=sgml: -->
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                 version='1.0'>
 
+  <!-- the synopsis element is a verbatim environment; you won't find any -->
+  <!-- code for handling it here -->
+
 <xsl:template match="synopfragment">
 <xsl:text>.PP&#10;</xsl:text>
 <xsl:apply-templates/>
 </xsl:template>
 <!--
-  there's a bug were an <arg> that's not inside a <group> isn't made bold
+  there's a bug where an <arg> that's not inside a <group> isn't made bold
 -->
 
 <xsl:template match="group|arg">
   <xsl:text>.ad&#10;.hy&#10;</xsl:text>
 </xsl:template>
 
-<xsl:template match="synopsis">
-  <xsl:text>.nf&#10;</xsl:text>
-  <xsl:apply-templates/>
-  <xsl:text>.fi&#10;</xsl:text>
-</xsl:template>
-
 <xsl:template match="void">
   <xsl:text>void</xsl:text>
 </xsl:template>