refactor: new project folder structure

This commit is contained in:
Alexandre Nunes 2020-09-20 16:53:56 -03:00
parent f05609b8b7
commit 8fcb04cf16
39 changed files with 62 additions and 61 deletions

@ -1,4 +1,4 @@
import MathMLStringToMathMLInterfaces from '../../../src/converters/mathml-string-to-mathml-interfaces';
import XmlToMathMLAdapter from '../../../src/converters/xml-mathml-to-latex/xml-to-mathml';
import {
singleMi,
singleMiNoRoot,
@ -12,7 +12,7 @@ describe('#convert', () => {
it('return array with single mathml interface of name math and child mi', () => {
const mathmlString = singleMi;
const result = new MathMLStringToMathMLInterfaces(mathmlString).convert();
const result = new XmlToMathMLAdapter(mathmlString).convert();
expect(result.length).toBe(1);
expect(result[0]).toMatchObject({
@ -28,7 +28,7 @@ describe('#convert', () => {
test('return array with single mathml interface of name math and child mi', () => {
const mathmlString = singleMiNoRoot;
const result = new MathMLStringToMathMLInterfaces(mathmlString).convert();
const result = new XmlToMathMLAdapter(mathmlString).convert();
expect(result.length).toBe(1);
expect(result[0]).toMatchObject({
@ -44,7 +44,7 @@ describe('#convert', () => {
test('return content in a three and keep value on each child', () => {
const mathmlString = mrow;
const result = new MathMLStringToMathMLInterfaces(mathmlString).convert();
const result = new XmlToMathMLAdapter(mathmlString).convert();
expect(result.length).toBe(1);
expect(result[0]).toMatchObject({
@ -71,7 +71,7 @@ describe('#convert', () => {
test('add attributes to children related with name mfenced', () => {
const mathmlString = mfencedWithSeparatorAttribute;
const result = new MathMLStringToMathMLInterfaces(mathmlString).convert();
const result = new XmlToMathMLAdapter(mathmlString).convert();
expect(result.length).toBe(1);
expect(result[0]).toMatchObject({
@ -98,7 +98,7 @@ describe('#convert', () => {
test('add attributes to children related with name mfenced', () => {
const mathmlString = mfencedWithBrokenAttribute;
const result = new MathMLStringToMathMLInterfaces(mathmlString).convert();
const result = new XmlToMathMLAdapter(mathmlString).convert();
expect(result.length).toBe(1);
expect(result[0]).toMatchObject({

@ -1,3 +0,0 @@
import { MathMLInterfacesToLaTeX } from './MathMLInterfacesToLaTeX';
export default MathMLInterfacesToLaTeX;

@ -1,18 +0,0 @@
import { MathML } from '../../interfaces/MathML';
import MathMLInterfacesToLaTeX from '../mathml-interfaces-to-latex';
import MathMLStringToInterfaces from '../mathml-string-to-mathml-interfaces';
export class MathMLToLaTeX {
constructor(private _mathml: string) {
this._mathml = _mathml;
}
static convert(_mathml: string): string {
return new MathMLToLaTeX(_mathml).convert();
}
convert(): string {
const mathmlInterfaces: MathML[] = new MathMLStringToInterfaces(this._mathml).convert();
return new MathMLInterfacesToLaTeX(mathmlInterfaces).convert();
}
}

@ -1,2 +0,0 @@
import { MathMLStringToMathMLInterfaces } from './MathMLStringToMathMLInterfaces';
export default MathMLStringToMathMLInterfaces;

@ -0,0 +1,18 @@
import { MathML } from '../../interfaces/MathML';
import MathmlToLatex from './xml-to-mathml/mathml-to-latex';
import XmlToMathml from './xml-to-mathml';
export class XmlMathMLToLaTeX {
constructor(private _mathml: string) {
this._mathml = _mathml;
}
static convert(_mathml: string): string {
return new XmlMathMLToLaTeX(_mathml).convert();
}
convert(): string {
const mathmlInterfaces: MathML[] = new XmlToMathml(this._mathml).convert();
return new MathmlToLatex(mathmlInterfaces).convert();
}
}

@ -0,0 +1,3 @@
import { XmlMathMLToLaTeX } from './XmlMathMLToLaTeX';
export default XmlMathMLToLaTeX;

@ -1,6 +1,6 @@
import { MathML } from '../../interfaces/MathML';
import { MathML } from '../../../interfaces/MathML';
export class ElementsToMathMLInterfacesConvertor {
export class ElementsToMathMLAdapter {
convert(els: Element[]): MathML[] {
return els.filter((el: Element) => el.tagName !== undefined).map((el: Element) => this._convertElement(el));
}
@ -16,7 +16,8 @@ export class ElementsToMathMLInterfacesConvertor {
private _convertElementAttributes(attributes: NamedNodeMap): Record<string, string> {
return Array.from(attributes).reduce(
(acc, attr: Attr) => Object.assign({ [attr.nodeName]: attr.nodeValue === attr.nodeName ? '' : attr.nodeValue }, acc),
(acc, attr: Attr) =>
Object.assign({ [attr.nodeName]: attr.nodeValue === attr.nodeName ? '' : attr.nodeValue }, acc),
{},
);
}
@ -27,6 +28,6 @@ export class ElementsToMathMLInterfacesConvertor {
}
private _isThereAnyNoTextNode(children: NodeListOf<ChildNode>): boolean {
return Array.from(children).some(child => child.nodeName !== '#text');
return Array.from(children).some((child) => child.nodeName !== '#text');
}
}

@ -2,18 +2,18 @@ import xmldom = require('xmldom');
import { DOMParser } from 'xmldom';
import { ErrorHandler } from './ErrorHandler';
import { MathML } from '../../interfaces/MathML';
import { ElementsToMathMLInterfacesConvertor } from './ElementsToMathMLInterfacesConvertor';
import { MathML } from '../../../interfaces/MathML';
import { ElementsToMathMLAdapter } from './ElementsToMathMLAdapter';
export class MathMLStringToMathMLInterfaces {
export class XmlToMathMLAdapter {
private _xmlDOM: DOMParser;
private _errorHandler: ErrorHandler;
private _elementsConvertor: ElementsToMathMLInterfacesConvertor;
private _elementsConvertor: ElementsToMathMLAdapter;
constructor(private _xml: string) {
this._xml = this._removeLineBreaks(_xml);
this._elementsConvertor = new ElementsToMathMLInterfacesConvertor();
this._elementsConvertor = new ElementsToMathMLAdapter();
this._errorHandler = new ErrorHandler();
this._xmlDOM = new xmldom.DOMParser({

@ -0,0 +1,2 @@
import { XmlToMathMLAdapter } from './XmlToMathMLAdapter';
export default XmlToMathMLAdapter;

@ -1,8 +1,8 @@
import { MathML } from '../../interfaces/MathML';
import Dispatcher from './mathml-tag-to-latex';
import { MathMLTag } from './mathml-tag-to-latex/mathml-tags';
import { MathML } from '../../../../interfaces/MathML';
import Dispatcher from './mathml-to-latex';
import { MathMLTag } from './mathml-to-latex/mathml-tags';
export class MathMLInterfacesToLaTeX {
export class MathMLToLaTeX {
constructor(private _mathMLInterfaces: MathML[]) {
this._mathMLInterfaces = _mathMLInterfaces;
}

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { InvalidNumberOfChild } from '../../../../errors';
import { latexAccents } from '../../../../syntax/latexAccents';
import { InvalidNumberOfChild } from '../../../../../../errors';
import { latexAccents } from '../../../../../../syntax/latexAccents';
export class GenericUnderOverTag extends MathMLTag {
convert(): string {

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { GenericWrapper } from '../../../../utils/wrappers';
import { JoinWithManySeparators } from '../../../../utils';
import { GenericWrapper } from '../../../../../../utils/wrappers';
import { JoinWithManySeparators } from '../../../../../../utils';
export class MFenced extends MathMLTag {
private readonly _open: string;

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { InvalidNumberOfChild } from '../../../../errors';
import { ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../../../errors';
import { ParenthesisWrapper } from '../../../../../../utils/wrappers';
export class MFrac extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,5 +1,5 @@
import { MathMLTag } from './MathMLTag';
import { allMathSymbolsByChar, allMathSymbolsByGlyph } from '../../../../syntax';
import { allMathSymbolsByChar, allMathSymbolsByGlyph } from '../../../../../../syntax';
export class MI extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../errors';
import { ParenthesisWrapper } from '../../../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../../../errors';
export class MMultiscripts extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,5 +1,5 @@
import { MathMLTag } from './MathMLTag';
import { allMathOperatorsByChar, allMathOperatorsByGlyph } from '../../../../syntax';
import { allMathOperatorsByChar, allMathOperatorsByGlyph } from '../../../../../../syntax';
export class MO extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,5 +1,5 @@
import { MathMLTag } from './MathMLTag';
import { InvalidNumberOfChild } from '../../../../errors';
import { InvalidNumberOfChild } from '../../../../../../errors';
export class MRoot extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { BracketWrapper, ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../errors';
import { BracketWrapper, ParenthesisWrapper } from '../../../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../../../errors';
export class MSub extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { BracketWrapper, ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../errors';
import { BracketWrapper, ParenthesisWrapper } from '../../../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../../../errors';
export class MSubsup extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,6 +1,6 @@
import { MathMLTag } from './MathMLTag';
import { BracketWrapper, ParenthesisWrapper } from '../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../errors';
import { BracketWrapper, ParenthesisWrapper } from '../../../../../../utils/wrappers';
import { InvalidNumberOfChild } from '../../../../../../errors';
export class MSup extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,5 +1,5 @@
import { MathMLTag } from './MathMLTag';
import { InvalidNumberOfChild } from '../../../../errors';
import { InvalidNumberOfChild } from '../../../../../../errors';
export class MUnderover extends MathMLTag {
constructor(value: string, attributes: Record<string, string>, children: MathMLTag[]) {

@ -1,3 +1,3 @@
import MathMLToLaTeX from './converters/mathml-string-to-latex';
import MathMLToLaTeX from './converters/xml-mathml-to-latex';
export default MathMLToLaTeX;