-
Notifications
You must be signed in to change notification settings - Fork 210
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
Add ability to serialize annotation-xml content. #678
Conversation
An example that used to fail is something like <math xmlns="http://www.w3.org/1998/Math/MathML" display="block">
<semantics>
<annotation-xml encoding="application/xhtml+xml">
<input style="width: 1em;" xmlns="http://www.w3.org/1999/xhtml">
</annotation-xml>
</semantics>
</math> This construction is used by the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have my doubts about whether self-closing tags are handled correctly.
ts/adaptors/lite/Parser.ts
Outdated
'<' + tag + (attributes ? ' ' + attributes : '') + '>' | ||
+ (SELF_CLOSING[tag] ? '' : adaptor.innerHTML(node) + '</' + tag + '>'); | ||
'<' + tag + (attributes ? ' ' + attributes : '') | ||
+ (SELF_CLOSING[tag] ? (xml ? ' />' : '>') : '>' + adaptor.innerHTML(node) + '</' + tag + '>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In XML any self-closing tag will close, regardless of whether there is innerHTML
or not. Is that really intended?
In other words: self_closing
is not the same as an empty tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The purpose, here, is to get HTML to serialize as XML. I'm not trying to handle all empty tags as self closing, as <tag></tag>
is valid in that case. This is to handle HTML where something like <input...>
doesn't have a close tag or a />
, but needs to in order to be used in <annotation-xml>
(unclosed tags cause parsing errors otherwise). The SELF_CLOSING
array lists those, and innerHTML
uses that to generates HTML that doesn't have a close tag when it is not needed in HTML (like for <input>
). We don't want to do that for XML output. Everything else gets a close tag already, so that is why SELF_CLOSING
is the trigger for />
in this case. Again, it is not about empty content (though it could be extended to do that, but that wasn't the intent).
I do see, however, that innerHTML
isn't the right thing to use, here, as the content needs to be serialized as XML as well. So I will have to fix that.
…f-closing tags, not HTML ones
OK, I adjusted the algorithm. See if you like that better. |
I do. |
This PR adds a
serializeXML()
method for the DOMadaptor, and implements it in the HTML and Lite adaptors. This is then used by theXMLNode
class to get its serialized version for output in serialized MathML. This allows<annotation-xml>
element that contain HTML content with self-closing tags like<input>
that don't usually produce valid XML to produce a serialized version that can be parsed by SRE as well as by MathJax. This allows<annotation-xml>
to be used with the assistive tools.