From c2aa7bf38fb30de2d04f87f8e7780e4c768ae6b1 Mon Sep 17 00:00:00 2001 From: Minteck Date: Thu, 20 Jan 2022 13:43:34 +0100 Subject: Initial commit --- .../lib/helpers/parse_link_destination.js | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 node_modules/markdown-it/lib/helpers/parse_link_destination.js (limited to 'node_modules/markdown-it/lib/helpers/parse_link_destination.js') diff --git a/node_modules/markdown-it/lib/helpers/parse_link_destination.js b/node_modules/markdown-it/lib/helpers/parse_link_destination.js new file mode 100644 index 0000000..637f1f4 --- /dev/null +++ b/node_modules/markdown-it/lib/helpers/parse_link_destination.js @@ -0,0 +1,82 @@ +// Parse link destination +// +'use strict'; + + +var unescapeAll = require('../common/utils').unescapeAll; + + +module.exports = 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 === 0x3C /* < */) { 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; + while (pos < max) { + code = str.charCodeAt(pos); + + if (code === 0x20) { break; } + + // ascii control characters + if (code < 0x20 || code === 0x7F) { break; } + + if (code === 0x5C /* \ */ && pos + 1 < max) { + if (str.charCodeAt(pos + 1) === 0x20) { break; } + pos += 2; + continue; + } + + if (code === 0x28 /* ( */) { + level++; + if (level > 32) { return result; } + } + + if (code === 0x29 /* ) */) { + if (level === 0) { break; } + level--; + } + + pos++; + } + + 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; +}; -- cgit