-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MathJax 3 completion handler fails if the content contains processing instructions #2662
Comments
Thanks for the report. I can reproduce the issue. Frankly, I have never seen these processing instructions before, so was unaware even of their existence! I will have to modify the code to skip over non-Element nodes. |
FWIW, XML processing instructions are not valid in (x)html5. |
Thanks @pkra. I'm not able to find a reference to that. I see where they are not allowed in HTML5, but I can't find a restriction in XHTML5. Do you have a citation for that? |
(I don't mean for this to have any bearing on what the MathJax team decides to support.) IIUC it's difficult to find because there's not really such a thing as XHTML5. E.g., https://en.wikipedia.org/wiki/HTML5#XHTML_5_(XML-serialized_HTML_5) writes
So HTML5 does not allow processing instructions and XML serialization only adds restrictions, it does not remove any. That being said, given that this is coming from VitalSource (who, ahem, should really become a MathJax sponsor?), it probably comes from an epub file and, alas, epubcheck does allow processing instructions. [Still, this should really be sorted out in production] |
@pkra, thanks for the additional information. I was mostly just curious about what the various standards allow. I have worked out a means of ignoring those nodes that should resolve the issue, but your comment piqued my interest. |
As far as I know, processing instructions are valid in xhtml (and valid in epub files). And yes, this came from debugging an issue with a real epub on our platform, so people are using these. Thanks for fixing this for us! |
I have made a pull request to resolve the issue. In the meantime, you can use the following configuration to work around the problem for now. MathJax = {
startup: {
ready: function() {
//
// Patch the HTMLAdaptor's kind() method to return '' for node types we can't process.
//
const {HTMLAdaptor} = MathJax._.adaptors.HTMLAdaptor;
HTMLAdaptor.prototype.kind = function (node) {
const n = node.nodeType;
return (n === 1 || n === 3 || n === 8 ? node.nodeName.toLowerCase() : '');
};
//
// Subclass the DOM string walker to handle unknown node types
//
const {HTMLDomStrings} = MathJax._.handlers.html.HTMLDomStrings;
class myDomStrings extends HTMLDomStrings {
handleContainer(node, ignore) {
if (this.adaptor.kind(node) === '') {
this.pushString();
return [this.adaptor.next(node), ignore];
} else {
return super.handleContainer(node, ignore);
}
}
}
//
// Use our DOM string class instead of the usual one
//
MathJax.config.options = {DomStrings: new myDomStrings()};
//
// Do the usual processing
//
MathJax.startup.defaultReady();
//
// Inform us when it's done
//
MathJax.startup.promise.then(function() {
console.log("done");
});
}
}
}; |
PS, this could be put into a separate script file that is loaded before MathJax itself if you need it for multiple pages. |
Have HTMLDomStrings skip node types that it can't process. (mathjax/MathJax#2662)
Issue Summary
We found a bug where, when using tex-mml-chtml conversion, if the input file is xhtml containing a processing instruction, the completion handler never fires. Additionally, the javascript will show the following error in the console:
Unhandled Promise Rejection: TypeError: t.getAttribute is not a function. (In 't.getAttribute(e)', 't.getAttribute' is undefined)
We've replicated this in WebKit / Safari on macOS, iOS. And also in the embedded webkit view in Android.
Essentially, it's iterating through the content looking at the "class" attribute of various nodes. Somehow it is assuming they're all elements, and when it hits a processing instruction node (where getAttribute is not defined) it throws this error. You can see exactly what is happening if you turn on "break on exceptions" in the WebKit debugger.
We noticed that it only happens during TEX input processing, which we don't need. Turning off TEX works around the problem, which is what we have done. But it's still a bug, so I thought you might be interested in looking at it.
I've included 3 different versions of the file to illustrate this:
This is the one that fails. It has a completion handler defined that logs "done" to the console. If you open up the console you'll see the error I described, and "done" is never logged.
This illustrates that without the pi the example completes successfully and logs "done" to the console.
This illustrates that with the pi, but with mml-chtml ONLY (no TEX) it also completes successfully and logs "done" to the console.
Steps to Reproduce:
Technical details:
^ I was able to replicate with that. Easier than trying to reproduce with mobile.
Supporting information:
tex-pi-bug.zip
See the above attached zip for the promised example files. Just open them in Safari.
The text was updated successfully, but these errors were encountered: