DocBook 5.1: The Definitive Guide  (Version 1.5.3 for DocBook 5.1)

programlisting

programlisting — A literal listing of all or part of a program.

Synopsis

programlisting ::= [-]

Attributes

Common attributes and common linking attributes.

Additional attributes:

  • All of:
    • continuation (enumeration)
      • “continues”
      • “restarts”
    • linenumbering (enumeration)
      • “numbered”
      • “unnumbered”
    • startinglinenumber (integer)
    • xml:space (enumeration)
      • “preserve”
    • language
  • width (nonNegativeInteger)

Additional Constraints

  • If this element is the root element, it must have a version attribute.

Description

A programlisting is a verbatim environment for program source or source fragment listings. The programlistings are often placed in examples or figures so that they can be cross-referenced from the text.

Processing expectations

Formatted as a displayed block. This element is displayed “verbatim”; whitespace and line breaks within this element are significant. The programlistings are usually displayed in a fixed-width font.

Other markup within a programlisting is recognized. Contrast this with systems like LaTeX, in which verbatim environments disable markup recognition. If you want to disable markup recognition, you must use a CDATA section:

<programlisting>
<![CDATA[
This is a programlisting so white       space and line
breaks are significant.  But it is also a CDATA
section so <emphasis>tags</emphasis> and &entities;
are not recognized.  The only markup that is recognized
is the end-of-section marker, which is two
"]"'s in a row followed by a >.

]]>

</programlisting>

Two markup tags have special significance in programlistings: co and lineannotation. A co identifies the location of a callout. A lineannotation is a comment, added by the documentor—not the programmer.

Attributes

Common attributes and common linking attributes.

continuation

Determines whether line numbering continues from the previous element or restarts.

Enumerated values:
“continues”

Line numbering continues from the immediately preceding element with the same name.

“restarts”

Line numbering restarts (begins at 1, usually).

language

Identifies the language (i.e. programming language) of the verbatim content.

linenumbering

Determines whether lines are numbered.

Enumerated values:
“numbered”

Lines are numbered.

“unnumbered”

Lines are not numbered.

startinglinenumber

Specifies the initial line number.

width

Specifies the width (in characters) of the element

xml:space

Can be used to indicate explicitly that whitespace in the verbatim environment is preserved. Whitespace must always be preserved in verbatim environments whether this attribute is specified or not.

Enumerated values:
“preserve”

Whitespace must be preserved.