<code>

Description

Preformed source code.

Code elements are processed during translation in order to add syntax highlighting for the language specified in the lang attribute.

The processing removes any uniform leading tabs/spaces from the code lines. This allows the source document to contain uniform indenting, without affecting the layout of the code in the final document. The example below illustrates this.

The default BDML CSS provided with the Bora document processor specifies a tab size of 4 characters.

Attributes

In addition to the following attributes, standard attributes may be defined on <code> elements.

Attribute name Description
lang The programming language contained in the code element.

Immediate descendants

<h3> elements may contain text.

No element descendants are defined for the <h3> element.

Immediate ancestors

Element name Relation
<chapter> The enclosing chapter of the source code block.

Example

<document xmlns="http://boradoc.org/1.0">
  <chapter>
    <code lang="C++">
        namespace NS {
            // A simple class.
            class A {
                public: std::string data;
            };
        }

        // Example Balau toString function for the above class.
        namespace NS {
            inline string toString(const A & value) {
                return value.data;
            }
        }
    </code>
  </chapter>
</document>

The above BDML renders to the following:

				namespace NS {
					// A simple class.
					class A {
						public: std::string data;
					};
				}

				// Example Balau toString function for the above class.
				namespace NS {
					inline string toString(const A & value) {
						return value.data;
					}
				}