Skip to content
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

Handle document created by parsing in XHTML. (mathjax/MathJax#2788) #758

Merged
merged 1 commit into from
Apr 6, 2022

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Jan 18, 2022

MathJax uses HTML parsing by default for parsing MathML strings (so that when we support HTML-in-MathML, it should work). But in an XHTML document, the parsing structure is not the same as in HTML, so this PR alters the HTML adaptor to work with that structure as well.

@dpvc dpvc requested a review from zorkow January 18, 2022 14:15
Copy link
Member

@zorkow zorkow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see that the solution works, although I find it rather broad.

So for future considerations, here are a couple of points:

  • When using the HTMLAdaptor I would assume it's behaviour to correspond to HTML. If there is no head or body something is wrong with the document and I (developer or client) would have to do something with that information.
  • Instead of conflating xhtml and html we could have an XHTMLAdaptor.
  • We do have a chooseAdaptor and a browserAdaptor which could ensure that the right one is chosen depending on the document.

@dpvc dpvc added this to the 3.2.1 milestone Feb 22, 2022
@dpvc
Copy link
Member Author

dpvc commented Feb 22, 2022

The issue occurs where a document fragment is parsed. In this case, it was the MathML that was being parsed as a string, like <math><mi>x</mi></math>, which is not a complete document. I suppose we could put <!DOCTYPE html><html><head><title>None</title></head><body> and </body></html> around the math string instead, but it's not usually necessary. (I include the <title> tags because it is a required tag for an HTML document.) That could be done here:

let mathml = this.executeFilters(this.preFilters, math, document, math.math || '<math></math>');
let doc = this.checkForErrors(this.adaptor.parse(mathml, 'text/' + this.options['parseAs']));
let body = this.adaptor.body(doc);

Would that be better? There are a couple of other places that might be necessary (adaptor.parse() is used in several places).

@dpvc
Copy link
Member Author

dpvc commented Feb 22, 2022

The chooseAdaptor was really just for testing purposes so that the same code could be run in node and in the browser.

If you wanted to use it for choosing between HTMLadaptor, the liteAdaptor (as it does now), and a proposed XHTMLadaptor, then any component that includes it would have to include all three adaptors, enlarging the component file for very little reason (there is no real reason to have the liteAdaptor in the browser, even if it is only 20K).

@zorkow
Copy link
Member

zorkow commented Apr 6, 2022

I see and agree that we might not want to extend the chooseAdaptor then.
In the long run it might consider moving the chooseAdaptor to the demo repository, rather than keeping it in the main code base (the @fileoverview comment is incorrect anyway).

@dpvc dpvc merged commit 588d515 into develop Apr 6, 2022
@dpvc dpvc deleted the issue2788 branch April 6, 2022 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants