feat: implement msub tag use case

This commit is contained in:
Alexandre Nunes 2020-09-15 12:22:27 -03:00
parent ce30359447
commit a1be62bf19
3 changed files with 26 additions and 4 deletions

View File

@ -5,7 +5,6 @@ import {
MO,
MN,
MSqrt,
MSup,
MFenced,
MFrac,
MRoot,
@ -15,6 +14,8 @@ import {
MError,
MOver,
MPhantom,
MSup,
MSub,
} from './mathml-tags';
export class Dispatcher {
@ -42,8 +43,6 @@ export class Dispatcher {
return new MN(this._value, this._attributes, this._children);
case 'msqrt':
return new MSqrt(this._value, this._attributes, this._children);
case 'msup':
return new MSup(this._value, this._attributes, this._children);
case 'mfenced':
return new MFenced(this._value, this._attributes, this._children);
case 'mfrac':
@ -60,6 +59,10 @@ export class Dispatcher {
return new MOver(this._value, this._attributes, this._children);
case 'mphantom':
return new MPhantom(this._value, this._attributes, this._children);
case 'msup':
return new MSup(this._value, this._attributes, this._children);
case 'msub':
return new MSub(this._value, this._attributes, this._children);
case 'mrow':
case 'mpadded':
return new GenericContentWrapperTag(this._name, this._value, this._attributes, this._children);

View File

@ -0,0 +1,18 @@
import { MathMLTag } from './MathMLTag';
import { BracketWrapper, ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../errors';
export class MSub extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
super('msub', value, attributes, children);
}
convert(): string {
if (this._children.length !== 2) throw new InvalidNumberOfChild(this._name, 2, this._children.length);
const base = this._children[0].convert();
const exponent = this._children[1].convert();
return `${new ParenthesisWrapper().wrapIfMoreThanOneChar(base)}_${new BracketWrapper().wrap(exponent)}`;
}
}

View File

@ -4,7 +4,6 @@ export { MI } from './MI';
export { MO } from './MO';
export { MN } from './MN';
export { MSqrt } from './MSqrt';
export { MSup } from './MSup';
export { MFenced } from './MFenced';
export { MFrac } from './MFrac';
export { MRoot } from './MRoot';
@ -14,3 +13,5 @@ export { MEnclose } from './MEnclose';
export { MError } from './MError';
export { MOver } from './MOver';
export { MPhantom } from './MPhantom';
export { MSup } from './MSup';
export { MSub } from './MSub';