refactor: move mfenced vector case to external class
This commit is contained in:
parent
605eaed457
commit
6921b8869f
@ -3,21 +3,37 @@ import { GenericWrapper } from '../../../../utils/wrappers';
|
||||
import { JoinWithManySeparators } from '../../../../utils';
|
||||
|
||||
export class MFenced extends MathMLTag {
|
||||
private _wrapper: GenericWrapper;
|
||||
private _separators: string[];
|
||||
private readonly _open: string;
|
||||
private readonly _close: string;
|
||||
private readonly _separators: string[];
|
||||
|
||||
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
|
||||
super('mfenced', value, attributes, children);
|
||||
|
||||
const open: string = this._attributes.open || '(';
|
||||
const close: string = this._attributes.close || ')';
|
||||
this._wrapper = new GenericWrapper(open, close);
|
||||
|
||||
this._open = this._attributes.open || '(';
|
||||
this._close = this._attributes.close || ')';
|
||||
this._separators = Array.from(this._attributes.separators || '');
|
||||
}
|
||||
|
||||
convert(): string {
|
||||
const withoutWrapper = JoinWithManySeparators.join(this._mapChildrenToLaTeX(), this._separators);
|
||||
return this._wrapper.wrap(withoutWrapper);
|
||||
return new Vector(this._open, this._close, this._separators).apply(this._mapChildrenToLaTeX());
|
||||
}
|
||||
}
|
||||
|
||||
class Vector {
|
||||
private readonly _open: string;
|
||||
private readonly _close: string;
|
||||
private readonly _separators: string[];
|
||||
|
||||
constructor(open: string, close: string, separators: string[]) {
|
||||
this._open = open;
|
||||
this._close = close;
|
||||
this._separators = separators;
|
||||
}
|
||||
|
||||
apply(latexContents: string[]): string {
|
||||
const contentWithoutWrapper = JoinWithManySeparators.join(latexContents, this._separators);
|
||||
|
||||
return new GenericWrapper(this._open, this._close).wrap(contentWithoutWrapper);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user