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

Add ability to serialize annotation-xml content. #678

Merged
merged 3 commits into from
Apr 16, 2021
Merged

Conversation

dpvc
Copy link
Member

@dpvc dpvc commented Mar 31, 2021

This PR adds a serializeXML() method for the DOMadaptor, and implements it in the HTML and Lite adaptors. This is then used by the XMLNode 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.

@dpvc dpvc added this to the 3.1.3 milestone Mar 31, 2021
@dpvc dpvc requested a review from zorkow March 31, 2021 23:40
@dpvc
Copy link
Member Author

dpvc commented Mar 31, 2021

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 \forminput extension to insert input areas into MathJax expressions.

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 have my doubts about whether self-closing tags are handled correctly.

'<' + tag + (attributes ? ' ' + attributes : '') + '>'
+ (SELF_CLOSING[tag] ? '' : adaptor.innerHTML(node) + '</' + tag + '>');
'<' + tag + (attributes ? ' ' + attributes : '')
+ (SELF_CLOSING[tag] ? (xml ? ' />' : '>') : '>' + adaptor.innerHTML(node) + '</' + tag + '>');
Copy link
Member

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?

Copy link
Member Author

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.

@dpvc
Copy link
Member Author

dpvc commented Apr 14, 2021

I have my doubts about whether self-closing tags are handled correctly.

OK, I adjusted the algorithm. See if you like that better.

@dpvc dpvc requested a review from zorkow April 14, 2021 14:59
@zorkow
Copy link
Member

zorkow commented Apr 14, 2021

I have my doubts about whether self-closing tags are handled correctly.

OK, I adjusted the algorithm. See if you like that better.

I do.

@dpvc dpvc merged commit cc3ce70 into develop Apr 16, 2021
@dpvc dpvc deleted the serialize-xml branch April 16, 2021 17:29
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.

2 participants