Sha256: 960a87d6d81dc5f117a8ae10bd34b501a10623350fc6edfb5c814a2032f80941

Contents?: true

Size: 1.29 KB

Versions: 7

Compression:

Stored size: 1.29 KB

Contents

/**
 * This is the ParseError class, which is the main error thrown by KaTeX
 * functions when something has gone wrong. This is used to distinguish internal
 * errors from errors in the expression that the user provided.
 */
function ParseError(message, lexer, position) {
    var error = "KaTeX parse error: " + message;

    if (lexer !== undefined && position !== undefined) {
        // If we have the input and a position, make the error a bit fancier

        // Prepend some information
        error += " at position " + position + ": ";

        // Get the input
        var input = lexer._input;
        // Insert a combining underscore at the correct position
        input = input.slice(0, position) + "\u0332" +
            input.slice(position);

        // Extract some context from the input and add it to the error
        var begin = Math.max(0, position - 15);
        var end = position + 15;
        error += input.slice(begin, end);
    }

    // Some hackery to make ParseError a prototype of Error
    // See http://stackoverflow.com/a/8460753
    var self = new Error(error);
    self.name = "ParseError";
    self.__proto__ = ParseError.prototype;

    self.position = position;
    return self;
}

// More hackery
ParseError.prototype.__proto__ = Error.prototype;

module.exports = ParseError;

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
hyhyhy-1.0.0 lib/hyhyhy/structure/_includes/katex/src/ParseError.js
hyhyhy-0.0.9 lib/hyhyhy/structure/_includes/katex/src/ParseError.js
hyhyhy-0.0.8 lib/hyhyhy/structure/_includes/katex/src/ParseError.js
hyhyhy-0.0.7 lib/hyhyhy/structure/_includes/katex/src/ParseError.js
hyhyhy-0.0.6 lib/hyhyhy/structure/_includes/katex/src/ParseError.js
hyhyhy-0.0.5 lib/hyhyhy/structure/_includes/katex/src/ParseError.js
hyhyhy-0.0.4 lib/hyhyhy/structure/_includes/katex/src/ParseError.js