mozilla

Revision 43394 of View source

  • Revision slug: View_source
  • Revision title: View source
  • Revision id: 43394
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment new page for bug 482921; page created, 399 words added

Revision Content

The View Source option in the Tools menu lets you look at the HTML or XML for the document you're viewing. This article provides useful information about this feature.

Note: This article covers the new implementation of the View Source feature implemented in Firefox 10, which offers new features over older versions of Firefox.

Features offered by View Source

Syntax highlighting
The View Source window uses the same HTML5 parser Firefox uses when processing content in order to offer accurate syntax highlighting of the markup.
Error reporting
The View Source window highlights parsing errors in red; hovering your mouse over errors displays a tooltip explaining the error.

Limitations of View Source

There are limitations to what View Source does for you that you need to be aware of.

Error reporter ≠ validator

The View Source window only reports parsing errors, not HTML validity errors. For example, putting a {{ HTMLElement("div") }} element as a child of a {{ HTMLElement("ul") }} element isn't a parse error, but it is not valid HTML. Therefore, this error will not be flagged in the View Source window. If you want to check that HTML is valid, you should use an HTML validator, such as the one offered by W3C.

Not all parse errors are reported

Even though all the reported errors are parse errors according to the HTML specification, not all parse errors are reported by View Source. Among the errors that don't get reported:

  • Bytes that are illegal according to the document's encoding aren't marked as errors.
  • Forbidden characters aren't reported as errors.
  • Errors related to the end-of-file aren't reported.
  • Tree builder errors relating to text (as opposed to tags, comments, or doctypes) aren't reported.
  • Parse errors related to xmlns attributes aren't reported.

XML syntax highlighting

The View Source window uses the HTML tokenizer when highlighting XML source. While the tokenizer has support for processing instructions when highlighting XML source, that's the only XML-specific capability provided. Because of this, doctypes that have an internal subset are not highlighted correctly, and entity references to custom entities are also not highlighted correctly.

This mishighlighting can be seen by viewing the source of Firefox chrome files (such as XUL documents). However, this shouldn't be a problem in practice when viewing typical XML files.

See also

Revision Source

<p>The View Source option in the Tools menu lets you look at the HTML or XML for the document you're viewing. This article provides useful information about this feature.</p>
<div class="note"><strong>Note:</strong> This article covers the new implementation of the View Source feature implemented in Firefox 10, which offers new features over older versions of Firefox.</div>
<h2>Features offered by View Source</h2>
<dl> <dt>Syntax highlighting</dt> <dd>The View Source window uses the same HTML5 parser Firefox uses when processing content in order to offer accurate syntax highlighting of the markup.</dd> <dt>Error reporting</dt> <dd>The View Source window highlights parsing errors in red; hovering your mouse over errors displays a tooltip explaining the error.</dd>
</dl>
<h2>Limitations of View Source</h2>
<p>There are limitations to what View Source does for you that you need to be aware of.</p>
<h3>Error reporter ≠ validator</h3>
<p>The View Source window only reports parsing errors, <strong>not</strong> HTML validity errors. For example, putting a {{ HTMLElement("div") }} element as a child of a {{ HTMLElement("ul") }} element isn't a parse error, but it <strong>is not</strong> valid HTML. Therefore, this error will not be flagged in the View Source window. If you want to check that HTML is valid, you should use an HTML validator, such as <a class=" external" href="http://validator.w3.org/" title="http://validator.w3.org/">the one offered by W3C</a>.</p>
<h3>Not all parse errors are reported</h3>
<p>Even though all the reported errors are parse errors according to the HTML specification, not all parse errors are reported by View Source. Among the errors that don't get reported:</p>
<ul> <li>Bytes that are illegal according to the document's encoding aren't marked as errors.</li> <li>Forbidden characters aren't reported as errors.</li> <li>Errors related to the end-of-file aren't reported.</li> <li>Tree builder errors relating to text (as opposed to tags, comments, or doctypes) aren't reported.</li> <li>Parse errors related to <code>xmlns</code> attributes aren't reported.</li>
</ul>
<h2>XML syntax highlighting</h2>
<p>The View Source window uses the HTML tokenizer when highlighting XML source. While the tokenizer has support for processing instructions when highlighting XML source, that's the only XML-specific capability provided. Because of this, doctypes that have an internal subset are not highlighted correctly, and entity references to custom entities are also not highlighted correctly.</p>
<p>This mishighlighting can be seen by viewing the source of Firefox chrome files (such as XUL documents). However, this shouldn't be a problem in practice when viewing typical XML files.</p>
<h2>See also</h2>
<ul> <li><a class=" external" href="http://hsivonen.iki.fi/view-source/" title="http://hsivonen.iki.fi/view-source/">HTML5 Parser-Based View Source Syntax Highlighting</a> (Blog post)</li>
</ul>
Revert to this revision