1
<?xml version="1.0" encoding="utf-8"?>
2
<page xmlns="http://projectmallard.org/1.0/" type="topic" id="mal_inline_code">
5
<link type="guide" xref="mal_inline#elements"/>
7
<revision version="0.1" date="2008-12-12" status="review"/>
10
<name>Shaun McCance</name>
11
<email>shaunm@gnome.org</email>
12
<years>2008-2009</years>
15
<include xmlns="http://www.w3.org/2001/XInclude" href="legal.xml"/>
17
<desc>Mark up code from a programming, markup, or other machine-readable format.</desc>
20
<title>Code Snippets</title>
22
<synopsis><code mime="application/relax-ng-compact-syntax">
23
mal_inline_code = element code {
24
<link xref="mal_attr_link">mal_attr_link</link> ?,
25
attribute style { xsd:NMTOKENS } ?,
26
attribute mime { text } ?,
27
attribute * - (mal:* | local:*) { text } *,
29
<link xref="mal_inline">mal_inline</link>
33
<p>Use the <code>code</code> element to mark up a portion of text from a
34
computer language. This includes programming languages, markup languages,
35
and the contents of any type of file with a structured syntax. For commands
36
which are run in an interactive shell, however, you should use the
37
<code xref="mal_inline_cmd">cmd</code> element, even though they may
38
include snippets of shell programming.</p>
40
<p>You can use the <code>code</code> element to mark up any portion of
41
code, including comments or textual content that doesn't strictly follow
44
<p>Use the <code xref="mal_inline_var">var</code> element inside a
45
<code>code</code> element to indicate text that should be replaced
53
<item><p>The <code>code</code> element can contain a mixture of text and
54
any <link xref="mal_inline">general inline elements</link>.</p></item>
56
<item><p>The <code>code</code> element can occur in any
57
general inline context, including inside most
58
<link xref="mal_inline">inline elements</link>, some
59
<link xref="mal_block#basic">basic block elements</link>, and certain
60
<link xref="mal_info">informational elements</link>.</p></item>
62
<item><p>The <code>code</code> element can link to other pages or documents.
63
See <link xref="mal_attr_link"/> for more information.</p></item>
65
<item><p>The <code>style</code> attribute takes a space-separated list of
66
style hints. Processing tools should adjust their behavior according to
67
those style hints they understand.</p></item>
69
<item><p>The <code>mime</code> attribute takes a valid MIME type. Processing
70
tools may adjust their behavior for particular MIME types.</p></item>
72
<item><p>The <code>code</code> element can have attributes from external
73
namespaces. See <link xref="mal_external"/> for more information
74
on external-namespace attributes.</p></item>
76
<item><p>The <code>code</code> element may also be used in a block context.
77
See <link xref="mal_block_code"/> for more information.</p></item>
83
<!-- BEGIN examples -->
84
<section id="examples">
85
<title>Ejemplos</title>
87
<p>Use <code>code</code> to mark up the name of a function, struct, or other
88
constuct in a programming language:</p>
92
Use <code>gtk_container_add</code> to add a child widget to a
93
<code>GtkButton</code>.
95
<p>Use <code>gtk_container_add</code> to add a child widget to a <code>GtkButton</code>.</p>
98
<p>Use <code>code</code> with <code xref="mal_inline_var">var</code> to mark
99
up code with a placeholder for an argument the user should supply:</p>
103
To create a new button with a label, use
104
<code>gtk_button_new_with_label(<var>label</var>)</code>,
105
replacing <var>label</var> with the text of the label.
107
<p>To create a new button with a label, use
108
<code>gtk_button_new_with_label(<var>label</var>)</code>,
109
replacing <var>label</var> with the text of the label.</p>
112
<p>Link to a web page directly with a <code>code</code> element:</p>
116
Use <code>code</code> with <code xref="mal_inline_var">var</code> to mark
117
up code with a placeholder for an argument the user should supply.
119
<p>Use <code>code</code> with <code xref="mal_inline_var">var</code> to mark
120
up code with a placeholder for an argument the user should supply.</p>
123
<!-- END examples -->
126
<!-- BEGIN processing -->
127
<section id="processing">
128
<title>Processing Expectations</title>
129
<p>Code snippets are displayed in a fixed-width font. This mimics
130
the look of a typical environment where code is typed. More importantly,
131
fixed-width fonts tend to have more distinction between visually similar
132
characters. This is particularly important in code, since letters often
133
appear without the context of a known word that helps make them discernable
136
<p>For particularly long code snippets, display tools may use a background
137
color or border to make the beginning and end clear, although authors should
138
prefer <link xref="mal_block_code">code blocks</link> for long code snippets.</p>
140
<!-- END processing -->
143
<!-- BEGIN comparison -->
144
<section id="comparison">
145
<title>Comparison to Other Formats</title>
146
<p>The <code>code</code> element is similar to the
147
<code href="http://www.docbook.org/tdg/en/html/code.html">code</code> element
148
in DocBook. Since Mallard does not attempt to model programming languages,
149
<code>code</code> may be used in place of numerous DocBook elements, including
150
<code href="http://www.docbook.org/tdg/en/html/classname.html">classname</code>,
151
<code href="http://www.docbook.org/tdg/en/html/constant.html">constant</code>,
152
<code href="http://www.docbook.org/tdg/en/html/function.html">function</code>,
153
<code href="http://www.docbook.org/tdg/en/html/interfacename.html">interfacename</code>,
154
<code href="http://www.docbook.org/tdg/en/html/methodname.html">methodname</code>,
155
<code href="http://www.docbook.org/tdg/en/html/parameter.html">parameter</code>,
156
<code href="http://www.docbook.org/tdg/en/html/structfield.html">structfield</code>,
157
<code href="http://www.docbook.org/tdg/en/html/structname.html">structname</code>, and
158
<code href="http://www.docbook.org/tdg/en/html/varname.html">varname</code>.
159
Additionally, since Mallard does not provide separate elements for marking
160
portions of markup languages, the <code>code</code> element should be used
161
in place of the DocBook elements
162
<code href="http://www.docbook.org/tdg/en/html/markup.html">markup</code> and
163
<code href="http://www.docbook.org/tdg/en/html/sgmltag.html">sgmltag</code>.</p>
165
<!-- END comparison -->