code 要素
4.6.11 code 要素
- カテゴリー
- フロー・コンテンツ
- フレージング・コンテンツ
- この要素を使うことができるコンテキスト:
- フレージング・コンテンツが期待される場所
- コンテンツ・モデル:
- フレージング・コンテンツ
- コンテンツ属性:
- グローバル属性
- DOMインタフェース:
HTMLElementを使う。
code 要素は、コンピューター・コードの断片を表します。これは、XML 要素名、ファイル名、コンピューター・プログラム、そのほかコンピューターが認識する文字列などが考えられます。
コンピューターの言語をマークアップする正式な方法はありませんが、例えば、構文をハイライトするスクリプトが正しい規則を使うことができるように、code 要素を使って使用言語をマークアップしたい場合、ウェブ制作者は、その要素にプレフィックス "language-" を付けた class を加えることで、そうすることができます。
次の例は、要素名とコンピューターコードを区切り文字も含めてマークアップするために、段落の中でこの要素をどうやって使うのかを示しています。
<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>
この例では、class を使って使用言語を指し示しています。
詳しくは pre 要素をご覧ください。
※ 原文:http://www.w3.org/TR/2011/WD-html5-20110525/text-level-semantics.html#the-code-element