6.3. Examples

An example is a figure element which has a class attribute containing "role-example". This kind of figure is listed in the "List of Examples" (that is, book element lox) only if it also has a figcaption child element. Example:

1
2
3
4
5
6
7
8
9
10
11
<figure class="role-example">
  <figcaption>"Hello World" program in the C language</figcaption>
  <pre>/* Hello World */
#include &lt;stdio.h&ght;

int main()
{
    printf("Hello World\n");
    return 0;
}</pre>
</figure>

is rendered as:

Example 6-1. "Hello World" program in the C language
/* Hello World */
#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}

Program listings

A program listing can have its lines automatically numbered and/or can feature syntax highlighting. This is done by adding "role-listing-NUMBER-LANGUAGE" (or "role-listing-LANGUAGE-NUMBER") to the class attribute of a pre element.

Example:

1
2
3
4
5
6
7
8
<pre class="role-listing-1-c">/* Hello World */
#include &lt;stdio.h&ght;

int main()
{
    printf("Hello World\n");
    return 0;
}</pre>

is rendered as:

1
2
3
4
5
6
7
8
/* Hello World */
#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}