<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Defective Semantics &#187; prettify</title>
	<atom:link href="http://scarff.id.au/blog/tag/prettify/feed/" rel="self" type="application/rss+xml" />
	<link>http://scarff.id.au</link>
	<description>Dean Scarff's perpetual struggle with technology, and other anecdotes</description>
	<lastBuildDate>Sat, 31 Jul 2010 02:44:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Firefox NS_ERROR_INVALID_POINTER with innerHTML</title>
		<link>http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/</link>
		<comments>http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 04:33:46 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[prettify]]></category>
		<category><![CDATA[xhtml]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=329</guid>
		<description><![CDATA[<p>When trying to use prettify here on Defective Semantics I ran into problems with firefox.  Here are the errors from the error console:</p>
<pre class="error">
Error: undefined entity
Error: uncaught exception: [Exception...
 "Component returned failure code: 0x80004003
 (NS_ERROR_INVALID_POINTER) [nsIDOMNSHTMLElement.innerHTML]"
  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"
  location: "JS frame :: hxxp://example.net/prettify.js ::
             replaceWithPrettyPrintedHtml :: line 1414"
  data: no]
</pre>
<p>My insistence on trying to use XHTML on the blog is partly to blame.  Prettify tries to add &#8220;&#38;nbsp;&#8221; entities to the source (even if it&#8217;s a pre element) to appease Internet Explorer.  This entity only semi-works in XHTML: I&#8217;ve run into similar problems with some HTML entities not being loaded, because some browsers don&#8217;t load the DTD (which in turn loads the entity sets).  It also appears that while Firefox claims to support HTML latin 1 entities in a document with a PUBLIC XHTML identifier, it doesn&#8217;t actually reparse innerHTML assignments according to those&#8230; <a href="http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>When trying to use <a href="http://code.google.com/p/google-code-prettify/">prettify</a> here on Defective Semantics I ran into problems with firefox.  Here are the errors from the error console:</p>
<pre class="error">
Error: undefined entity
Error: uncaught exception: [Exception...
 "Component returned failure code: 0x80004003
 (NS_ERROR_INVALID_POINTER) [nsIDOMNSHTMLElement.innerHTML]"
  nsresult: "0x80004003 (NS_ERROR_INVALID_POINTER)"
  location: "JS frame :: hxxp://example.net/prettify.js ::
             replaceWithPrettyPrintedHtml :: line 1414"
  data: no]
</pre>
<p>My insistence on trying to use XHTML on the blog is partly to blame.  Prettify tries to add &#8220;&amp;nbsp;&#8221; entities to the source (even if it&#8217;s a pre element) to appease Internet Explorer.  This entity only semi-works in XHTML: I&#8217;ve run into similar problems with some HTML entities not being loaded, because some browsers don&#8217;t load the DTD (which in turn loads the entity sets).  It also appears that while Firefox <a href="https://developer.mozilla.org/en/XML_in_Mozilla#XHTML">claims to support HTML latin 1 entities</a> in a document with a PUBLIC XHTML identifier, it doesn&#8217;t actually reparse innerHTML assignments according to those rules.</p>
<p>My solution is to add a conditional test for XML.  Having a look at the <a href="https://developer.mozilla.org/en/DOM/document">Javascript document object</a> there doesn&#8217;t seem to be a <em>reliable</em> way to detect whether the browser is treating the document as XML from javascript.  My best attempt was:</p>
<pre class="codeblock javascript">
document.xmlVersion &#038;&#038; (document.compatMode=='CSS1Compat');
</pre>
<p>which works for Firefox and Opera.</p>
<p>As a separate issue, Chrome and Safari (and presumably anything WebKit based) don&#8217;t allow assignment of innerHTML for XML documents, giving <code class="error">NO_MODIFICATION_ALLOWED_ERR: DOM Exception 7</code>.<br />
Fixing prettify to use only DOM methods instead of building up a string and assigning it to innerHTML could be a lot of work.  At least this exception, unlike the Firefox error, doesn&#8217;t leave the pretty-printed block in an inconsistent state.</p>
<p>I submitted a patch to the <a href="http://code.google.com/p/google-code-prettify/issues/detail?id=108">prettify issue tracker</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2010/firefox-ns_error_invalid_pointer-with-innerhtml/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
