UNPKG

mathpix-markdown-it

Version:

Mathpix-markdown-it is an open source implementation of the mathpix-markdown spec written in Typescript. It relies on the following open source libraries: MathJax v3 (to render math with SVGs), markdown-it (for standard Markdown parsing)

84 lines 2.32 kB
// Parse link destination // 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseLinkDestination = void 0; var unescapeAll = require('markdown-it/lib/common/utils').unescapeAll; function parseLinkDestination(str, pos, max) { var code, level, lines = 0, start = pos, result = { ok: false, pos: 0, lines: 0, str: '' }; if (str.charCodeAt(pos) === 0x3C /* < */) { pos++; while (pos < max) { code = str.charCodeAt(pos); if (code === 0x0A /* \n */) { return result; } if (code === 0x3E /* > */) { result.pos = pos + 1; result.str = unescapeAll(str.slice(start + 1, pos)); result.ok = true; return result; } if (code === 0x5C /* \ */ && pos + 1 < max) { pos += 2; continue; } pos++; } // no closing '>' return result; } // this should be ... } else { ... branch level = 0; var hasPoint = false; var beforeCode = -1; while (pos < max) { code = str.charCodeAt(pos); if (code === 0x20 /* space */ && hasPoint) { break; } if (code === 0x2E /* . */) { if (beforeCode !== -1 && beforeCode !== 0x2E /* . */ && beforeCode !== 0x2F /* / */) { hasPoint = true; } } // ascii control characters if (code < 0x20 || code === 0x7F) { break; } if (code === 0x5C /* \ */ && pos + 1 < max) { pos += 2; continue; } if (code === 0x28 /* ( */) { level++; } if (code === 0x29 /* ) */) { if (level === 0) { break; } level--; } pos++; beforeCode = code; } if (start === pos) { return result; } if (level !== 0) { return result; } result.str = unescapeAll(str.slice(start, pos)); result.lines = lines; result.pos = pos; result.ok = true; return result; } exports.parseLinkDestination = parseLinkDestination; ; //# sourceMappingURL=parze_link_destination.js.map