Remove double encoding in MathML via Unicode MathML spaces (#1813)

* Remove double encoding in MathML via Unicode MathML spaces

We used to have a complex mechanic for escaping strings, marking them as
`needsEscape = false`, and then not escaping those strings (for
combining strings in `\operatorname`).  But this doesn't really work
with `render`ing directly to a node, as `document.createTextNode` can't
be stopped from escaping.

I've thus removed this mechanic, which required the following changes:

* Switch MathML "smart space" encoding to use Unicode instead of
  `&LongNames;` (which weren't working with `render` for the same reason).
* Hack our HTML/MathML serializer to not use `String.trim`, which wrecks
  havoc with emitted Unicode spaces.

Now `toText()` doesn't escape, so strings concatenate in unescaped form,
and `toHTML()` only does the necessary escaping.  Thus fix #1782.

* Fix src/utils.js

Co-Authored-By: edemaine <edemaine@mit.edu>

* Fix src/mathMLTree.js documentation

Co-Authored-By: edemaine <edemaine@mit.edu>

* Remove trim hack thanks to diffable-html@4.0.0

* Switch back to jest-serializer-html

* Update mathMLTree.js
This commit is contained in:
Erik Demaine
2019-01-01 11:55:44 -05:00
committed by ylemkimon
parent f5234a2f01
commit 647c661db0
6 changed files with 53 additions and 53 deletions

View File

@@ -46,6 +46,7 @@ exports[`A MathML builder \\text fonts become mathvariant 1`] = `
bold
</mtext>
<mtext>
 
</mtext>
<mtext mathvariant="bold-italic">
italic
@@ -68,6 +69,7 @@ exports[`A MathML builder \\text fonts become mathvariant 1`] = `
bold
</mtext>
<mtext>
 
</mtext>
<mtext mathvariant="sans-serif-bold-italic">
italic
@@ -91,6 +93,7 @@ exports[`A MathML builder \\text fonts become mathvariant 1`] = `
bold
</mtext>
<mtext>
 
</mtext>
<mtext mathvariant="monospace">
italic
@@ -300,7 +303,7 @@ exports[`A MathML builder should generate the right types of nodes 1`] = `
1
</mn>
<mtext>
&ThickSpace;
</mtext>
<mtext>
a
@@ -344,7 +347,7 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} correc
<msub>
<mo>
<mi mathvariant="normal">
lim&ThinSpace;sup
limsup
</mi>
<mo>
@@ -379,7 +382,7 @@ exports[`A MathML builder should output \\limsup_{x \\rightarrow \\infty} in dis
<munder>
<mo>
<mi mathvariant="normal">
lim&ThinSpace;sup
limsup
</mi>
<mo>
@@ -702,61 +705,61 @@ exports[`A MathML builder special spaces render specially 1`] = `
<semantics>
<mrow>
<mtext>
&ThinSpace;
</mtext>
<mtext>
&ThinSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&ThickSpace;
</mtext>
<mtext>
&ThickSpace;
</mtext>
<mtext>
&NegativeThinSpace;
</mtext>
<mtext>
&NegativeThinSpace;
</mtext>
<mtext>
&NegativeMediumSpace;
</mtext>
<mtext>
&NegativeThickSpace;
</mtext>
<mtext>
&VeryThinSpace;
</mtext>
<mtext>
&ThinSpace;
</mtext>
<mtext>
&MediumSpace;
</mtext>
<mtext>
&ThickSpace;
</mtext>
<mtext>
&NegativeVeryThinSpace;
</mtext>
<mtext>
&NegativeThinSpace;
</mtext>
<mtext>
&NegativeMediumSpace;
</mtext>
<mtext>
&NegativeThickSpace;
</mtext>
</mrow>
<annotation encoding="application/x-tex">

View File

@@ -8,7 +8,7 @@ import {
expectKaTeX, expectEquivalent,
} from "./helpers";
// Serializer support
// JSON serializer
const typeFirstCompare = (a, b) => {
if (a.key === 'type') {