I'm using PrinceXML to make some PDFs of some HTML which includes some MathJax markup. In order to render the math properly, the javascript handling the math rendering needs to be run on the page before conversion to PDF.
If I enable javascript in PrinceXML and try to load the MathJax library, I get a "TypeError: null value is not an object" in the initialisation code. Tracking this down, it turns out that the following causes the error:
var scripts = (document.documentElement || document).getElementsByTagName("script");
var namePattern = new RegExp("(^|/)"+BASENAME+"\\.js(\\?.*)?$");
for (var i = scripts.length-1; i >= 0; i--) {
if (scripts[i].src.match(namePattern)) { // <--- Error thrown here
STARTUP.script = scripts[i].innerHTML;
if (RegExp.$2) {
<etc...>
The error is thrown on a script element without an src attribute (MathJax uses script elements to store LaTeX code in). PrinceXML appears to handle missing src attributes by returning null when accessing a missing src attribute - hence scripts[i].src.match(namePattern)
throws an error as src
is null. However, when done in Firefox (see fiddle: http://jsfiddle.net/9ZHMR/) element.src returns the empty string when the src attribute is missing, and so I didn't see this issue when working in the browser.
Which behaviour is 'correct' - should a script element's src attribute be null or the empty string if the attribute does not exist? Is this a case of real-life vs the standards?
EDIT I'm interested primarily in whether this behavior is specified by a standard somewhere, so I know whether to post a bug report to Firefox or PrinceXML, or if there is no standard, post a bug report to MathJax to handle this case.