1.2.2 The codeph element
This tutorial guides you through adding a codeph (code phrase) element to a DITA XML topic.
Overview
By the end of this tutorial, you will be able to:
- Explain the purpose and usage of code phrase elements in DITA XML.
- Identify appropriate locations to use
codephelements in DITA documents. - Add new
codephelements to a DITA concept document using the Oxygen XML editor. - Apply different methods for inserting
codephelements in Oxygen. - Mark up inline code snippets and programming terms in DITA XML.
Background
In DITA, a <codeph> element represents an inline phrase of code. It’s used to semantically identify small pieces of computer code that appear within the flow of text. Common uses include marking up:
- Variable names (e.g.,
<codeph>maxConnections</codeph>) - Function or method names (e.g.,
<codeph>calculateTotal()</codeph>) - Command names (e.g., run
<codeph>npm install</codeph>) - Filenames or paths (e.g., open
<codeph>src/main.js</codeph>) - Short code snippets or keywords that fit naturally within a sentence (e.g., the
<codeph>public static void</codeph>declaration).
Use <codeph> to wrap these code phrases directly a paragraph (<p>).
<codeph> is an inline element.
Add a <codeph> element
-
Open the concept topic you edited in The p element.
-
Click between the closing
<p>tag and the closing<conbody>tag to place the cursor. -
Add a new
<p>element. -
Type the following text inside the new
<p>element:A paragraph in text mode looks like this:Ensure to leave a space after the colon.
-
Add a new
<codeph>element. -
Type the following inside the
<codeph>element:<p>Hello</p> -
Save the file.
Expected result
DITA_101_oXygen/my_concept_using_codeph.xml (or a similar name you chose) to confirm the successful completion of this task.