Skip to content

Commit 86376ee

Browse files
committed
Cleanup of MathML to avoids some common input errors.
1 parent 92c202f commit 86376ee

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/v3-lab.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,21 @@ const Lab = window.Lab = {
158158
return math;
159159
},
160160

161+
readInput() {
162+
let input = this.input.value;
163+
if (this.format !== 'MathML') {
164+
return input;
165+
}
166+
input = input.trim();
167+
if (!input.match(/^<math/)) {
168+
input = '<math>' + input;
169+
}
170+
if (!input.match(/\/math>$/)) {
171+
input += '</math>';
172+
}
173+
return input;
174+
},
175+
161176
/**
162177
* Perform the typesetting of the math in the proper format
163178
*/
@@ -175,7 +190,7 @@ const Lab = window.Lab = {
175190
// set its metrics, and link it to the text element created above, then
176191
// add it to the document's math list.
177192
//
178-
this.mathItem = this.MathItem(this.input.value, this.output);
193+
this.mathItem = this.MathItem(this.readInput(), this.output);
179194
this.doc.clear();
180195
this.doc.math.push(this.mathItem);
181196

0 commit comments

Comments
 (0)