feat: add multiscripts without prescripts use case

This commit is contained in:
Alexandre Nunes 2020-09-20 16:00:55 -03:00
parent a64cd5f730
commit 7079d2f558
3 changed files with 30 additions and 0 deletions

View File

@ -45,6 +45,8 @@ export class Dispatcher {
return new MathMLTags.MSub(this._value, this._attributes, this._children);
case 'msubsup':
return new MathMLTags.MSubsup(this._value, this._attributes, this._children);
case 'mmultiscripts':
return new MathMLTags.MMultiscripts(this._value, this._attributes, this._children);
case 'mtext':
return new MathMLTags.MText(this._value, this._attributes, this._children);
case 'munderover':

View File

@ -0,0 +1,27 @@
import { MathMLTag } from './MathMLTag';
import { BracketWrapper, ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../errors';
export class MMultiscripts extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
super('mmultiscripts', value, attributes, children);
}
convert(): string {
if (this._children.length !== 3) throw new InvalidNumberOfChild(this._name, 2, this._children.length);
const base = this._children[0].convert();
const sub = this._children[1].convert();
const sup = this._children[2].convert();
const wrappedSub = new BracketWrapper().wrap(sub);
const wrappedSup = new BracketWrapper().wrap(sup);
return `${this._wrapInParenthesisIfThereIsSpace(base)}_${wrappedSub}^${wrappedSup}`;
}
private _wrapInParenthesisIfThereIsSpace(str: string): string {
if (!str.match(/\s+/g)) return str;
return new ParenthesisWrapper().wrap(str);
}
}

View File

@ -14,6 +14,7 @@ export { MPhantom } from './MPhantom';
export { MSup } from './MSup';
export { MSub } from './MSub';
export { MSubsup } from './MSubsup';
export { MMultiscripts } from './MMultiscripts';
export { MText } from './MText';
export { MUnderover } from './MUnderover';
export { MTable } from './MTable';