8 に答える
XMP
とPRE
異なります。タグ内のコンテンツPRE
は次のようにフォーマットされます。
- コンテンツは固定フォントで表示されますが、
- すべての空白が保持され、
- 改行ごとに新しい行が始まります。
<
、 、>
などの特殊文字をタグ&
内に含める場合PRE
は、ブラウザが特別に解釈しないようにエスケープする必要があります。
対照的に、XMP
タグ内のコンテンツはエスケープする必要はありません。
タグ内に含めることができない唯一の文字シーケンスXMP
は、XMP
終了タグ ( </XMP>
) です。
XMP
私がテストしたブラウザではまだサポートされています。xmp.htmlで試すことができます。ソースを表示してタグを確認します。
W3C を Google で簡単に検索すると、HTML 3.2 以前で整形済みテキストXMP
を表示するために導入されたことがわかります。W3C がタグを非推奨にしたとき、タグを推奨される代替手段として使用することを提案しました。XMP
PRE
更新: http://www.w3.org/TR/REC-html32#xmp、http://www.w3.org/MarkUp/html-spec/html-spec_5.html#SEC5.5.2.1
XMP does some things that PRE does not support. I still depend on XMP, there is no substitute.
PHPxmp
でのデバッグにはまだタグを使用しています。なんらかの理由でタグvar_dump();
を使用することを思い出せません。pre
textarea
本当にテキストを出力したい場合は、readonly
属性を使用する必要があるため、それほど重要ではないと思います。
を使用<textarea>
しました。これは、html コードをきちんとしたボックスに入れ、前後のテキストとは異なるコードを明確に定義します。
<textarea><b>boldtext</b><textarea>
http://www.w3.org/Bugs/Public/show_bug.cgi?id=12235を参照してください。
HTML5 の場合。HTML5 エディター (コメント 11 と 12) によると、どちらにしても非常に近い結果でした。
生の html を表示するために引き続き機能します。スクリプトで使用する場合は、開始タグを壊してください。
var stuff='<xmp'+'>this is shown as is<br/>hello</xmp>';
document.getElementById("x").innerHTML=stuff;
<div id="x"></div>