4.3.1. Syntax highlighting Previous topic Parent topic Child topic Next topic

This section 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 (or -shell or -sh), language-c, language-cmake (or -make or -makefile), language-cpp, language-csharp, language-css21 (or -css), 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 (or -sql), 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:

Example: customization of the syntax highlighting of a keyword for HTML-based output formats

.hl-keyword {
    font-weight: bold;
    color: #602060;
}
This can be done from within XMLmind XML Editor using OptionsCustomize ConfigurationCustomize Document Conversion Stylesheets.
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.

Example: 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>
This can be done from within XMLmind XML Editor using OptionsCustomize ConfigurationCustomize Document Conversion Stylesheets.