返回

Code

<code>元素代表计算机代码的一部分。 这可以是XML元素名称,文件名,计算机程序或计算机可以识别的任何其他字符串。

没有正式的方法可以表明被标记的计算机代码的语言。 希望使用所用语言标记代码元素的作者,例如 这样语法突出显示脚本可以使用正确的规则,可以使用class属性,例如 通过向元素添加前缀为“ language-”的类。

示例

以下示例显示如何在段落中使用元素来标记元素名称和计算机代码,包括标点符号。

<p>The <code>code</code> element represents a fragment of computer code.</p> 
<p>
    When you call the <code>activate()</code> method on the   <code>robotSnowman</code> object, the eyes glow.
 </p> 
<p>The example below uses the <code>begin</code> keyword to indicate the start of a statement block. It is paired with an <code>end</code> keyword, which is followed by the <code>.</code> punctuation character (full stop) to indicate the end of the program.</p>

以下示例显示了如何使用pre和code元素标记代码块。
<pre><code class="language-pascal">var i: Integer; begin i := 1; end.</code></pre>