On Wed, 13 Oct 2010, Jason Gilmore wrote:

+--
| I am however running into a strange issue involving <programlisting>
| elements in which the enclosed text is delimited by <![CDATA[...]]>.
| When I convert from Docbook to PDF using oXygen (using the Saxon 6.5
| transformer), my program listing's include two extra newlines at the
| top and one at the bottom when the <programlisting>'s look like this:
+--

Here's how I format code snippets (with a little context to show the
indentation):

    <para>
      This code destroys Western Snivelization:
    </para>
    <programlisting role='outFile:hardloop.bas'
 10 PRINT "BASIC IS OLDER THAN DIRT"
  20 GOTO 10
  30 END
</programlisting>
    <para>
      And now...
    </para>

We're especially sensitive to how <programlisting> works because we
use this element for literate programming: the code snippets are
the ones that get executed.  Remarks on the above example:

 a. Whitespace, including newlines, is always allowed before the
    closing '>' of a tag.

 b. We use the 'role' attribute, which is reserved for application
    use, to mark the source file to which each fragment is written.
    The lines written to file "hardloop.bas" look like this:

================================================================
  10 PRINT "BASIC IS OLDER THAN DIRT"
  20 GOTO 10
  30 END
----------------------------------------------------------------

 c. Note that the first code line is misaligned relative to the
    following line because of the '>'.  This is annoying only while
    you're editing the source; it looks correct in HTML and PDF
    output.

With CDATA it'd look like this:

    <programlisting>
<![CDATA[   10 PRINT "BASIC IS OLDER THAN DIRT"
  20 GOTO 10
  30 END
]]></programlisting>

Here's a boatload of literate programming examples and some pointers
to the why and how in our local practice:

    http://www.nmt.edu/~shipman/soft/litprog/

Happy happy joy joy,
John Shipman ([email protected]), Applications Specialist, NM Tech Computer Center,
Speare 119, Socorro, NM 87801, (575) 835-5735, http://www.nmt.edu/~john
  ``Let's go outside and commiserate with nature.''  --Dave Farber

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to