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';
|
import { JoinWithManySeparators } from '../../../../utils';
|
||||||
|
|
||||||
export class MFenced extends MathMLTag {
|
export class MFenced extends MathMLTag {
|
||||||
private _wrapper: GenericWrapper;
|
private readonly _open: string;
|
||||||
private _separators: string[];
|
private readonly _close: string;
|
||||||
|
private readonly _separators: string[];
|
||||||
|
|
||||||
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
|
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {
|
||||||
super('mfenced', value, attributes, children);
|
super('mfenced', value, attributes, children);
|
||||||
|
|
||||||
const open: string = this._attributes.open || '(';
|
this._open = this._attributes.open || '(';
|
||||||
const close: string = this._attributes.close || ')';
|
this._close = this._attributes.close || ')';
|
||||||
this._wrapper = new GenericWrapper(open, close);
|
|
||||||
|
|
||||||
this._separators = Array.from(this._attributes.separators || '');
|
this._separators = Array.from(this._attributes.separators || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
convert(): string {
|
convert(): string {
|
||||||
const withoutWrapper = JoinWithManySeparators.join(this._mapChildrenToLaTeX(), this._separators);
|
return new Vector(this._open, this._close, this._separators).apply(this._mapChildrenToLaTeX());
|
||||||
return this._wrapper.wrap(withoutWrapper);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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