DITA: Code (inline and block)
codeph
and codeblock
.codeph
, like
this:
codeph
stands for "code phrase." (There's another tag called
ph
that is just "phrase.")
codeblock
with an outputclass
attribute that specifies the language for the syntax
highlighter:
As soon as you type outputclass="
in the code editor, you're prompted with
language options. If you don't choose an output
class, the default is
java.
Note that adding the outputclass will prompt Oxygen to add syntax highlighting in the output (injecting a lot of inline formatting). If you're publishing to a location that already provides a syntax highlighter, don't add an outputclass.
<
is <
and >
is >
For &
,
use &
. The above code really looks like
this:
You can also reference code stored in another file using a coderef
element
inside a codeblock
:
With this method, you don't have to convert the illegal symbols into their character equivalents. Also, the referenced file cabe stored with the programming language type extension, which gives you syntax highlighting while you're editing it.
If you want to title the code sample with a name, use the fig
and
title
elements:
If you want to bold part of a code sample, you can do so by inserting b
tags to bold the content. (Don't convert the angle brackets around the b tag to
character equivalents.)
If the syntax highlighter is accidentally highlighting some of your code as a comment instead of actual code, wrap the problematic code inside codeph
tags.
About Tom Johnson
I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.
If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.