Merge pull request #6 from asnunes/fix-command-spacing

Fix command spacing
This commit is contained in:
Alexandre Nunes 2021-04-11 18:46:30 -03:00 committed by GitHub
commit 6b02fc8cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 23 deletions

@ -1 +1 @@
nodejs 14.15.3
nodejs 14.16.1

@ -92,6 +92,14 @@ describe('#convert', () => {
expect(result).toMatch('b');
});
it('appends space between command and next tag', () => {
const mathml = mathmlStrings.moWithCharOperatorAndMi;
const result = MathMLToLaTeX.convert(mathml);
expect(result).toMatch('a \\Rightarrow b');
});
});
});

@ -92,6 +92,18 @@ export const moWithCharOperator = `
</root>
`;
export const moWithCharOperatorAndMi = `
<root>
<math xmlns="http://www.w3.org/1998/Math/MathML">
<mstyle displaystyle="true">
<mi>a</mi>
<mo>&#x21D2;</mo>
<mi>b</mi>
</mstyle>
</math>
</root>
`;
export const mrowWithMnAndMo = `
<root>
<math>

2
package-lock.json generated

@ -1,6 +1,6 @@
{
"name": "mathml-to-latex",
"version": "1.0.0",
"version": "1.0.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {

@ -1,6 +1,6 @@
{
"name": "mathml-to-latex",
"version": "1.0.1",
"version": "1.1.0",
"description": "A JavaScript tool to convert mathml string to LaTeX string",
"main": "dist/index.js",
"types": "dist/index.d.ts",

@ -1,18 +0,0 @@
import { ToLaTeXConverter } from '../../../../domain/usecases/to-latex-converter';
import { MathMLElement } from '../../../protocols/mathml-element';
import { mathMLElementToLaTeXConverter } from '../../../helpers';
export class GenericNoSpacingWrapper implements ToLaTeXConverter {
private readonly _mathmlElement: MathMLElement;
constructor(mathElement: MathMLElement) {
this._mathmlElement = mathElement;
}
convert(): string {
return this._mathmlElement.children
.map((child) => mathMLElementToLaTeXConverter(child))
.map((converter) => converter.convert())
.join('');
}
}

@ -19,5 +19,4 @@ export { MUnderover } from './munderover';
export { MTable } from './mtable';
export { MTr } from './mtr';
export { GenericSpacingWrapper } from './generic-spacing-wrapper';
export { GenericNoSpacingWrapper } from './generic-no-spacing-wrapper';
export { GenericUnderOver } from './generic-under-over';

@ -11,7 +11,7 @@ export class MathMLElementToLatexConverterAdapter {
toLatexConverter(): ToLaTeXConverter {
const { name } = this._mathMLElement;
const Converter = fromMathMLElementToLatexConverter[name] || ToLatexConverters.GenericNoSpacingWrapper;
const Converter = fromMathMLElementToLatexConverter[name] || ToLatexConverters.GenericSpacingWrapper;
return new Converter(this._mathMLElement);
}