UNPKG

@qtikit/mathml-to-latex

Version:

A JavaScript tool to convert mathml string to LaTeX string

43 lines (42 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ErrorHandler = void 0; var ErrorHandler = /** @class */ (function () { function ErrorHandler() { this._errors = []; this.errorLocator = {}; } ErrorHandler.prototype.fixError = function (xml, errorMessage) { if (!this._isMissingAttributeValueError(errorMessage)) return xml; this._errors.push(errorMessage); return this._fixMissingAttribute(errorMessage, xml); }; ErrorHandler.prototype.isThereAnyErrors = function () { return this._errors.length > 0; }; ErrorHandler.prototype.cleanErrors = function () { this._errors = []; }; ErrorHandler.prototype._fixMissingAttribute = function (errorMessage, xml) { var missingAttribute = errorMessage.split('"')[1]; if (missingAttribute) return xml.replace(this._matchMissingValueForAttribute(missingAttribute), ''); while (this._mathGenericMissingValue().exec(xml)) { xml = xml.replace(this._mathGenericMissingValue(), '$1$3'); } return xml; }; ErrorHandler.prototype._matchMissingValueForAttribute = function (attribute) { return new RegExp("(".concat(attribute, "=(?!(\"|')))|(").concat(attribute, "(?!(\"|')))"), 'gm'); }; ErrorHandler.prototype._mathGenericMissingValue = function () { return /(\<.* )(\w+=(?!\"|\'))(.*\>)/gm; }; ErrorHandler.prototype._isMissingAttributeValueError = function (errorMessage) { return ((!!errorMessage.includes('attribute') && !!errorMessage.includes('missed')) || errorMessage.includes('attribute value missed')); }; return ErrorHandler; }()); exports.ErrorHandler = ErrorHandler;