Cleanup MathML <mrow>, <mtext>, <mn> (#1338)

* Avoid unnecessary <mrow> wrapping

buildMathML gains two helpers:
* `makeRow` helper wraps an array of nodes in `<mrow>`,
  unless the array has length 1, in which case no wrapping is necessary.
* `buildExpressionRow` for common case of `makeRow(buildExpression(...))`

* Combine adjacent <mtext>s in all cases

No more need for `makeTextRow` helper or anything fancy in text MathML handler.

* Concatenate <mn>s and decimal point into single <mn>

Fix #203

* Fix snapshots
This commit is contained in:
Erik Demaine
2018-05-21 22:56:34 -04:00
committed by GitHub
parent ef9cd5c172
commit 485c509879
8 changed files with 104 additions and 113 deletions

View File

@@ -57,6 +57,35 @@ exports[`A MathML builder accents turn into <mover accent="true"> in MathML 1`]
`;
exports[`A MathML builder should concatenate digits into single <mn> 1`] = `
<math>
<semantics>
<mrow>
<mi>
sin
</mi>
<mo>
</mo>
<mi>
α
</mi>
<mo>
=
</mo>
<mn>
0.34
</mn>
</mrow>
<annotation encoding="application/x-tex">
\\sin{\\alpha}=0.34
</annotation>
</semantics>
</math>
`;
exports[`A MathML builder should generate <mphantom> nodes for \\phantom 1`] = `
<math>
@@ -87,11 +116,9 @@ exports[`A MathML builder should generate the right types of nodes 1`] = `
<mo>
</mo>
<mrow>
<mi>
x
</mi>
</mrow>
<mi>
x
</mi>
<mo>
+
</mo>
@@ -339,11 +366,9 @@ exports[`A MathML builder should render mathchoice as if there was nothing 3`] =
<mi>
x
</mi>
<mrow>
<mi>
T
</mi>
</mrow>
<mi>
T
</mi>
</msub>
</mrow>
<annotation encoding="application/x-tex">
@@ -367,11 +392,9 @@ exports[`A MathML builder should render mathchoice as if there was nothing 4`] =
<mi>
y
</mi>
<mrow>
<mi>
T
</mi>
</mrow>
<mi>
T
</mi>
</msub>
</msub>
</mrow>
@@ -387,8 +410,8 @@ exports[`A MathML builder should set href attribute for href appropriately 1`] =
<math>
<semantics>
<mrow href="http://example.org">
<mi>
<mrow>
<mi href="http://example.org">
α
</mi>
</mrow>
@@ -406,11 +429,9 @@ exports[`A MathML builder should use <menclose> for colorbox 1`] = `
<semantics>
<mrow>
<menclose mathbackground="red">
<mrow>
<mtext>
b
</mtext>
</mrow>
<mtext>
b
</mtext>
</menclose>
</mrow>
<annotation encoding="application/x-tex">
@@ -427,11 +448,9 @@ exports[`A MathML builder should use <mpadded> for raisebox 1`] = `
<semantics>
<mrow>
<mpadded voffset="0.25em">
<mrow>
<mtext>
b
</mtext>
</mrow>
<mtext>
b
</mtext>
</mpadded>
</mrow>
<annotation encoding="application/x-tex">
@@ -507,22 +526,9 @@ exports[`A MathML builder tags use <mlabeledtr> 1`] = `
<mtable side="right">
<mlabeledtr>
<mtd>
<mrow>
<mtext>
(
</mtext>
<mrow>
<mtext>
h
</mtext>
<mtext>
i
</mtext>
</mrow>
<mtext>
)
</mtext>
</mrow>
<mtext>
(hi)
</mtext>
</mtd>
<mtd>
<mrow>

View File

@@ -35,6 +35,10 @@ describe("A MathML builder", function() {
expect(getMathML("\\sin{x}+1\\;\\text{a}")).toMatchSnapshot();
});
it('should concatenate digits into single <mn>', () => {
expect(getMathML("\\sin{\\alpha}=0.34")).toMatchSnapshot();
});
it('should make prime operators into <mo> nodes', () => {
expect(getMathML("f'")).toMatchSnapshot();
});