Implemented msrqrt tag case
This commit is contained in:
parent
312e52d355
commit
702bd8ba92
@ -66,4 +66,83 @@ describe('#convert', () => {
|
||||
expect(result).toMatch('2 + 2');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given math string with msqrt', () => {
|
||||
describe('single mn tag is inside', () => {
|
||||
test('convert msqrt wrapping its content inside sqrt LaTeX command', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<msqrt>
|
||||
<mn>2</mn>
|
||||
</msqrt>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\sqrt{2}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('there are many children inside sqrt tag', () => {
|
||||
test('convert msqrt wrapping its content inside sqrt LaTeX command', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<msqrt>
|
||||
<mn>2</mn>
|
||||
<mo>+</mo>
|
||||
<mn>2</mn>
|
||||
</msqrt>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\sqrt{2 + 2}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sqrt tag has single mrow child', () => {
|
||||
test('convert msqrt wrapping its content inside sqrt LaTeX command', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<msqrt>
|
||||
<mrow>
|
||||
<mn>2</mn>
|
||||
<mo>+</mo>
|
||||
<mn>2</mn>
|
||||
</mrow>
|
||||
</msqrt>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\sqrt{2 + 2}');
|
||||
});
|
||||
});
|
||||
|
||||
describe('there is no content inside msqrt', () => {
|
||||
test('empty sqrt is given', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<msqrt>
|
||||
</msqrt>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\sqrt{}');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Math, MathMLTag, MI, MO, MN, MRow } from './mathml-tags';
|
||||
import { Math, MathMLTag, MI, MO, MN, MSqrt, MRow } from './mathml-tags';
|
||||
|
||||
export class Dispatcher {
|
||||
private _name: string;
|
||||
@ -23,6 +23,8 @@ export class Dispatcher {
|
||||
return new MO(this._value, this._attributes, this._children);
|
||||
case 'mn':
|
||||
return new MN(this._value, this._attributes, this._children);
|
||||
case 'msqrt':
|
||||
return new MSqrt(this._value, this._attributes, this._children);
|
||||
case 'mrow':
|
||||
return new MRow(this._value, this._attributes, this._children);
|
||||
default:
|
||||
|
@ -0,0 +1,12 @@
|
||||
import { MathMLTag } from './MathMLTag';
|
||||
|
||||
export class MSqrt extends MathMLTag {
|
||||
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
|
||||
super('msqrt', value, attributes, children);
|
||||
}
|
||||
|
||||
convert(): string {
|
||||
const content = this._mapChildrenToLaTeX().join(' ');
|
||||
return `\\sqrt{${content}}`;
|
||||
}
|
||||
}
|
@ -3,4 +3,5 @@ export { MathMLTag } from './MathMLTag';
|
||||
export { MI } from './MI';
|
||||
export { MO } from './MO';
|
||||
export { MN } from './MN';
|
||||
export { MSqrt } from './MSqrt';
|
||||
export { MRow } from './MRow';
|
||||
|
Loading…
Reference in New Issue
Block a user