A.9. Docbook Common Issues

The following Docbook issues come up often. Some of these are preferences, but others can create mysterious build errors or other problems.

A.9.1. What can go where?
A.9.2. Paragraphs and Admonitions
A.9.3. Wrap textual <listitem> and <entry> contents in <para> elements.
A.9.4. When to use <command>, <code>, <programlisting>, <screen>
A.9.5. How to escape XML elements so that they show up as XML
A.9.6. Tips and tricks for making screen output look good
A.9.7. Isolate Changes for Easy Diff Review.
A.9.8. Syntax Highlighting

A.9.1.

What can go where?

There is often confusion about which child elements are valid in a given context. When in doubt, Docbook: The Definitive Guide is the best resource. It has an appendix which is indexed by element and contains all valid child and parent elements of any given element. If you edit Docbook often, a schema-aware XML editor makes things easier.

A.9.2.

Paragraphs and Admonitions

It is a common pattern, and it is technically valid, to put an admonition such as a <note> inside a <para> element. Because admonitions render as block-level elements (they take the whole width of the page), it is better to mark them up as siblings to the paragraphs around them, like this:

<para>This is the paragraph.</para>
<note>
    <para>This is an admonition which occurs after the paragraph.</para>
</note>

A.9.3.

Wrap textual <listitem> and <entry> contents in <para> elements.

Because the contents of a <listitem> (an element in an itemized, ordered, or variable list) or an <entry> (a cell in a table) can consist of things other than plain text, they need to be wrapped in some element. If they are plain text, they need to be inclosed in <para> tags. This is tedious but necessary for validity.

<itemizedlist>
    <listitem>
        <para>This is a paragraph.</para>
    </listitem>
    <listitem>
        <screen>This is screen output.</screen>
    </listitem>
</itemizedlist>

A.9.4.

When to use <command>, <code>, <programlisting>, <screen>

The first two are in-line tags, which can occur within the flow of paragraphs or titles. The second two are block elements.

Use <command> to mention a command such as hbase shell in the flow of a sentence. Use <code> for other inline text referring to code. Incidentally, use <literal> to specify literal strings that should be typed or entered exactly as shown. Within a <screen> listing, it can be helpful to use the <userinput> and <computeroutput> elements to mark up the text further.

Use <screen> to display input and output as the user would see it on the screen, in a log file, etc. Use <programlisting> only for blocks of code that occur within a file, such as Java or XML code, or a Bash shell script.

A.9.5.

How to escape XML elements so that they show up as XML

For one-off instances or short in-line mentions, use the &lt; and &gt; encoded characters. For longer mentions, or blocks of code, enclose it with &lt;![CDATA[]]&gt;, which is much easier to maintain and parse in the source files..

A.9.6.

Tips and tricks for making screen output look good

Text within <screen> and <programlisting> elements is shown exactly as it appears in the source, including indentation, tabs, and line wrap.

  • Indent the starting and closing XML elements, but do not indent the content. Also, to avoid having an extra blank line at the beginning of the programlisting output, do not put the CDATA element on its own line. For example:

            <programlisting>
    case $1 in
      --cleanZk|--cleanHdfs|--cleanAll)
        matches="yes" ;;
      *) ;;
    esac
            </programlisting>
  • After pasting code into a programlisting, fix the indentation manually, using two spaces per desired indentation. For screen output, be sure to include line breaks so that the text is no longer than 100 characters.

A.9.7.

Isolate Changes for Easy Diff Review.

Be careful with pretty-printing or re-formatting an entire XML file, even if the formatting has degraded over time. If you need to reformat a file, do that in a separate JIRA where you do not change any content. Be careful because some XML editors do a bulk-reformat when you open a new file, especially if you use GUI mode in the editor.

A.9.8.

Syntax Highlighting

The HBase Reference Guide uses the XSLT Syntax Highlighting Maven module for syntax highlighting. To enable syntax highlighting for a given <programlisting> or <screen> (or possibly other elements), add the attribute language=LANGUAGE_OF_CHOICE to the element, as in the following example:

<programlisting language="xml">
    <foo>bar</foo>
    <bar>foo</bar>
</programlisting>

Several syntax types are supported. The most interesting ones for the HBase Reference Guide are java, xml, sql, and bourne (for BASH shell output or Linux command-line examples).

comments powered by Disqus