Chapter 7. Syntax highlighting

This chapter explains how you can automatically colorize the source code contained in <pre>, <codeblock> or any other element specializing <pre>.

You can automatically colorize the source code contained in <pre>, <codeblock> or any other element specializing <pre>. This feature, commonly called syntax highlighting, has been implemented using an open source software component called "XSLT syntax highlighting Opens in new window".
If you want to turn on syntax highlighting in a DITA document, suffice to add attribute @outputclass to a <pre>, <codeblock> or any other element specializing <pre>. The value of attribute @outputclass must be any of: language-bourne, language-c, language-cmake, language-cpp, language-csharp, language-css21, language-delphi, language-ini, language-java, language-javascript, language-lua, language-m2 (Modula 2), language-perl, language-php, language-python, language-ruby, language-sql1999, language-sql2003, language-sql92, language-tcl, language-upc (Unified Parallel C), language-html, language-xml.
If you want to customize syntax highlighting for an HTML-based output format (XHTML, EPUB, etc), then redefine any of the following CSS styles:

Customization of the syntax highlighting of a keyword for HTML-based output formats

.hl-keyword {
    font-weight: bold;
    color: #602060;
}
How to use a custom CSS stylesheet is explained in Part II, Chapter 9, Section 1.
If you want to customize syntax highlighting for an XSL-FO-based output format (PDF, RTF, etc), then redefine any of the following <attribute-set>s: hl-keyword, hl-string, hl-number, hl-comment, hl-doccomment, hl-directive, hl-annotation, hl-tag, hl-attribute, hl-value, hl-doctype.

Customization of the syntax highlighting of a keyword for XSL-FO-based output formats

<xsl:attribute-set name="hl-keyword" use-attribute-sets="hl-style">
  <xsl:attribute name="font-weight">bold</xsl:attribute>
  <xsl:attribute name="color">#602060</xsl:attribute>
</xsl:attribute-set>
How to use a custom XSLT stylesheet generating XSL-FO is explained in Part II, Chapter 9, Section 2.