<codeblock>
A code block is a set of lines from a program.
Rendering expectations
Processors SHOULD preserve line the breaks and spaces
that are present in the content of a <codeblock>
element.
The content of the <codeblock>
element is typically
rendered in a monospaced font.
Specialization hierarchy
The <codeblock>
element is specialized from <pre>
. It is
defined in the programming domain module.
Content model
(Text |
<cite>
|
<include>
|
<keyword>
|
<markupname>
|
<apiname>
|
<option>
|
<parmname>
|
<cmdname>
|
<msgnum>
|
<varname>
|
<wintitle>
|
<numcharref>
|
<parameterentity>
|
<textentity>
|
<xmlatt>
|
<xmlelement>
|
<xmlnsname>
|
<xmlpi>
|
<ph>
|
<strong>
|
<em>
|
<b>
|
<i>
|
<line-through>
|
<overline>
|
<sup>
|
<sub>
|
<tt>
|
<u>
|
<hwcontrol>
|
<partno>
|
<codeph>
|
<filepath>
|
<msgph>
|
<systemoutput>
|
<userinput>
|
<synph>
|
<menucascade>
|
<uicontrol>
|
<q>
|
<term>
|
<abbreviated-form>
|
<text>
|
<xref>
|
<coderef>
|
<data>
|
<sort-as>
|
<foreign>
|
<draft-comment>
|
<fn>
|
<indexterm>
|
<required-cleanup>
)*
- Text
-
<abbreviated-form>
-
<apiname>
-
<b>
-
<cite>
-
<cmdname>
-
<codeph>
-
<coderef>
-
<data>
-
<draft-comment>
-
<em>
-
<filepath>
-
<fn>
-
<foreign>
-
<hwcontrol>
-
<i>
-
<include>
-
<indexterm>
-
<keyword>
-
<line-through>
-
<markupname>
-
<menucascade>
-
<msgnum>
-
<msgph>
-
<numcharref>
-
<option>
-
<overline>
-
<parameterentity>
-
<parmname>
-
<partno>
-
<ph>
-
<q>
-
<required-cleanup>
-
<sort-as>
-
<strong>
-
<sub>
-
<sup>
-
<synph>
-
<systemoutput>
-
<term>
-
<text>
-
<textentity>
-
<tt>
-
<u>
-
<uicontrol>
-
<userinput>
-
<varname>
-
<wintitle>
-
<xmlatt>
-
<xmlelement>
-
<xmlnsname>
-
<xmlpi>
-
<xref>
Attributes
The following attributes are available on this element: display
attributes, universal
attributes, and @xml:space
.
The following attributes are available on this element: universal attributes and the attributes defined below.
@expanse
(display attributes)- Specifies the horizontal placement of the element. The
following values are valid:
- column
- Indicates that the element is aligned with the current column margin.
- page
- Indicates that the element is placed on the left page margin for left-to-right presentation or the right page margin for right-to-left presentation.
- spread
- Indicates that the object is rendered across a multi-page spread. If the output format does not have anything that corresponds to spreads, then spread has the same meaning as page.
- textline
- Indicates that the element is aligned with the left (for left-to-right presentation) or right (for right-to-left presentation) margin of the current text line and takes indentation into account.
- -dita-use-conref-target
- See Using the -dita-use-conref-target value for more information.
For
<table>
, in place of the@expanse
attribute that is used by other DITA elements, the@pgwide
attribute is used in order to conform to the OASIS Exchange Table Model.Some processors or output formats might not support all values.
@frame
(display attributes)- Specifies which portion of a border surrounds the element.
The following values are valid:
- all
- Indicates that a line is rendered at the top, bottom, left, and right of the containing element.
- bottom
- Indicates that a line is rendered at the bottom of the containing element.
- none
- Indicates that no lines are rendered.
- sides
- Indicates that a line is rendered at the left and right of the containing element.
- top
- Indicates that a line is rendered at the top of the containing element.
- topbot
- Indicates that a line is rendered at the top and bottom of the containing element.
- -dita-use-conref-target
- See Using the -dita-use-conref-target value for more information.
Some processors or output formats might not support all values.
@scale
(display attributes)- Specifies the percentage by which fonts are resized in
relation to the normal text size. The value of this attribute
is a positive integer. When used on
<table>
or<simpletable>
, the following values are valid: 50, 60, 70, 80, 90, 100, 110, 120, 140, 160, 180, 200, and -dita-use-conref-target.This attribute is primarily useful for print-oriented display. Some processors might not support all values.
If the
@scale
attribute is specified on an element that contains an image, the image is not scaled. The image is scaled only if a scaling property is explicitly specified for the<image>
element. @xml:space
- Specifies how to handle white space in the
current element. This attribute is provided
on
<pre>
,<lines>
, and on elements specialized from those. It ensures that parsers respect white space that is part of the data in those elements, including line-end characters. When defined, it has a fixed value of preserve, making it a default property of the element that cannot be changed or deleted by authors.
Example
This section is non-normative.
The following code sample shows how the <codeblock>
element can be
used to tag an excerpt from an XSLT stylesheet:
<codeblock>
<xsl:template match="*[contains(@outputclass,'green')]">
<xsl:attribute name="color">#006400;</xsl:attribute>
</xsl:template>
</codeblock>
For a sample of how this element can be combined with
<coderef>
to embed external code samples, see coderef.