A importância de comentar o HTML corretamente

  • Revision slug: A_importância_de_comentar_o_HTML_corretamente
  • Revision title: A importância de comentar o HTML corretamente
  • Revision id: 283232
  • Created:
  • Creator: Verruckt
  • Is current revision? Não
  • コメント

Revision Content

When authoring HTML in standards mode, incorrectly formed comments can break your pages, resulting in part or all of your content being commented out. When authoring XHTML or XML, incorrect comments will result in your documents not being able to be displayed at all.

HTML 4.01

From W3C HTML 4.01 Recommendation Section 3.2.4 - Comments:

White space is not permitted between the markup declaration open delimiter("<!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter (">"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.

Examples

The following are valid comments in HTML.

<!-- valid html comment -->
<!-- valid html comment -- >

The following is not a valid comment in HTML.

<!-- invalid -- html comment -->

XML

From the W3C XML 1.0 Recommendation Section 2.5 - Comments:

Definition: Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string "--" (double-hyphen) must not occur within comments. Parameter entity references must not be recognized within comments.
[15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'

As described in the grammar for comments in XML, a comment has the form

<!-- characters excluding adjacent dashes -->

Examples

The following is a valid comment in XML and XHTML.

<!-- valid xml/xhtml comment -->

The following are not valid comments in XML and XHTML.

<!-- invalid -- xml comment -->
<!-- invalid xml comment --->
<!-- invalid xml comment -- >

Further Reading

{{template.InfoDocOriginal("-", "-", "19/05/03", "Copyright © 2001-2003 Netscape. All rights reserved.")}}

Categorias

Interwiki Language Links

{{ wiki.languages( { "en": "en/The_Importance_of_Correct_HTML_Commenting", "es": "es/HTML/La_importancia_de_comentar_correctamente", "fr": "fr/De_l\'importance_des_commentaires_bien_form\u00e9s_en_HTML", "pl": "pl/HTML/Znaczenie_poprawnego_komentowania", "ko": "ko/The_Importance_of_Correct_HTML_Commenting" } ) }}

Revision Source

<p>
When authoring HTML in <a class="external" href="http://www.mozilla.org/docs/web-developer/quirks/doctypes.html">standards mode</a>, incorrectly formed comments can break your pages, resulting in part or all of your content being commented out. When authoring XHTML or XML, incorrect comments will result in your documents not being able to be displayed at all.
</p>
<h3 name="HTML_4.01"> HTML 4.01 </h3>
<p><i>From <a class="external" href="http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4">W3C HTML 4.01 Recommendation Section 3.2.4 - Comments</a>:</i>
</p><p>White space is not permitted between the markup declaration open delimiter("&lt;!") and the comment open delimiter ("--"), but is permitted between the comment close delimiter ("--") and the markup declaration close delimiter ("&gt;"). A common error is to include a string of hyphens ("---") within a comment. Authors should avoid putting two or more adjacent hyphens inside comments.
</p>
<h4 name="Examples"> Examples </h4>
<p>The following are valid comments in HTML.
</p>
<pre class="eval">&lt;!-- valid html comment --&gt;
&lt;!-- valid html comment -- &gt;
</pre>
<p>The following is not a valid comment in HTML.
</p>
<pre class="eval">&lt;!-- invalid -- html comment --&gt;
</pre>
<h3 name="XML"> XML </h3>
<p><i>From the <a class="external" href="http://www.w3.org/TR/REC-xml#sec-comments">W3C XML 1.0 Recommendation Section 2.5 - Comments</a>:</i>
</p>
<blockquote>
<b>Definition:</b> Comments may appear anywhere in a document outside other markup; in addition, they may appear within the document type declaration at places allowed by the grammar. They are not part of the document's character data; an XML processor may, but need not, make it possible for an application to retrieve the text of comments. For compatibility, the string "--" (double-hyphen) must not occur within comments. Parameter entity references must not be recognized within comments.

<pre>[15] Comment ::= '&lt;!--' ((Char - '-') | ('-' (Char - '-')))* '--&gt;'
</pre></blockquote>
<p>As described in the grammar for comments in XML, a comment has the form
</p>
<pre class="eval">&lt;!-- characters excluding adjacent dashes --&gt;
</pre>
<h4 name="Examples_2"> Examples </h4>
<p>The following is a valid comment in XML and XHTML.
</p>
<pre class="eval">&lt;!-- valid xml/xhtml comment --&gt;
</pre>
<p>The following are not valid comments in XML and XHTML.
</p>
<pre class="eval">&lt;!-- invalid -- xml comment --&gt;
&lt;!-- invalid xml comment ---&gt;
&lt;!-- invalid xml comment -- &gt;
</pre>
<h3 name="Further_Reading"> Further Reading </h3>
<ul><li> <a class="external" href="http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.4">HTML 4.01 Recommendation: 3.2.4 - Comments</a>
</li><li> <a class="external" href="http://www.w3.org/TR/REC-xml#sec-comments">XML Recommendation: 2.5 - Comments</a>
</li><li> {{wiki.template('Named-bug', [ 144432, "Bugzilla bug 144432" ])}}
</li><li> {{wiki.template('Named-bug', [ 102127, "Bugzilla bug 102127" ])}}
</li></ul>
<p>{{template.InfoDocOriginal("-", "-", "19/05/03", "Copyright © 2001-2003 Netscape. All rights reserved.")}}
</p><p><span class="comment">Categorias</span>
</p><p><span class="comment">Interwiki Language Links</span>
</p>{{ wiki.languages( { "en": "en/The_Importance_of_Correct_HTML_Commenting", "es": "es/HTML/La_importancia_de_comentar_correctamente", "fr": "fr/De_l\'importance_des_commentaires_bien_form\u00e9s_en_HTML", "pl": "pl/HTML/Znaczenie_poprawnego_komentowania", "ko": "ko/The_Importance_of_Correct_HTML_Commenting" } ) }}
Revert to this revision