docbook / xslt10-stylesheets

XSLT 1.0 Stylesheets for DocBook
99 stars 76 forks source link

manpage stylesheet formatting of <classsynopsis> #218

Open svarshavchik opened 3 years ago

svarshavchik commented 3 years ago

Using 1.79.2 stylesheets to generate man pages (http://cdn.docbook.org/release/xsl-nons/current//manpages/docbook.xsl) from the following:

<refsynopsisdiv>
  <classsynopsis class="class" language="C++">
    <ooclass>
      <classname>struct unicode::bidi_calc_types</classname>
    </ooclass>
    <constructorsynopsis>
      <methodname>bidi_calc_types</methodname>
      <methodparam>
    const std::u32string &amp;<parameter>string</parameter>
      </methodparam>
    </constructorsynopsis>
  </classsynopsis>

This results in the following formatted man page:

SYNOPSIS
       struct unicode::bidi_calc_types {
         bidi_calc_types(
                 const std::u32string &string);
       }.fi

The troff ".fi" instruction is leaking. The raw troff source that came out was:


.SH "SYNOPSIS"
.sp
.nf
struct unicode::bidi_calc_types\ \&{
.
\ \&\ \&bidi_calc_types(
                const std::u32string &string);
.
}.fi
.sp

Seems like there's a missing newline somewhere.

bobstayton commented 3 years ago

I can duplicate this bug, which also appears in version 1.79.1. Line break management in the manpage stylesheet is tricky. The bug is in manpages/html-synop.xsl, in the template with match="classsynopsis" mode="cpp" in this case (and in the other language modes too). At the end of the template where it has:

< /pre><xsl:text/><xsl:text>.fi </text>

that should be:

< /pre><xsl:text> </text><xsl:text>.fi </text>

Fixing this in the source is more complicated, though, because the html-synop.xsl stylesheet file is generated by the DocBook XSL build process, so I'll have to trace through that process to see where this is going wrong. However, if you need an immediate fix, copy that template to a customization layer and make this change as a workaround.

bobstayton commented 3 years ago

I traced the problem in the build to xsl/tools/xsl/build/html2roff.xsl. Every instance of this:

<xsl:element name="xsl:text">&#10;</xsl:element>

should be replaced with:

<xsl:element name="xsl:text"><xsl:text>&#10;</xsl:text></xsl:element>

That's because a white-space-only node is not preserved unless it is inside <xsl:text>.