chiark / gitweb /
Add manpage XSL from git and enhance with literallayout fixes
authorJonas Fonseca <fonseca@diku.dk>
Thu, 31 May 2007 08:19:22 +0000 (10:19 +0200)
committerJonas Fonseca <fonseca@diku.dk>
Thu, 31 May 2007 08:19:22 +0000 (10:19 +0200)
It ensures that .sp tags will be properly output so they do not appear
in the rendered manpages. Grabed from git's Documentation/callouts.xsl
file. From the git's commit 7ef0435088f41165ece95b6f226d3c15438505a5:

    This is just a random hack to work around problems people seem
    to be seeing in manpage backend of xmlto (it appears we are
    getting ".sp" at the end of line without line break).

Additionally, output an empty line after literallayout blocks (.nf .fi)
so that any text following it will appear in a separate block.

Makefile
manpage.xsl [new file with mode: 0644]

index 06a5d6ae9eca55be2e0e585a152e6b1336f2b20e..f8e601d5322c9afac77e55f3787257b62caa22f0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -91,7 +91,7 @@ README.html: README
        asciidoc -b docbook -d manpage $<
 
 %.1 : %.1.xml
-       xmlto man $<
+       xmlto -m manpage.xsl man $<
 
 %.5.html : %.5.txt
        asciidoc -b xhtml11 -d manpage $<
@@ -100,7 +100,7 @@ README.html: README
        asciidoc -b docbook -d manpage $<
 
 %.5 : %.5.xml
-       xmlto man $<
+       xmlto -m manpage.xsl man $<
 
 %.html : %.txt
        asciidoc -b xhtml11 -d article -n $<
diff --git a/manpage.xsl b/manpage.xsl
new file mode 100644 (file)
index 0000000..b01a958
--- /dev/null
@@ -0,0 +1,55 @@
+<!-- manpage.xsl: various fixups to docbook -> manpage output
+  -
+  - For now converts it adds a newline after preformatted text enclosed
+  - in screen.
+  -
+  -->
+
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+<xsl:template match="screen">
+       <xsl:text>.sp&#10;.nf&#10;</xsl:text>
+       <xsl:apply-templates/>
+       <xsl:text>&#10;.fi&#10;.sp&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="simpara">
+  <xsl:variable name="content">
+    <xsl:apply-templates/>
+  </xsl:variable>
+  <xsl:value-of select="normalize-space($content)"/>
+  <xsl:text>&#10;</xsl:text>
+  <xsl:text>.sp&#10;</xsl:text>
+</xsl:template>
+
+<xsl:template match="address|literallayout|programlisting|screen|synopsis">
+  <!-- * Yes, address and synopsis are verbatim environments. -->
+
+  <xsl:choose>
+    <!-- * Check to see if this verbatim item is within a parent element that -->
+    <!-- * allows mixed content. -->
+    <!-- * -->
+    <!-- * If it is within a mixed-content parent, then a line space 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 space 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:text>.sp&#10;</xsl:text>
+    </xsl:otherwise>
+  </xsl:choose>
+  <xsl:text>.nf&#10;</xsl:text>
+  <xsl:apply-templates/>
+  <xsl:text>&#10;</xsl:text>
+  <xsl:text>&#10;&#10;.fi&#10;</xsl:text>
+  <!-- * if first following sibling node of this verbatim -->
+  <!-- * environment is a text node, output a line of space before it -->
+  <xsl:if test="following-sibling::node()[1][name(.) = '']">
+    <xsl:text>&#10;</xsl:text>
+    <xsl:text>.sp&#10;</xsl:text>
+  </xsl:if>
+</xsl:template>
+</xsl:stylesheet>