Implemented mfenced for single char
This commit is contained in:
parent
72ef77a720
commit
c2610a3860
@ -239,4 +239,76 @@ describe('#convert', () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('given math string with mfenced with single content and no attr', () => {
|
||||
test('convert mfenced wrapping it content in dots', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<mfenced>
|
||||
<mn>3</mn>
|
||||
</mfenced>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\left.3\\right.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given math string with mfenced with single content and open attribute in parenthesis char', () => {
|
||||
test('convert mfenced wrapping it content between parenthesis and dot', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<mfenced open="(">
|
||||
<mn>3</mn>
|
||||
</mfenced>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\left(3\\right.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given math string with mfenced with single content and open and closes attributes in parenthesis char', () => {
|
||||
test('convert mfenced wrapping it content between parenthesis', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<mfenced open="(" close=")">
|
||||
<mn>3</mn>
|
||||
</mfenced>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\left(3\\right)');
|
||||
});
|
||||
});
|
||||
|
||||
describe('given math string with mfenced with single content and open attribute in parenthesis char and close attribute without value', () => {
|
||||
test('convert mfenced wrapping it content between parenthesis', () => {
|
||||
const mathml = `
|
||||
<root>
|
||||
<math>
|
||||
<mfenced open="(" close>
|
||||
<mn>3</mn>
|
||||
</mfenced>
|
||||
</math>
|
||||
</root>
|
||||
`;
|
||||
|
||||
const result = MathMLToLaTeX.convert(mathml);
|
||||
|
||||
expect(result).toMatch('\\left(3\\right.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { Math, MathMLTag, MI, MO, MN, MSqrt, MRow, MSup } from './mathml-tags';
|
||||
import { Math, MathMLTag, MI, MO, MN, MSqrt, MRow, MSup, MFenced } from './mathml-tags';
|
||||
|
||||
export class Dispatcher {
|
||||
private _name: string;
|
||||
@ -29,6 +29,8 @@ export class Dispatcher {
|
||||
return new MRow(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);
|
||||
default:
|
||||
return new MathMLTag(this._name, this._value, this._attributes, this._children);
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
import { MathMLTag } from './MathMLTag';
|
||||
import { GenericWrapper } from '../../../../wrappers';
|
||||
|
||||
export class MFenced extends MathMLTag {
|
||||
private _wrapper: GenericWrapper;
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
convert(): string {
|
||||
return this._wrapper.wrap(this._mapChildrenToLaTeX().join(' '));
|
||||
}
|
||||
}
|
@ -6,3 +6,4 @@ export { MN } from './MN';
|
||||
export { MSqrt } from './MSqrt';
|
||||
export { MRow } from './MRow';
|
||||
export { MSup } from './MSup';
|
||||
export { MFenced } from './MFenced';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { Wrapper } from './Wrapper';
|
||||
|
||||
export class BracketWrapper extends Wrapper {
|
||||
protected _openChar = '{';
|
||||
protected _closeChar = '}';
|
||||
protected _open = '{';
|
||||
protected _close = '}';
|
||||
}
|
||||
|
12
src/wrappers/GenericWrapper.ts
Normal file
12
src/wrappers/GenericWrapper.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Wrapper } from './Wrapper';
|
||||
|
||||
export class GenericWrapper extends Wrapper {
|
||||
protected _open: string;
|
||||
protected _close: string;
|
||||
|
||||
constructor(open: string, close: string) {
|
||||
super();
|
||||
this._open = '\\left' + open;
|
||||
this._close = '\\right' + close;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import { Wrapper } from './Wrapper';
|
||||
|
||||
export class ParenthesisWrapper extends Wrapper {
|
||||
protected _openChar = '\\left(';
|
||||
protected _closeChar = '\\right)';
|
||||
protected _open = '\\left(';
|
||||
protected _close = '\\right)';
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
export abstract class Wrapper {
|
||||
protected abstract _openChar: string;
|
||||
protected abstract _closeChar: string;
|
||||
protected abstract _open: string;
|
||||
protected abstract _close: string;
|
||||
|
||||
wrap(str: string): string {
|
||||
return this._openChar + str + this._closeChar;
|
||||
return this._open + str + this._close;
|
||||
}
|
||||
|
||||
wrapIfMoreThanOneChar(str: string): string {
|
||||
|
@ -1,2 +1,3 @@
|
||||
export { BracketWrapper } from './BracketWrapper';
|
||||
export { ParenthesisWrapper } from './ParenthesisWrapper';
|
||||
export { GenericWrapper } from './GenericWrapper';
|
||||
|
Loading…
Reference in New Issue
Block a user