|
import { |
|
decodeEntities, |
|
dedent, |
|
log$1 |
|
} from "./chunk-3PMDUHG4.js"; |
|
import { |
|
dequal |
|
} from "./chunk-HTVXVXIR.js"; |
|
import { |
|
__commonJS, |
|
__export, |
|
__toESM |
|
} from "./chunk-TNDHKS54.js"; |
|
|
|
|
|
var require_ms = __commonJS({ |
|
"node_modules/ms/index.js"(exports, module) { |
|
var s = 1e3; |
|
var m = s * 60; |
|
var h = m * 60; |
|
var d = h * 24; |
|
var w = d * 7; |
|
var y = d * 365.25; |
|
module.exports = function(val, options) { |
|
options = options || {}; |
|
var type = typeof val; |
|
if (type === "string" && val.length > 0) { |
|
return parse2(val); |
|
} else if (type === "number" && isFinite(val)) { |
|
return options.long ? fmtLong(val) : fmtShort(val); |
|
} |
|
throw new Error( |
|
"val is not a non-empty string or a valid number. val=" + JSON.stringify(val) |
|
); |
|
}; |
|
function parse2(str) { |
|
str = String(str); |
|
if (str.length > 100) { |
|
return; |
|
} |
|
var match = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( |
|
str |
|
); |
|
if (!match) { |
|
return; |
|
} |
|
var n = parseFloat(match[1]); |
|
var type = (match[2] || "ms").toLowerCase(); |
|
switch (type) { |
|
case "years": |
|
case "year": |
|
case "yrs": |
|
case "yr": |
|
case "y": |
|
return n * y; |
|
case "weeks": |
|
case "week": |
|
case "w": |
|
return n * w; |
|
case "days": |
|
case "day": |
|
case "d": |
|
return n * d; |
|
case "hours": |
|
case "hour": |
|
case "hrs": |
|
case "hr": |
|
case "h": |
|
return n * h; |
|
case "minutes": |
|
case "minute": |
|
case "mins": |
|
case "min": |
|
case "m": |
|
return n * m; |
|
case "seconds": |
|
case "second": |
|
case "secs": |
|
case "sec": |
|
case "s": |
|
return n * s; |
|
case "milliseconds": |
|
case "millisecond": |
|
case "msecs": |
|
case "msec": |
|
case "ms": |
|
return n; |
|
default: |
|
return void 0; |
|
} |
|
} |
|
function fmtShort(ms) { |
|
var msAbs = Math.abs(ms); |
|
if (msAbs >= d) { |
|
return Math.round(ms / d) + "d"; |
|
} |
|
if (msAbs >= h) { |
|
return Math.round(ms / h) + "h"; |
|
} |
|
if (msAbs >= m) { |
|
return Math.round(ms / m) + "m"; |
|
} |
|
if (msAbs >= s) { |
|
return Math.round(ms / s) + "s"; |
|
} |
|
return ms + "ms"; |
|
} |
|
function fmtLong(ms) { |
|
var msAbs = Math.abs(ms); |
|
if (msAbs >= d) { |
|
return plural(ms, msAbs, d, "day"); |
|
} |
|
if (msAbs >= h) { |
|
return plural(ms, msAbs, h, "hour"); |
|
} |
|
if (msAbs >= m) { |
|
return plural(ms, msAbs, m, "minute"); |
|
} |
|
if (msAbs >= s) { |
|
return plural(ms, msAbs, s, "second"); |
|
} |
|
return ms + " ms"; |
|
} |
|
function plural(ms, msAbs, n, name) { |
|
var isPlural = msAbs >= n * 1.5; |
|
return Math.round(ms / n) + " " + name + (isPlural ? "s" : ""); |
|
} |
|
} |
|
}); |
|
|
|
|
|
var require_common = __commonJS({ |
|
"node_modules/debug/src/common.js"(exports, module) { |
|
function setup(env) { |
|
createDebug2.debug = createDebug2; |
|
createDebug2.default = createDebug2; |
|
createDebug2.coerce = coerce; |
|
createDebug2.disable = disable2; |
|
createDebug2.enable = enable; |
|
createDebug2.enabled = enabled; |
|
createDebug2.humanize = require_ms(); |
|
createDebug2.destroy = destroy; |
|
Object.keys(env).forEach((key) => { |
|
createDebug2[key] = env[key]; |
|
}); |
|
createDebug2.names = []; |
|
createDebug2.skips = []; |
|
createDebug2.formatters = {}; |
|
function selectColor(namespace) { |
|
let hash = 0; |
|
for (let i = 0; i < namespace.length; i++) { |
|
hash = (hash << 5) - hash + namespace.charCodeAt(i); |
|
hash |= 0; |
|
} |
|
return createDebug2.colors[Math.abs(hash) % createDebug2.colors.length]; |
|
} |
|
createDebug2.selectColor = selectColor; |
|
function createDebug2(namespace) { |
|
let prevTime; |
|
let enableOverride = null; |
|
let namespacesCache; |
|
let enabledCache; |
|
function debug2(...args) { |
|
if (!debug2.enabled) { |
|
return; |
|
} |
|
const self = debug2; |
|
const curr = Number( new Date()); |
|
const ms = curr - (prevTime || curr); |
|
self.diff = ms; |
|
self.prev = prevTime; |
|
self.curr = curr; |
|
prevTime = curr; |
|
args[0] = createDebug2.coerce(args[0]); |
|
if (typeof args[0] !== "string") { |
|
args.unshift("%O"); |
|
} |
|
let index2 = 0; |
|
args[0] = args[0].replace(/%([a-zA-Z%])/g, (match, format) => { |
|
if (match === "%%") { |
|
return "%"; |
|
} |
|
index2++; |
|
const formatter = createDebug2.formatters[format]; |
|
if (typeof formatter === "function") { |
|
const val = args[index2]; |
|
match = formatter.call(self, val); |
|
args.splice(index2, 1); |
|
index2--; |
|
} |
|
return match; |
|
}); |
|
createDebug2.formatArgs.call(self, args); |
|
const logFn = self.log || createDebug2.log; |
|
logFn.apply(self, args); |
|
} |
|
debug2.namespace = namespace; |
|
debug2.useColors = createDebug2.useColors(); |
|
debug2.color = createDebug2.selectColor(namespace); |
|
debug2.extend = extend; |
|
debug2.destroy = createDebug2.destroy; |
|
Object.defineProperty(debug2, "enabled", { |
|
enumerable: true, |
|
configurable: false, |
|
get: () => { |
|
if (enableOverride !== null) { |
|
return enableOverride; |
|
} |
|
if (namespacesCache !== createDebug2.namespaces) { |
|
namespacesCache = createDebug2.namespaces; |
|
enabledCache = createDebug2.enabled(namespace); |
|
} |
|
return enabledCache; |
|
}, |
|
set: (v) => { |
|
enableOverride = v; |
|
} |
|
}); |
|
if (typeof createDebug2.init === "function") { |
|
createDebug2.init(debug2); |
|
} |
|
return debug2; |
|
} |
|
function extend(namespace, delimiter) { |
|
const newDebug = createDebug2(this.namespace + (typeof delimiter === "undefined" ? ":" : delimiter) + namespace); |
|
newDebug.log = this.log; |
|
return newDebug; |
|
} |
|
function enable(namespaces) { |
|
createDebug2.save(namespaces); |
|
createDebug2.namespaces = namespaces; |
|
createDebug2.names = []; |
|
createDebug2.skips = []; |
|
let i; |
|
const split = (typeof namespaces === "string" ? namespaces : "").split(/[\s,]+/); |
|
const len = split.length; |
|
for (i = 0; i < len; i++) { |
|
if (!split[i]) { |
|
continue; |
|
} |
|
namespaces = split[i].replace(/\*/g, ".*?"); |
|
if (namespaces[0] === "-") { |
|
createDebug2.skips.push(new RegExp("^" + namespaces.slice(1) + "$")); |
|
} else { |
|
createDebug2.names.push(new RegExp("^" + namespaces + "$")); |
|
} |
|
} |
|
} |
|
function disable2() { |
|
const namespaces = [ |
|
...createDebug2.names.map(toNamespace), |
|
...createDebug2.skips.map(toNamespace).map((namespace) => "-" + namespace) |
|
].join(","); |
|
createDebug2.enable(""); |
|
return namespaces; |
|
} |
|
function enabled(name) { |
|
if (name[name.length - 1] === "*") { |
|
return true; |
|
} |
|
let i; |
|
let len; |
|
for (i = 0, len = createDebug2.skips.length; i < len; i++) { |
|
if (createDebug2.skips[i].test(name)) { |
|
return false; |
|
} |
|
} |
|
for (i = 0, len = createDebug2.names.length; i < len; i++) { |
|
if (createDebug2.names[i].test(name)) { |
|
return true; |
|
} |
|
} |
|
return false; |
|
} |
|
function toNamespace(regexp) { |
|
return regexp.toString().substring(2, regexp.toString().length - 2).replace(/\.\*\?$/, "*"); |
|
} |
|
function coerce(val) { |
|
if (val instanceof Error) { |
|
return val.stack || val.message; |
|
} |
|
return val; |
|
} |
|
function destroy() { |
|
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); |
|
} |
|
createDebug2.enable(createDebug2.load()); |
|
return createDebug2; |
|
} |
|
module.exports = setup; |
|
} |
|
}); |
|
|
|
|
|
var require_browser = __commonJS({ |
|
"node_modules/debug/src/browser.js"(exports, module) { |
|
exports.formatArgs = formatArgs; |
|
exports.save = save; |
|
exports.load = load; |
|
exports.useColors = useColors; |
|
exports.storage = localstorage(); |
|
exports.destroy = (() => { |
|
let warned = false; |
|
return () => { |
|
if (!warned) { |
|
warned = true; |
|
console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); |
|
} |
|
}; |
|
})(); |
|
exports.colors = [ |
|
"#0000CC", |
|
"#0000FF", |
|
"#0033CC", |
|
"#0033FF", |
|
"#0066CC", |
|
"#0066FF", |
|
"#0099CC", |
|
"#0099FF", |
|
"#00CC00", |
|
"#00CC33", |
|
"#00CC66", |
|
"#00CC99", |
|
"#00CCCC", |
|
"#00CCFF", |
|
"#3300CC", |
|
"#3300FF", |
|
"#3333CC", |
|
"#3333FF", |
|
"#3366CC", |
|
"#3366FF", |
|
"#3399CC", |
|
"#3399FF", |
|
"#33CC00", |
|
"#33CC33", |
|
"#33CC66", |
|
"#33CC99", |
|
"#33CCCC", |
|
"#33CCFF", |
|
"#6600CC", |
|
"#6600FF", |
|
"#6633CC", |
|
"#6633FF", |
|
"#66CC00", |
|
"#66CC33", |
|
"#9900CC", |
|
"#9900FF", |
|
"#9933CC", |
|
"#9933FF", |
|
"#99CC00", |
|
"#99CC33", |
|
"#CC0000", |
|
"#CC0033", |
|
"#CC0066", |
|
"#CC0099", |
|
"#CC00CC", |
|
"#CC00FF", |
|
"#CC3300", |
|
"#CC3333", |
|
"#CC3366", |
|
"#CC3399", |
|
"#CC33CC", |
|
"#CC33FF", |
|
"#CC6600", |
|
"#CC6633", |
|
"#CC9900", |
|
"#CC9933", |
|
"#CCCC00", |
|
"#CCCC33", |
|
"#FF0000", |
|
"#FF0033", |
|
"#FF0066", |
|
"#FF0099", |
|
"#FF00CC", |
|
"#FF00FF", |
|
"#FF3300", |
|
"#FF3333", |
|
"#FF3366", |
|
"#FF3399", |
|
"#FF33CC", |
|
"#FF33FF", |
|
"#FF6600", |
|
"#FF6633", |
|
"#FF9900", |
|
"#FF9933", |
|
"#FFCC00", |
|
"#FFCC33" |
|
]; |
|
function useColors() { |
|
if (typeof window !== "undefined" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) { |
|
return true; |
|
} |
|
if (typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) { |
|
return false; |
|
} |
|
return typeof document !== "undefined" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || |
|
typeof window !== "undefined" && window.console && (window.console.firebug || window.console.exception && window.console.table) || |
|
|
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31 || |
|
typeof navigator !== "undefined" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); |
|
} |
|
function formatArgs(args) { |
|
args[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + args[0] + (this.useColors ? "%c " : " ") + "+" + module.exports.humanize(this.diff); |
|
if (!this.useColors) { |
|
return; |
|
} |
|
const c = "color: " + this.color; |
|
args.splice(1, 0, c, "color: inherit"); |
|
let index2 = 0; |
|
let lastC = 0; |
|
args[0].replace(/%[a-zA-Z%]/g, (match) => { |
|
if (match === "%%") { |
|
return; |
|
} |
|
index2++; |
|
if (match === "%c") { |
|
lastC = index2; |
|
} |
|
}); |
|
args.splice(lastC, 0, c); |
|
} |
|
exports.log = console.debug || console.log || (() => { |
|
}); |
|
function save(namespaces) { |
|
try { |
|
if (namespaces) { |
|
exports.storage.setItem("debug", namespaces); |
|
} else { |
|
exports.storage.removeItem("debug"); |
|
} |
|
} catch (error) { |
|
} |
|
} |
|
function load() { |
|
let r; |
|
try { |
|
r = exports.storage.getItem("debug"); |
|
} catch (error) { |
|
} |
|
if (!r && typeof process !== "undefined" && "env" in process) { |
|
r = process.env.DEBUG; |
|
} |
|
return r; |
|
} |
|
function localstorage() { |
|
try { |
|
return localStorage; |
|
} catch (error) { |
|
} |
|
} |
|
module.exports = require_common()(exports); |
|
var { formatters } = module.exports; |
|
formatters.j = function(v) { |
|
try { |
|
return JSON.stringify(v); |
|
} catch (error) { |
|
return "[UnexpectedJSONParseError]: " + error.message; |
|
} |
|
}; |
|
} |
|
}); |
|
|
|
|
|
var FORCE_COLOR; |
|
var NODE_DISABLE_COLORS; |
|
var NO_COLOR; |
|
var TERM; |
|
var isTTY = true; |
|
if (typeof process !== "undefined") { |
|
({ FORCE_COLOR, NODE_DISABLE_COLORS, NO_COLOR, TERM } = process.env || {}); |
|
isTTY = process.stdout && process.stdout.isTTY; |
|
} |
|
var $ = { |
|
enabled: !NODE_DISABLE_COLORS && NO_COLOR == null && TERM !== "dumb" && (FORCE_COLOR != null && FORCE_COLOR !== "0" || isTTY), |
|
|
|
reset: init(0, 0), |
|
bold: init(1, 22), |
|
dim: init(2, 22), |
|
italic: init(3, 23), |
|
underline: init(4, 24), |
|
inverse: init(7, 27), |
|
hidden: init(8, 28), |
|
strikethrough: init(9, 29), |
|
|
|
black: init(30, 39), |
|
red: init(31, 39), |
|
green: init(32, 39), |
|
yellow: init(33, 39), |
|
blue: init(34, 39), |
|
magenta: init(35, 39), |
|
cyan: init(36, 39), |
|
white: init(37, 39), |
|
gray: init(90, 39), |
|
grey: init(90, 39), |
|
|
|
bgBlack: init(40, 49), |
|
bgRed: init(41, 49), |
|
bgGreen: init(42, 49), |
|
bgYellow: init(43, 49), |
|
bgBlue: init(44, 49), |
|
bgMagenta: init(45, 49), |
|
bgCyan: init(46, 49), |
|
bgWhite: init(47, 49) |
|
}; |
|
function run(arr, str) { |
|
let i = 0, tmp, beg = "", end = ""; |
|
for (; i < arr.length; i++) { |
|
tmp = arr[i]; |
|
beg += tmp.open; |
|
end += tmp.close; |
|
if (!!~str.indexOf(tmp.close)) { |
|
str = str.replace(tmp.rgx, tmp.close + tmp.open); |
|
} |
|
} |
|
return beg + str + end; |
|
} |
|
function chain(has, keys) { |
|
let ctx = { has, keys }; |
|
ctx.reset = $.reset.bind(ctx); |
|
ctx.bold = $.bold.bind(ctx); |
|
ctx.dim = $.dim.bind(ctx); |
|
ctx.italic = $.italic.bind(ctx); |
|
ctx.underline = $.underline.bind(ctx); |
|
ctx.inverse = $.inverse.bind(ctx); |
|
ctx.hidden = $.hidden.bind(ctx); |
|
ctx.strikethrough = $.strikethrough.bind(ctx); |
|
ctx.black = $.black.bind(ctx); |
|
ctx.red = $.red.bind(ctx); |
|
ctx.green = $.green.bind(ctx); |
|
ctx.yellow = $.yellow.bind(ctx); |
|
ctx.blue = $.blue.bind(ctx); |
|
ctx.magenta = $.magenta.bind(ctx); |
|
ctx.cyan = $.cyan.bind(ctx); |
|
ctx.white = $.white.bind(ctx); |
|
ctx.gray = $.gray.bind(ctx); |
|
ctx.grey = $.grey.bind(ctx); |
|
ctx.bgBlack = $.bgBlack.bind(ctx); |
|
ctx.bgRed = $.bgRed.bind(ctx); |
|
ctx.bgGreen = $.bgGreen.bind(ctx); |
|
ctx.bgYellow = $.bgYellow.bind(ctx); |
|
ctx.bgBlue = $.bgBlue.bind(ctx); |
|
ctx.bgMagenta = $.bgMagenta.bind(ctx); |
|
ctx.bgCyan = $.bgCyan.bind(ctx); |
|
ctx.bgWhite = $.bgWhite.bind(ctx); |
|
return ctx; |
|
} |
|
function init(open, close) { |
|
let blk = { |
|
open: `\x1B[${open}m`, |
|
close: `\x1B[${close}m`, |
|
rgx: new RegExp(`\\x1b\\[${close}m`, "g") |
|
}; |
|
return function(txt) { |
|
if (this !== void 0 && this.has !== void 0) { |
|
!!~this.has.indexOf(open) || (this.has.push(open), this.keys.push(blk)); |
|
return txt === void 0 ? this : $.enabled ? run(this.keys, txt + "") : txt + ""; |
|
} |
|
return txt === void 0 ? chain([open], [blk]) : $.enabled ? run([blk], txt + "") : txt + ""; |
|
}; |
|
} |
|
var kleur_default = $; |
|
|
|
|
|
function Diff() { |
|
} |
|
Diff.prototype = { |
|
diff: function diff(oldString, newString) { |
|
var _options$timeout; |
|
var options = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}; |
|
var callback = options.callback; |
|
if (typeof options === "function") { |
|
callback = options; |
|
options = {}; |
|
} |
|
this.options = options; |
|
var self = this; |
|
function done(value) { |
|
if (callback) { |
|
setTimeout(function() { |
|
callback(void 0, value); |
|
}, 0); |
|
return true; |
|
} else { |
|
return value; |
|
} |
|
} |
|
oldString = this.castInput(oldString); |
|
newString = this.castInput(newString); |
|
oldString = this.removeEmpty(this.tokenize(oldString)); |
|
newString = this.removeEmpty(this.tokenize(newString)); |
|
var newLen = newString.length, oldLen = oldString.length; |
|
var editLength = 1; |
|
var maxEditLength = newLen + oldLen; |
|
if (options.maxEditLength) { |
|
maxEditLength = Math.min(maxEditLength, options.maxEditLength); |
|
} |
|
var maxExecutionTime = (_options$timeout = options.timeout) !== null && _options$timeout !== void 0 ? _options$timeout : Infinity; |
|
var abortAfterTimestamp = Date.now() + maxExecutionTime; |
|
var bestPath = [{ |
|
oldPos: -1, |
|
lastComponent: void 0 |
|
}]; |
|
var newPos = this.extractCommon(bestPath[0], newString, oldString, 0); |
|
if (bestPath[0].oldPos + 1 >= oldLen && newPos + 1 >= newLen) { |
|
return done([{ |
|
value: this.join(newString), |
|
count: newString.length |
|
}]); |
|
} |
|
var minDiagonalToConsider = -Infinity, maxDiagonalToConsider = Infinity; |
|
function execEditLength() { |
|
for (var diagonalPath = Math.max(minDiagonalToConsider, -editLength); diagonalPath <= Math.min(maxDiagonalToConsider, editLength); diagonalPath += 2) { |
|
var basePath = void 0; |
|
var removePath = bestPath[diagonalPath - 1], addPath = bestPath[diagonalPath + 1]; |
|
if (removePath) { |
|
bestPath[diagonalPath - 1] = void 0; |
|
} |
|
var canAdd = false; |
|
if (addPath) { |
|
var addPathNewPos = addPath.oldPos - diagonalPath; |
|
canAdd = addPath && 0 <= addPathNewPos && addPathNewPos < newLen; |
|
} |
|
var canRemove = removePath && removePath.oldPos + 1 < oldLen; |
|
if (!canAdd && !canRemove) { |
|
bestPath[diagonalPath] = void 0; |
|
continue; |
|
} |
|
if (!canRemove || canAdd && removePath.oldPos + 1 < addPath.oldPos) { |
|
basePath = self.addToPath(addPath, true, void 0, 0); |
|
} else { |
|
basePath = self.addToPath(removePath, void 0, true, 1); |
|
} |
|
newPos = self.extractCommon(basePath, newString, oldString, diagonalPath); |
|
if (basePath.oldPos + 1 >= oldLen && newPos + 1 >= newLen) { |
|
return done(buildValues(self, basePath.lastComponent, newString, oldString, self.useLongestToken)); |
|
} else { |
|
bestPath[diagonalPath] = basePath; |
|
if (basePath.oldPos + 1 >= oldLen) { |
|
maxDiagonalToConsider = Math.min(maxDiagonalToConsider, diagonalPath - 1); |
|
} |
|
if (newPos + 1 >= newLen) { |
|
minDiagonalToConsider = Math.max(minDiagonalToConsider, diagonalPath + 1); |
|
} |
|
} |
|
} |
|
editLength++; |
|
} |
|
if (callback) { |
|
(function exec() { |
|
setTimeout(function() { |
|
if (editLength > maxEditLength || Date.now() > abortAfterTimestamp) { |
|
return callback(); |
|
} |
|
if (!execEditLength()) { |
|
exec(); |
|
} |
|
}, 0); |
|
})(); |
|
} else { |
|
while (editLength <= maxEditLength && Date.now() <= abortAfterTimestamp) { |
|
var ret = execEditLength(); |
|
if (ret) { |
|
return ret; |
|
} |
|
} |
|
} |
|
}, |
|
addToPath: function addToPath(path, added, removed, oldPosInc) { |
|
var last = path.lastComponent; |
|
if (last && last.added === added && last.removed === removed) { |
|
return { |
|
oldPos: path.oldPos + oldPosInc, |
|
lastComponent: { |
|
count: last.count + 1, |
|
added, |
|
removed, |
|
previousComponent: last.previousComponent |
|
} |
|
}; |
|
} else { |
|
return { |
|
oldPos: path.oldPos + oldPosInc, |
|
lastComponent: { |
|
count: 1, |
|
added, |
|
removed, |
|
previousComponent: last |
|
} |
|
}; |
|
} |
|
}, |
|
extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) { |
|
var newLen = newString.length, oldLen = oldString.length, oldPos = basePath.oldPos, newPos = oldPos - diagonalPath, commonCount = 0; |
|
while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) { |
|
newPos++; |
|
oldPos++; |
|
commonCount++; |
|
} |
|
if (commonCount) { |
|
basePath.lastComponent = { |
|
count: commonCount, |
|
previousComponent: basePath.lastComponent |
|
}; |
|
} |
|
basePath.oldPos = oldPos; |
|
return newPos; |
|
}, |
|
equals: function equals(left, right) { |
|
if (this.options.comparator) { |
|
return this.options.comparator(left, right); |
|
} else { |
|
return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase(); |
|
} |
|
}, |
|
removeEmpty: function removeEmpty(array) { |
|
var ret = []; |
|
for (var i = 0; i < array.length; i++) { |
|
if (array[i]) { |
|
ret.push(array[i]); |
|
} |
|
} |
|
return ret; |
|
}, |
|
castInput: function castInput(value) { |
|
return value; |
|
}, |
|
tokenize: function tokenize(value) { |
|
return value.split(""); |
|
}, |
|
join: function join(chars2) { |
|
return chars2.join(""); |
|
} |
|
}; |
|
function buildValues(diff2, lastComponent, newString, oldString, useLongestToken) { |
|
var components = []; |
|
var nextComponent; |
|
while (lastComponent) { |
|
components.push(lastComponent); |
|
nextComponent = lastComponent.previousComponent; |
|
delete lastComponent.previousComponent; |
|
lastComponent = nextComponent; |
|
} |
|
components.reverse(); |
|
var componentPos = 0, componentLen = components.length, newPos = 0, oldPos = 0; |
|
for (; componentPos < componentLen; componentPos++) { |
|
var component = components[componentPos]; |
|
if (!component.removed) { |
|
if (!component.added && useLongestToken) { |
|
var value = newString.slice(newPos, newPos + component.count); |
|
value = value.map(function(value2, i) { |
|
var oldValue = oldString[oldPos + i]; |
|
return oldValue.length > value2.length ? oldValue : value2; |
|
}); |
|
component.value = diff2.join(value); |
|
} else { |
|
component.value = diff2.join(newString.slice(newPos, newPos + component.count)); |
|
} |
|
newPos += component.count; |
|
if (!component.added) { |
|
oldPos += component.count; |
|
} |
|
} else { |
|
component.value = diff2.join(oldString.slice(oldPos, oldPos + component.count)); |
|
oldPos += component.count; |
|
if (componentPos && components[componentPos - 1].added) { |
|
var tmp = components[componentPos - 1]; |
|
components[componentPos - 1] = components[componentPos]; |
|
components[componentPos] = tmp; |
|
} |
|
} |
|
} |
|
var finalComponent = components[componentLen - 1]; |
|
if (componentLen > 1 && typeof finalComponent.value === "string" && (finalComponent.added || finalComponent.removed) && diff2.equals("", finalComponent.value)) { |
|
components[componentLen - 2].value += finalComponent.value; |
|
components.pop(); |
|
} |
|
return components; |
|
} |
|
var characterDiff = new Diff(); |
|
function diffChars(oldStr, newStr, options) { |
|
return characterDiff.diff(oldStr, newStr, options); |
|
} |
|
var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/; |
|
var reWhitespace = /\S/; |
|
var wordDiff = new Diff(); |
|
wordDiff.equals = function(left, right) { |
|
if (this.options.ignoreCase) { |
|
left = left.toLowerCase(); |
|
right = right.toLowerCase(); |
|
} |
|
return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right); |
|
}; |
|
wordDiff.tokenize = function(value) { |
|
var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); |
|
for (var i = 0; i < tokens.length - 1; i++) { |
|
if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) { |
|
tokens[i] += tokens[i + 2]; |
|
tokens.splice(i + 1, 2); |
|
i--; |
|
} |
|
} |
|
return tokens; |
|
}; |
|
var lineDiff = new Diff(); |
|
lineDiff.tokenize = function(value) { |
|
if (this.options.stripTrailingCr) { |
|
value = value.replace(/\r\n/g, "\n"); |
|
} |
|
var retLines = [], linesAndNewlines = value.split(/(\n|\r\n)/); |
|
if (!linesAndNewlines[linesAndNewlines.length - 1]) { |
|
linesAndNewlines.pop(); |
|
} |
|
for (var i = 0; i < linesAndNewlines.length; i++) { |
|
var line2 = linesAndNewlines[i]; |
|
if (i % 2 && !this.options.newlineIsToken) { |
|
retLines[retLines.length - 1] += line2; |
|
} else { |
|
if (this.options.ignoreWhitespace) { |
|
line2 = line2.trim(); |
|
} |
|
retLines.push(line2); |
|
} |
|
} |
|
return retLines; |
|
}; |
|
function diffLines(oldStr, newStr, callback) { |
|
return lineDiff.diff(oldStr, newStr, callback); |
|
} |
|
var sentenceDiff = new Diff(); |
|
sentenceDiff.tokenize = function(value) { |
|
return value.split(/(\S.+?[.!?])(?=\s+|$)/); |
|
}; |
|
var cssDiff = new Diff(); |
|
cssDiff.tokenize = function(value) { |
|
return value.split(/([{}:;,]|\s+)/); |
|
}; |
|
function _typeof(obj) { |
|
"@babel/helpers - typeof"; |
|
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { |
|
_typeof = function(obj2) { |
|
return typeof obj2; |
|
}; |
|
} else { |
|
_typeof = function(obj2) { |
|
return obj2 && typeof Symbol === "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; |
|
}; |
|
} |
|
return _typeof(obj); |
|
} |
|
var objectPrototypeToString = Object.prototype.toString; |
|
var jsonDiff = new Diff(); |
|
jsonDiff.useLongestToken = true; |
|
jsonDiff.tokenize = lineDiff.tokenize; |
|
jsonDiff.castInput = function(value) { |
|
var _this$options = this.options, undefinedReplacement = _this$options.undefinedReplacement, _this$options$stringi = _this$options.stringifyReplacer, stringifyReplacer = _this$options$stringi === void 0 ? function(k, v) { |
|
return typeof v === "undefined" ? undefinedReplacement : v; |
|
} : _this$options$stringi; |
|
return typeof value === "string" ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, " "); |
|
}; |
|
jsonDiff.equals = function(left, right) { |
|
return Diff.prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, "$1"), right.replace(/,([\r\n])/g, "$1")); |
|
}; |
|
function canonicalize(obj, stack, replacementStack, replacer, key) { |
|
stack = stack || []; |
|
replacementStack = replacementStack || []; |
|
if (replacer) { |
|
obj = replacer(key, obj); |
|
} |
|
var i; |
|
for (i = 0; i < stack.length; i += 1) { |
|
if (stack[i] === obj) { |
|
return replacementStack[i]; |
|
} |
|
} |
|
var canonicalizedObj; |
|
if ("[object Array]" === objectPrototypeToString.call(obj)) { |
|
stack.push(obj); |
|
canonicalizedObj = new Array(obj.length); |
|
replacementStack.push(canonicalizedObj); |
|
for (i = 0; i < obj.length; i += 1) { |
|
canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key); |
|
} |
|
stack.pop(); |
|
replacementStack.pop(); |
|
return canonicalizedObj; |
|
} |
|
if (obj && obj.toJSON) { |
|
obj = obj.toJSON(); |
|
} |
|
if (_typeof(obj) === "object" && obj !== null) { |
|
stack.push(obj); |
|
canonicalizedObj = {}; |
|
replacementStack.push(canonicalizedObj); |
|
var sortedKeys = [], _key; |
|
for (_key in obj) { |
|
if (obj.hasOwnProperty(_key)) { |
|
sortedKeys.push(_key); |
|
} |
|
} |
|
sortedKeys.sort(); |
|
for (i = 0; i < sortedKeys.length; i += 1) { |
|
_key = sortedKeys[i]; |
|
canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key); |
|
} |
|
stack.pop(); |
|
replacementStack.pop(); |
|
} else { |
|
canonicalizedObj = obj; |
|
} |
|
return canonicalizedObj; |
|
} |
|
var arrayDiff = new Diff(); |
|
arrayDiff.tokenize = function(value) { |
|
return value.slice(); |
|
}; |
|
arrayDiff.join = arrayDiff.removeEmpty = function(value) { |
|
return value; |
|
}; |
|
function diffArrays(oldArr, newArr, callback) { |
|
return arrayDiff.diff(oldArr, newArr, callback); |
|
} |
|
|
|
|
|
var colors = { |
|
"--": kleur_default.red, |
|
"··": kleur_default.grey, |
|
"++": kleur_default.green |
|
}; |
|
var TITLE = kleur_default.dim().italic; |
|
var TAB = kleur_default.dim("→"); |
|
var SPACE = kleur_default.dim("·"); |
|
var NL = kleur_default.dim("↵"); |
|
var LOG = (sym, str) => colors[sym](sym + PRETTY(str)) + "\n"; |
|
var LINE = (num, x) => kleur_default.dim("L" + String(num).padStart(x, "0") + " "); |
|
var PRETTY = (str) => str.replace(/[ ]/g, SPACE).replace(/\t/g, TAB).replace(/(\r?\n)/g, NL); |
|
function line(obj, prev, pad) { |
|
let char = obj.removed ? "--" : obj.added ? "++" : "··"; |
|
let arr = obj.value.replace(/\r?\n$/, "").split("\n"); |
|
let i = 0, tmp, out = ""; |
|
if (obj.added) out += colors[char]().underline(TITLE("Expected:")) + "\n"; |
|
else if (obj.removed) out += colors[char]().underline(TITLE("Actual:")) + "\n"; |
|
for (; i < arr.length; i++) { |
|
tmp = arr[i]; |
|
if (tmp != null) { |
|
if (prev) out += LINE(prev + i, pad); |
|
out += LOG(char, tmp || "\n"); |
|
} |
|
} |
|
return out; |
|
} |
|
function arrays(input, expect) { |
|
let arr = diffArrays(input, expect); |
|
let i = 0, j = 0, k = 0, tmp, val, char, isObj, str; |
|
let out = LOG("··", "["); |
|
for (; i < arr.length; i++) { |
|
char = (tmp = arr[i]).removed ? "--" : tmp.added ? "++" : "··"; |
|
if (tmp.added) { |
|
out += colors[char]().underline(TITLE("Expected:")) + "\n"; |
|
} else if (tmp.removed) { |
|
out += colors[char]().underline(TITLE("Actual:")) + "\n"; |
|
} |
|
for (j = 0; j < tmp.value.length; j++) { |
|
isObj = tmp.value[j] && typeof tmp.value[j] === "object"; |
|
val = stringify(tmp.value[j]).split(/\r?\n/g); |
|
for (k = 0; k < val.length; ) { |
|
str = " " + val[k++] + (isObj ? "" : ","); |
|
if (isObj && k === val.length && j + 1 < tmp.value.length) str += ","; |
|
out += LOG(char, str); |
|
} |
|
} |
|
} |
|
return out + LOG("··", "]"); |
|
} |
|
function lines(input, expect, linenum = 0) { |
|
let i = 0, tmp, output = ""; |
|
let arr = diffLines(input, expect); |
|
let pad = String(expect.split(/\r?\n/g).length - linenum).length; |
|
for (; i < arr.length; i++) { |
|
output += line(tmp = arr[i], linenum, pad); |
|
if (linenum && !tmp.removed) linenum += tmp.count; |
|
} |
|
return output; |
|
} |
|
function chars(input, expect) { |
|
let arr = diffChars(input, expect); |
|
let i = 0, output = "", tmp; |
|
let l1 = input.length; |
|
let l2 = expect.length; |
|
let p1 = PRETTY(input); |
|
let p2 = PRETTY(expect); |
|
tmp = arr[i]; |
|
if (l1 === l2) { |
|
} else if (tmp.removed && arr[i + 1]) { |
|
let del = tmp.count - arr[i + 1].count; |
|
if (del == 0) { |
|
} else if (del > 0) { |
|
expect = " ".repeat(del) + expect; |
|
p2 = " ".repeat(del) + p2; |
|
l2 += del; |
|
} else if (del < 0) { |
|
input = " ".repeat(-del) + input; |
|
p1 = " ".repeat(-del) + p1; |
|
l1 += -del; |
|
} |
|
} |
|
output += direct(p1, p2, l1, l2); |
|
if (l1 === l2) { |
|
for (tmp = " "; i < l1; i++) { |
|
tmp += input[i] === expect[i] ? " " : "^"; |
|
} |
|
} else { |
|
for (tmp = " "; i < arr.length; i++) { |
|
tmp += (arr[i].added || arr[i].removed ? "^" : " ").repeat(Math.max(arr[i].count, 0)); |
|
if (i + 1 < arr.length && (arr[i].added && arr[i + 1].removed || arr[i].removed && arr[i + 1].added)) { |
|
arr[i + 1].count -= arr[i].count; |
|
} |
|
} |
|
} |
|
return output + kleur_default.red(tmp); |
|
} |
|
function direct(input, expect, lenA = String(input).length, lenB = String(expect).length) { |
|
let gutter = 4; |
|
let lenC = Math.max(lenA, lenB); |
|
let typeA = typeof input, typeB = typeof expect; |
|
if (typeA !== typeB) { |
|
gutter = 2; |
|
let delA = gutter + lenC - lenA; |
|
let delB = gutter + lenC - lenB; |
|
input += " ".repeat(delA) + kleur_default.dim(`[${typeA}]`); |
|
expect += " ".repeat(delB) + kleur_default.dim(`[${typeB}]`); |
|
lenA += delA + typeA.length + 2; |
|
lenB += delB + typeB.length + 2; |
|
lenC = Math.max(lenA, lenB); |
|
} |
|
let output = colors["++"]("++" + expect + " ".repeat(gutter + lenC - lenB) + TITLE("(Expected)")) + "\n"; |
|
return output + colors["--"]("--" + input + " ".repeat(gutter + lenC - lenA) + TITLE("(Actual)")) + "\n"; |
|
} |
|
function sort(input, expect) { |
|
var k, i = 0, tmp, isArr = Array.isArray(input); |
|
var keys = [], out = isArr ? Array(input.length) : {}; |
|
if (isArr) { |
|
for (i = 0; i < out.length; i++) { |
|
tmp = input[i]; |
|
if (!tmp || typeof tmp !== "object") out[i] = tmp; |
|
else out[i] = sort(tmp, expect[i]); |
|
} |
|
} else { |
|
for (k in expect) |
|
keys.push(k); |
|
for (; i < keys.length; i++) { |
|
if (Object.prototype.hasOwnProperty.call(input, k = keys[i])) { |
|
if (!(tmp = input[k]) || typeof tmp !== "object") out[k] = tmp; |
|
else out[k] = sort(tmp, expect[k]); |
|
} |
|
} |
|
for (k in input) { |
|
if (!out.hasOwnProperty(k)) { |
|
out[k] = input[k]; |
|
} |
|
} |
|
} |
|
return out; |
|
} |
|
function circular() { |
|
var cache = new Set(); |
|
return function print(key, val) { |
|
if (val === void 0) return "[__VOID__]"; |
|
if (typeof val === "number" && val !== val) return "[__NAN__]"; |
|
if (typeof val === "bigint") return val.toString(); |
|
if (!val || typeof val !== "object") return val; |
|
if (cache.has(val)) return "[Circular]"; |
|
cache.add(val); |
|
return val; |
|
}; |
|
} |
|
function stringify(input) { |
|
return JSON.stringify(input, circular(), 2).replace(/"\[__NAN__\]"/g, "NaN").replace(/"\[__VOID__\]"/g, "undefined"); |
|
} |
|
function compare(input, expect) { |
|
if (Array.isArray(expect) && Array.isArray(input)) return arrays(input, expect); |
|
if (expect instanceof RegExp) return chars("" + input, "" + expect); |
|
let isA = input && typeof input == "object"; |
|
let isB = expect && typeof expect == "object"; |
|
if (isA && isB) input = sort(input, expect); |
|
if (isB) expect = stringify(expect); |
|
if (isA) input = stringify(input); |
|
if (expect && typeof expect == "object") { |
|
input = stringify(sort(input, expect)); |
|
expect = stringify(expect); |
|
} |
|
isA = typeof input == "string"; |
|
isB = typeof expect == "string"; |
|
if (isA && /\r?\n/.test(input)) return lines(input, "" + expect); |
|
if (isB && /\r?\n/.test(expect)) return lines("" + input, expect); |
|
if (isA && isB) return chars(input, expect); |
|
return direct(input, expect); |
|
} |
|
|
|
|
|
function dedent2(str) { |
|
str = str.replace(/\r?\n/g, "\n"); |
|
let arr = str.match(/^[ \t]*(?=\S)/gm); |
|
let i = 0, min = 1 / 0, len = (arr || []).length; |
|
for (; i < len; i++) min = Math.min(min, arr[i].length); |
|
return len && min ? str.replace(new RegExp(`^[ \\t]{${min}}`, "gm"), "") : str; |
|
} |
|
var Assertion = class extends Error { |
|
constructor(opts = {}) { |
|
super(opts.message); |
|
this.name = "Assertion"; |
|
this.code = "ERR_ASSERTION"; |
|
if (Error.captureStackTrace) { |
|
Error.captureStackTrace(this, this.constructor); |
|
} |
|
this.details = opts.details || false; |
|
this.generated = !!opts.generated; |
|
this.operator = opts.operator; |
|
this.expects = opts.expects; |
|
this.actual = opts.actual; |
|
} |
|
}; |
|
function assert(bool, actual, expects, operator, detailer, backup, msg) { |
|
if (bool) return; |
|
let message = msg || backup; |
|
if (msg instanceof Error) throw msg; |
|
let details = detailer && detailer(actual, expects); |
|
throw new Assertion({ actual, expects, operator, message, details, generated: !msg }); |
|
} |
|
function ok(val, msg) { |
|
assert(!!val, false, true, "ok", false, "Expected value to be truthy", msg); |
|
} |
|
function is(val, exp, msg) { |
|
assert(val === exp, val, exp, "is", compare, "Expected values to be strictly equal:", msg); |
|
} |
|
function not(val, msg) { |
|
assert(!val, true, false, "not", false, "Expected value to be falsey", msg); |
|
} |
|
not.ok = not; |
|
is.not = function(val, exp, msg) { |
|
assert(val !== exp, val, exp, "is.not", false, "Expected values not to be strictly equal", msg); |
|
}; |
|
not.equal = function(val, exp, msg) { |
|
assert(!dequal(val, exp), val, exp, "not.equal", false, "Expected values not to be deeply equal", msg); |
|
}; |
|
not.type = function(val, exp, msg) { |
|
let tmp = typeof val; |
|
assert(tmp !== exp, tmp, exp, "not.type", false, `Expected "${tmp}" not to be "${exp}"`, msg); |
|
}; |
|
not.instance = function(val, exp, msg) { |
|
let name = "`" + (exp.name || exp.constructor.name) + "`"; |
|
assert(!(val instanceof exp), val, exp, "not.instance", false, `Expected value not to be an instance of ${name}`, msg); |
|
}; |
|
not.snapshot = function(val, exp, msg) { |
|
val = dedent2(val); |
|
exp = dedent2(exp); |
|
assert(val !== exp, val, exp, "not.snapshot", false, "Expected value not to match snapshot", msg); |
|
}; |
|
not.fixture = function(val, exp, msg) { |
|
val = dedent2(val); |
|
exp = dedent2(exp); |
|
assert(val !== exp, val, exp, "not.fixture", false, "Expected value not to match fixture", msg); |
|
}; |
|
not.match = function(val, exp, msg) { |
|
if (typeof exp === "string") { |
|
assert(!val.includes(exp), val, exp, "not.match", false, `Expected value not to include "${exp}" substring`, msg); |
|
} else { |
|
assert(!exp.test(val), val, exp, "not.match", false, `Expected value not to match \`${String(exp)}\` pattern`, msg); |
|
} |
|
}; |
|
not.throws = function(blk, exp, msg) { |
|
if (!msg && typeof exp === "string") { |
|
msg = exp; |
|
exp = null; |
|
} |
|
try { |
|
blk(); |
|
} catch (err) { |
|
if (typeof exp === "function") { |
|
assert(!exp(err), true, false, "not.throws", false, "Expected function not to throw matching exception", msg); |
|
} else if (exp instanceof RegExp) { |
|
assert(!exp.test(err.message), true, false, "not.throws", false, `Expected function not to throw exception matching \`${String(exp)}\` pattern`, msg); |
|
} else if (!exp) { |
|
assert(false, true, false, "not.throws", false, "Expected function not to throw", msg); |
|
} |
|
} |
|
}; |
|
|
|
|
|
var emptyOptions = {}; |
|
function toString(value, options) { |
|
const settings = options || emptyOptions; |
|
const includeImageAlt = typeof settings.includeImageAlt === "boolean" ? settings.includeImageAlt : true; |
|
const includeHtml = typeof settings.includeHtml === "boolean" ? settings.includeHtml : true; |
|
return one(value, includeImageAlt, includeHtml); |
|
} |
|
function one(value, includeImageAlt, includeHtml) { |
|
if (node(value)) { |
|
if ("value" in value) { |
|
return value.type === "html" && !includeHtml ? "" : value.value; |
|
} |
|
if (includeImageAlt && "alt" in value && value.alt) { |
|
return value.alt; |
|
} |
|
if ("children" in value) { |
|
return all(value.children, includeImageAlt, includeHtml); |
|
} |
|
} |
|
if (Array.isArray(value)) { |
|
return all(value, includeImageAlt, includeHtml); |
|
} |
|
return ""; |
|
} |
|
function all(values2, includeImageAlt, includeHtml) { |
|
const result = []; |
|
let index2 = -1; |
|
while (++index2 < values2.length) { |
|
result[index2] = one(values2[index2], includeImageAlt, includeHtml); |
|
} |
|
return result.join(""); |
|
} |
|
function node(value) { |
|
return Boolean(value && typeof value === "object"); |
|
} |
|
|
|
|
|
var constants = ( |
|
|
|
{ |
|
attentionSideBefore: 1, |
|
|
|
attentionSideAfter: 2, |
|
|
|
atxHeadingOpeningFenceSizeMax: 6, |
|
|
|
autolinkDomainSizeMax: 63, |
|
|
|
autolinkSchemeSizeMax: 32, |
|
|
|
cdataOpeningString: "CDATA[", |
|
|
|
characterGroupWhitespace: 1, |
|
|
|
characterGroupPunctuation: 2, |
|
|
|
characterReferenceDecimalSizeMax: 7, |
|
|
|
characterReferenceHexadecimalSizeMax: 6, |
|
|
|
characterReferenceNamedSizeMax: 31, |
|
|
|
codeFencedSequenceSizeMin: 3, |
|
|
|
contentTypeDocument: "document", |
|
contentTypeFlow: "flow", |
|
contentTypeContent: "content", |
|
contentTypeString: "string", |
|
contentTypeText: "text", |
|
hardBreakPrefixSizeMin: 2, |
|
|
|
htmlRaw: 1, |
|
|
|
htmlComment: 2, |
|
|
|
htmlInstruction: 3, |
|
|
|
htmlDeclaration: 4, |
|
|
|
htmlCdata: 5, |
|
|
|
htmlBasic: 6, |
|
|
|
htmlComplete: 7, |
|
|
|
htmlRawSizeMax: 8, |
|
|
|
linkResourceDestinationBalanceMax: 32, |
|
|
|
linkReferenceSizeMax: 999, |
|
|
|
listItemValueSizeMax: 10, |
|
|
|
numericBaseDecimal: 10, |
|
numericBaseHexadecimal: 16, |
|
tabSize: 4, |
|
|
|
thematicBreakMarkerCountMin: 3, |
|
|
|
v8MaxSafeChunkSize: 1e4 |
|
|
|
} |
|
); |
|
|
|
|
|
function splice(list2, start, remove, items) { |
|
const end = list2.length; |
|
let chunkStart = 0; |
|
let parameters; |
|
if (start < 0) { |
|
start = -start > end ? 0 : end + start; |
|
} else { |
|
start = start > end ? end : start; |
|
} |
|
remove = remove > 0 ? remove : 0; |
|
if (items.length < constants.v8MaxSafeChunkSize) { |
|
parameters = Array.from(items); |
|
parameters.unshift(start, remove); |
|
list2.splice(...parameters); |
|
} else { |
|
if (remove) list2.splice(start, remove); |
|
while (chunkStart < items.length) { |
|
parameters = items.slice( |
|
chunkStart, |
|
chunkStart + constants.v8MaxSafeChunkSize |
|
); |
|
parameters.unshift(start, 0); |
|
list2.splice(...parameters); |
|
chunkStart += constants.v8MaxSafeChunkSize; |
|
start += constants.v8MaxSafeChunkSize; |
|
} |
|
} |
|
} |
|
function push(list2, items) { |
|
if (list2.length > 0) { |
|
splice(list2, list2.length, 0, items); |
|
return list2; |
|
} |
|
return items; |
|
} |
|
|
|
|
|
var hasOwnProperty = {}.hasOwnProperty; |
|
function combineExtensions(extensions) { |
|
const all2 = {}; |
|
let index2 = -1; |
|
while (++index2 < extensions.length) { |
|
syntaxExtension(all2, extensions[index2]); |
|
} |
|
return all2; |
|
} |
|
function syntaxExtension(all2, extension2) { |
|
let hook; |
|
for (hook in extension2) { |
|
const maybe = hasOwnProperty.call(all2, hook) ? all2[hook] : void 0; |
|
const left = maybe || (all2[hook] = {}); |
|
const right = extension2[hook]; |
|
let code; |
|
if (right) { |
|
for (code in right) { |
|
if (!hasOwnProperty.call(left, code)) left[code] = []; |
|
const value = right[code]; |
|
constructs( |
|
|
|
left[code], |
|
Array.isArray(value) ? value : value ? [value] : [] |
|
); |
|
} |
|
} |
|
} |
|
} |
|
function constructs(existing, list2) { |
|
let index2 = -1; |
|
const before = []; |
|
while (++index2 < list2.length) { |
|
; |
|
(list2[index2].add === "after" ? existing : before).push(list2[index2]); |
|
} |
|
splice(existing, 0, 0, before); |
|
} |
|
|
|
|
|
var codes = ( |
|
|
|
{ |
|
carriageReturn: -5, |
|
lineFeed: -4, |
|
carriageReturnLineFeed: -3, |
|
horizontalTab: -2, |
|
virtualSpace: -1, |
|
eof: null, |
|
nul: 0, |
|
soh: 1, |
|
stx: 2, |
|
etx: 3, |
|
eot: 4, |
|
enq: 5, |
|
ack: 6, |
|
bel: 7, |
|
bs: 8, |
|
ht: 9, |
|
|
|
lf: 10, |
|
|
|
vt: 11, |
|
|
|
ff: 12, |
|
|
|
cr: 13, |
|
|
|
so: 14, |
|
si: 15, |
|
dle: 16, |
|
dc1: 17, |
|
dc2: 18, |
|
dc3: 19, |
|
dc4: 20, |
|
nak: 21, |
|
syn: 22, |
|
etb: 23, |
|
can: 24, |
|
em: 25, |
|
sub: 26, |
|
esc: 27, |
|
fs: 28, |
|
gs: 29, |
|
rs: 30, |
|
us: 31, |
|
space: 32, |
|
exclamationMark: 33, |
|
|
|
quotationMark: 34, |
|
|
|
numberSign: 35, |
|
|
|
dollarSign: 36, |
|
|
|
percentSign: 37, |
|
|
|
ampersand: 38, |
|
|
|
apostrophe: 39, |
|
|
|
leftParenthesis: 40, |
|
|
|
rightParenthesis: 41, |
|
|
|
asterisk: 42, |
|
|
|
plusSign: 43, |
|
|
|
comma: 44, |
|
|
|
dash: 45, |
|
|
|
dot: 46, |
|
|
|
slash: 47, |
|
|
|
digit0: 48, |
|
|
|
digit1: 49, |
|
|
|
digit2: 50, |
|
|
|
digit3: 51, |
|
|
|
digit4: 52, |
|
|
|
digit5: 53, |
|
|
|
digit6: 54, |
|
|
|
digit7: 55, |
|
|
|
digit8: 56, |
|
|
|
digit9: 57, |
|
|
|
colon: 58, |
|
|
|
semicolon: 59, |
|
|
|
lessThan: 60, |
|
|
|
equalsTo: 61, |
|
|
|
greaterThan: 62, |
|
|
|
questionMark: 63, |
|
|
|
atSign: 64, |
|
|
|
uppercaseA: 65, |
|
|
|
uppercaseB: 66, |
|
|
|
uppercaseC: 67, |
|
|
|
uppercaseD: 68, |
|
|
|
uppercaseE: 69, |
|
|
|
uppercaseF: 70, |
|
|
|
uppercaseG: 71, |
|
|
|
uppercaseH: 72, |
|
|
|
uppercaseI: 73, |
|
|
|
uppercaseJ: 74, |
|
|
|
uppercaseK: 75, |
|
|
|
uppercaseL: 76, |
|
|
|
uppercaseM: 77, |
|
|
|
uppercaseN: 78, |
|
|
|
uppercaseO: 79, |
|
|
|
uppercaseP: 80, |
|
|
|
uppercaseQ: 81, |
|
|
|
uppercaseR: 82, |
|
|
|
uppercaseS: 83, |
|
|
|
uppercaseT: 84, |
|
|
|
uppercaseU: 85, |
|
|
|
uppercaseV: 86, |
|
|
|
uppercaseW: 87, |
|
|
|
uppercaseX: 88, |
|
|
|
uppercaseY: 89, |
|
|
|
uppercaseZ: 90, |
|
|
|
leftSquareBracket: 91, |
|
|
|
backslash: 92, |
|
|
|
rightSquareBracket: 93, |
|
|
|
caret: 94, |
|
|
|
underscore: 95, |
|
|
|
graveAccent: 96, |
|
|
|
lowercaseA: 97, |
|
|
|
lowercaseB: 98, |
|
|
|
lowercaseC: 99, |
|
|
|
lowercaseD: 100, |
|
|
|
lowercaseE: 101, |
|
|
|
lowercaseF: 102, |
|
|
|
lowercaseG: 103, |
|
|
|
lowercaseH: 104, |
|
|
|
lowercaseI: 105, |
|
|
|
lowercaseJ: 106, |
|
|
|
lowercaseK: 107, |
|
|
|
lowercaseL: 108, |
|
|
|
lowercaseM: 109, |
|
|
|
lowercaseN: 110, |
|
|
|
lowercaseO: 111, |
|
|
|
lowercaseP: 112, |
|
|
|
lowercaseQ: 113, |
|
|
|
lowercaseR: 114, |
|
|
|
lowercaseS: 115, |
|
|
|
lowercaseT: 116, |
|
|
|
lowercaseU: 117, |
|
|
|
lowercaseV: 118, |
|
|
|
lowercaseW: 119, |
|
|
|
lowercaseX: 120, |
|
|
|
lowercaseY: 121, |
|
|
|
lowercaseZ: 122, |
|
|
|
leftCurlyBrace: 123, |
|
|
|
verticalBar: 124, |
|
|
|
rightCurlyBrace: 125, |
|
|
|
tilde: 126, |
|
|
|
del: 127, |
|
|
|
byteOrderMarker: 65279, |
|
|
|
replacementCharacter: 65533 |
|
|
|
} |
|
); |
|
|
|
|
|
var unicodePunctuationRegex = /[!-/:-@[-`{-~\u00A1\u00A7\u00AB\u00B6\u00B7\u00BB\u00BF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061D-\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u09FD\u0A76\u0AF0\u0C77\u0C84\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1B7D\u1B7E\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E4F\u2E52-\u2E5D\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]/; |
|
|
|
|
|
var asciiAlpha = regexCheck(/[A-Za-z]/); |
|
var asciiAlphanumeric = regexCheck(/[\dA-Za-z]/); |
|
var asciiAtext = regexCheck(/[#-'*+\--9=?A-Z^-~]/); |
|
function asciiControl(code) { |
|
return ( |
|
|
|
|
|
code !== null && (code < codes.space || code === codes.del) |
|
); |
|
} |
|
var asciiDigit = regexCheck(/\d/); |
|
var asciiHexDigit = regexCheck(/[\dA-Fa-f]/); |
|
var asciiPunctuation = regexCheck(/[!-/:-@[-`{-~]/); |
|
function markdownLineEnding(code) { |
|
return code !== null && code < codes.horizontalTab; |
|
} |
|
function markdownLineEndingOrSpace(code) { |
|
return code !== null && (code < codes.nul || code === codes.space); |
|
} |
|
function markdownSpace(code) { |
|
return code === codes.horizontalTab || code === codes.virtualSpace || code === codes.space; |
|
} |
|
var unicodePunctuation = regexCheck(unicodePunctuationRegex); |
|
var unicodeWhitespace = regexCheck(/\s/); |
|
function regexCheck(regex) { |
|
return check; |
|
function check(code) { |
|
return code !== null && regex.test(String.fromCharCode(code)); |
|
} |
|
} |
|
|
|
|
|
function factorySpace(effects, ok2, type, max) { |
|
const limit = max ? max - 1 : Number.POSITIVE_INFINITY; |
|
let size = 0; |
|
return start; |
|
function start(code) { |
|
if (markdownSpace(code)) { |
|
effects.enter(type); |
|
return prefix(code); |
|
} |
|
return ok2(code); |
|
} |
|
function prefix(code) { |
|
if (markdownSpace(code) && size++ < limit) { |
|
effects.consume(code); |
|
return prefix; |
|
} |
|
effects.exit(type); |
|
return ok2(code); |
|
} |
|
} |
|
|
|
|
|
var types = ( |
|
|
|
{ |
|
|
|
data: "data", |
|
|
|
|
|
whitespace: "whitespace", |
|
|
|
|
|
lineEnding: "lineEnding", |
|
|
|
lineEndingBlank: "lineEndingBlank", |
|
|
|
|
|
linePrefix: "linePrefix", |
|
|
|
|
|
lineSuffix: "lineSuffix", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
atxHeading: "atxHeading", |
|
|
|
atxHeadingSequence: "atxHeadingSequence", |
|
|
|
|
|
atxHeadingText: "atxHeadingText", |
|
|
|
|
|
autolink: "autolink", |
|
|
|
autolinkEmail: "autolinkEmail", |
|
|
|
autolinkMarker: "autolinkMarker", |
|
|
|
autolinkProtocol: "autolinkProtocol", |
|
|
|
|
|
characterEscape: "characterEscape", |
|
|
|
characterEscapeValue: "characterEscapeValue", |
|
|
|
|
|
|
|
|
|
characterReference: "characterReference", |
|
|
|
characterReferenceMarker: "characterReferenceMarker", |
|
|
|
characterReferenceMarkerNumeric: "characterReferenceMarkerNumeric", |
|
|
|
characterReferenceMarkerHexadecimal: "characterReferenceMarkerHexadecimal", |
|
|
|
characterReferenceValue: "characterReferenceValue", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codeFenced: "codeFenced", |
|
|
|
|
|
codeFencedFence: "codeFencedFence", |
|
|
|
codeFencedFenceSequence: "codeFencedFenceSequence", |
|
|
|
|
|
codeFencedFenceInfo: "codeFencedFenceInfo", |
|
|
|
|
|
codeFencedFenceMeta: "codeFencedFenceMeta", |
|
|
|
codeFlowValue: "codeFlowValue", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
codeIndented: "codeIndented", |
|
|
|
|
|
|
|
codeText: "codeText", |
|
codeTextData: "codeTextData", |
|
|
|
codeTextPadding: "codeTextPadding", |
|
|
|
codeTextSequence: "codeTextSequence", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content: "content", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
definition: "definition", |
|
|
|
|
|
|
|
definitionDestination: "definitionDestination", |
|
|
|
|
|
|
|
|
|
definitionDestinationLiteral: "definitionDestinationLiteral", |
|
|
|
definitionDestinationLiteralMarker: "definitionDestinationLiteralMarker", |
|
|
|
|
|
|
|
definitionDestinationRaw: "definitionDestinationRaw", |
|
|
|
|
|
definitionDestinationString: "definitionDestinationString", |
|
|
|
|
|
definitionLabel: "definitionLabel", |
|
|
|
definitionLabelMarker: "definitionLabelMarker", |
|
|
|
|
|
definitionLabelString: "definitionLabelString", |
|
|
|
definitionMarker: "definitionMarker", |
|
|
|
|
|
definitionTitle: "definitionTitle", |
|
|
|
definitionTitleMarker: "definitionTitleMarker", |
|
|
|
|
|
definitionTitleString: "definitionTitleString", |
|
|
|
|
|
emphasis: "emphasis", |
|
|
|
emphasisSequence: "emphasisSequence", |
|
|
|
|
|
emphasisText: "emphasisText", |
|
|
|
escapeMarker: "escapeMarker", |
|
|
|
|
|
hardBreakEscape: "hardBreakEscape", |
|
|
|
|
|
hardBreakTrailing: "hardBreakTrailing", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
htmlFlow: "htmlFlow", |
|
htmlFlowData: "htmlFlowData", |
|
|
|
|
|
htmlText: "htmlText", |
|
htmlTextData: "htmlTextData", |
|
|
|
|
|
|
|
image: "image", |
|
|
|
|
|
label: "label", |
|
|
|
|
|
labelText: "labelText", |
|
|
|
|
|
labelLink: "labelLink", |
|
|
|
|
|
labelImage: "labelImage", |
|
|
|
labelMarker: "labelMarker", |
|
|
|
labelImageMarker: "labelImageMarker", |
|
|
|
|
|
labelEnd: "labelEnd", |
|
|
|
|
|
link: "link", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
paragraph: "paragraph", |
|
|
|
|
|
reference: "reference", |
|
|
|
referenceMarker: "referenceMarker", |
|
|
|
|
|
referenceString: "referenceString", |
|
|
|
|
|
|
|
resource: "resource", |
|
|
|
|
|
resourceDestination: "resourceDestination", |
|
|
|
|
|
|
|
resourceDestinationLiteral: "resourceDestinationLiteral", |
|
|
|
resourceDestinationLiteralMarker: "resourceDestinationLiteralMarker", |
|
|
|
|
|
resourceDestinationRaw: "resourceDestinationRaw", |
|
|
|
|
|
resourceDestinationString: "resourceDestinationString", |
|
|
|
resourceMarker: "resourceMarker", |
|
|
|
|
|
resourceTitle: "resourceTitle", |
|
|
|
resourceTitleMarker: "resourceTitleMarker", |
|
|
|
|
|
resourceTitleString: "resourceTitleString", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setextHeading: "setextHeading", |
|
|
|
|
|
setextHeadingText: "setextHeadingText", |
|
|
|
|
|
setextHeadingLine: "setextHeadingLine", |
|
|
|
setextHeadingLineSequence: "setextHeadingLineSequence", |
|
|
|
|
|
strong: "strong", |
|
|
|
strongSequence: "strongSequence", |
|
|
|
|
|
strongText: "strongText", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
thematicBreak: "thematicBreak", |
|
|
|
thematicBreakSequence: "thematicBreakSequence", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
blockQuote: "blockQuote", |
|
|
|
blockQuotePrefix: "blockQuotePrefix", |
|
|
|
blockQuoteMarker: "blockQuoteMarker", |
|
|
|
blockQuotePrefixWhitespace: "blockQuotePrefixWhitespace", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listOrdered: "listOrdered", |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
listUnordered: "listUnordered", |
|
|
|
listItemIndent: "listItemIndent", |
|
|
|
listItemMarker: "listItemMarker", |
|
|
|
|
|
|
|
listItemPrefix: "listItemPrefix", |
|
|
|
listItemPrefixWhitespace: "listItemPrefixWhitespace", |
|
|
|
listItemValue: "listItemValue", |
|
|
|
chunkDocument: "chunkDocument", |
|
chunkContent: "chunkContent", |
|
chunkFlow: "chunkFlow", |
|
chunkText: "chunkText", |
|
chunkString: "chunkString" |
|
} |
|
); |
|
|
|
|
|
var content = { tokenize: initializeContent }; |
|
function initializeContent(effects) { |
|
const contentStart = effects.attempt( |
|
this.parser.constructs.contentInitial, |
|
afterContentStartConstruct, |
|
paragraphInitial |
|
); |
|
let previous2; |
|
return contentStart; |
|
function afterContentStartConstruct(code) { |
|
ok( |
|
code === codes.eof || markdownLineEnding(code), |
|
"expected eol or eof" |
|
); |
|
if (code === codes.eof) { |
|
effects.consume(code); |
|
return; |
|
} |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return factorySpace(effects, contentStart, types.linePrefix); |
|
} |
|
function paragraphInitial(code) { |
|
ok( |
|
code !== codes.eof && !markdownLineEnding(code), |
|
"expected anything other than a line ending or EOF" |
|
); |
|
effects.enter(types.paragraph); |
|
return lineStart(code); |
|
} |
|
function lineStart(code) { |
|
const token = effects.enter(types.chunkText, { |
|
contentType: constants.contentTypeText, |
|
previous: previous2 |
|
}); |
|
if (previous2) { |
|
previous2.next = token; |
|
} |
|
previous2 = token; |
|
return data(code); |
|
} |
|
function data(code) { |
|
if (code === codes.eof) { |
|
effects.exit(types.chunkText); |
|
effects.exit(types.paragraph); |
|
effects.consume(code); |
|
return; |
|
} |
|
if (markdownLineEnding(code)) { |
|
effects.consume(code); |
|
effects.exit(types.chunkText); |
|
return lineStart; |
|
} |
|
effects.consume(code); |
|
return data; |
|
} |
|
} |
|
|
|
|
|
var document2 = { tokenize: initializeDocument }; |
|
var containerConstruct = { tokenize: tokenizeContainer }; |
|
function initializeDocument(effects) { |
|
const self = this; |
|
const stack = []; |
|
let continued = 0; |
|
let childFlow; |
|
let childToken; |
|
let lineStartOffset; |
|
return start; |
|
function start(code) { |
|
if (continued < stack.length) { |
|
const item = stack[continued]; |
|
self.containerState = item[1]; |
|
ok( |
|
item[0].continuation, |
|
"expected `continuation` to be defined on container construct" |
|
); |
|
return effects.attempt( |
|
item[0].continuation, |
|
documentContinue, |
|
checkNewContainers |
|
)(code); |
|
} |
|
return checkNewContainers(code); |
|
} |
|
function documentContinue(code) { |
|
ok( |
|
self.containerState, |
|
"expected `containerState` to be defined after continuation" |
|
); |
|
continued++; |
|
if (self.containerState._closeFlow) { |
|
self.containerState._closeFlow = void 0; |
|
if (childFlow) { |
|
closeFlow(); |
|
} |
|
const indexBeforeExits = self.events.length; |
|
let indexBeforeFlow = indexBeforeExits; |
|
let point3; |
|
while (indexBeforeFlow--) { |
|
if (self.events[indexBeforeFlow][0] === "exit" && self.events[indexBeforeFlow][1].type === types.chunkFlow) { |
|
point3 = self.events[indexBeforeFlow][1].end; |
|
break; |
|
} |
|
} |
|
ok(point3, "could not find previous flow chunk"); |
|
exitContainers(continued); |
|
let index2 = indexBeforeExits; |
|
while (index2 < self.events.length) { |
|
self.events[index2][1].end = Object.assign({}, point3); |
|
index2++; |
|
} |
|
splice( |
|
self.events, |
|
indexBeforeFlow + 1, |
|
0, |
|
self.events.slice(indexBeforeExits) |
|
); |
|
self.events.length = index2; |
|
return checkNewContainers(code); |
|
} |
|
return start(code); |
|
} |
|
function checkNewContainers(code) { |
|
if (continued === stack.length) { |
|
if (!childFlow) { |
|
return documentContinued(code); |
|
} |
|
if (childFlow.currentConstruct && childFlow.currentConstruct.concrete) { |
|
return flowStart(code); |
|
} |
|
self.interrupt = Boolean( |
|
childFlow.currentConstruct && !childFlow._gfmTableDynamicInterruptHack |
|
); |
|
} |
|
self.containerState = {}; |
|
return effects.check( |
|
containerConstruct, |
|
thereIsANewContainer, |
|
thereIsNoNewContainer |
|
)(code); |
|
} |
|
function thereIsANewContainer(code) { |
|
if (childFlow) closeFlow(); |
|
exitContainers(continued); |
|
return documentContinued(code); |
|
} |
|
function thereIsNoNewContainer(code) { |
|
self.parser.lazy[self.now().line] = continued !== stack.length; |
|
lineStartOffset = self.now().offset; |
|
return flowStart(code); |
|
} |
|
function documentContinued(code) { |
|
self.containerState = {}; |
|
return effects.attempt( |
|
containerConstruct, |
|
containerContinue, |
|
flowStart |
|
)(code); |
|
} |
|
function containerContinue(code) { |
|
ok( |
|
self.currentConstruct, |
|
"expected `currentConstruct` to be defined on tokenizer" |
|
); |
|
ok( |
|
self.containerState, |
|
"expected `containerState` to be defined on tokenizer" |
|
); |
|
continued++; |
|
stack.push([self.currentConstruct, self.containerState]); |
|
return documentContinued(code); |
|
} |
|
function flowStart(code) { |
|
if (code === codes.eof) { |
|
if (childFlow) closeFlow(); |
|
exitContainers(0); |
|
effects.consume(code); |
|
return; |
|
} |
|
childFlow = childFlow || self.parser.flow(self.now()); |
|
effects.enter(types.chunkFlow, { |
|
contentType: constants.contentTypeFlow, |
|
previous: childToken, |
|
_tokenizer: childFlow |
|
}); |
|
return flowContinue(code); |
|
} |
|
function flowContinue(code) { |
|
if (code === codes.eof) { |
|
writeToChild(effects.exit(types.chunkFlow), true); |
|
exitContainers(0); |
|
effects.consume(code); |
|
return; |
|
} |
|
if (markdownLineEnding(code)) { |
|
effects.consume(code); |
|
writeToChild(effects.exit(types.chunkFlow)); |
|
continued = 0; |
|
self.interrupt = void 0; |
|
return start; |
|
} |
|
effects.consume(code); |
|
return flowContinue; |
|
} |
|
function writeToChild(token, eof) { |
|
ok(childFlow, "expected `childFlow` to be defined when continuing"); |
|
const stream = self.sliceStream(token); |
|
if (eof) stream.push(null); |
|
token.previous = childToken; |
|
if (childToken) childToken.next = token; |
|
childToken = token; |
|
childFlow.defineSkip(token.start); |
|
childFlow.write(stream); |
|
if (self.parser.lazy[token.start.line]) { |
|
let index2 = childFlow.events.length; |
|
while (index2--) { |
|
if ( |
|
|
|
childFlow.events[index2][1].start.offset < lineStartOffset && |
|
(!childFlow.events[index2][1].end || |
|
childFlow.events[index2][1].end.offset > lineStartOffset) |
|
) { |
|
return; |
|
} |
|
} |
|
const indexBeforeExits = self.events.length; |
|
let indexBeforeFlow = indexBeforeExits; |
|
let seen; |
|
let point3; |
|
while (indexBeforeFlow--) { |
|
if (self.events[indexBeforeFlow][0] === "exit" && self.events[indexBeforeFlow][1].type === types.chunkFlow) { |
|
if (seen) { |
|
point3 = self.events[indexBeforeFlow][1].end; |
|
break; |
|
} |
|
seen = true; |
|
} |
|
} |
|
ok(point3, "could not find previous flow chunk"); |
|
exitContainers(continued); |
|
index2 = indexBeforeExits; |
|
while (index2 < self.events.length) { |
|
self.events[index2][1].end = Object.assign({}, point3); |
|
index2++; |
|
} |
|
splice( |
|
self.events, |
|
indexBeforeFlow + 1, |
|
0, |
|
self.events.slice(indexBeforeExits) |
|
); |
|
self.events.length = index2; |
|
} |
|
} |
|
function exitContainers(size) { |
|
let index2 = stack.length; |
|
while (index2-- > size) { |
|
const entry = stack[index2]; |
|
self.containerState = entry[1]; |
|
ok( |
|
entry[0].exit, |
|
"expected `exit` to be defined on container construct" |
|
); |
|
entry[0].exit.call(self, effects); |
|
} |
|
stack.length = size; |
|
} |
|
function closeFlow() { |
|
ok( |
|
self.containerState, |
|
"expected `containerState` to be defined when closing flow" |
|
); |
|
ok(childFlow, "expected `childFlow` to be defined when closing it"); |
|
childFlow.write([codes.eof]); |
|
childToken = void 0; |
|
childFlow = void 0; |
|
self.containerState._closeFlow = void 0; |
|
} |
|
} |
|
function tokenizeContainer(effects, ok2, nok) { |
|
ok( |
|
this.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
return factorySpace( |
|
effects, |
|
effects.attempt(this.parser.constructs.document, ok2, nok), |
|
types.linePrefix, |
|
this.parser.constructs.disable.null.includes("codeIndented") ? void 0 : constants.tabSize |
|
); |
|
} |
|
|
|
|
|
function classifyCharacter(code) { |
|
if (code === codes.eof || markdownLineEndingOrSpace(code) || unicodeWhitespace(code)) { |
|
return constants.characterGroupWhitespace; |
|
} |
|
if (unicodePunctuation(code)) { |
|
return constants.characterGroupPunctuation; |
|
} |
|
} |
|
|
|
|
|
function resolveAll(constructs2, events, context) { |
|
const called = []; |
|
let index2 = -1; |
|
while (++index2 < constructs2.length) { |
|
const resolve = constructs2[index2].resolveAll; |
|
if (resolve && !called.includes(resolve)) { |
|
events = resolve(events, context); |
|
called.push(resolve); |
|
} |
|
} |
|
return events; |
|
} |
|
|
|
|
|
var attention = { |
|
name: "attention", |
|
tokenize: tokenizeAttention, |
|
resolveAll: resolveAllAttention |
|
}; |
|
function resolveAllAttention(events, context) { |
|
let index2 = -1; |
|
let open; |
|
let group; |
|
let text3; |
|
let openingSequence; |
|
let closingSequence; |
|
let use; |
|
let nextEvents; |
|
let offset; |
|
while (++index2 < events.length) { |
|
if (events[index2][0] === "enter" && events[index2][1].type === "attentionSequence" && events[index2][1]._close) { |
|
open = index2; |
|
while (open--) { |
|
if (events[open][0] === "exit" && events[open][1].type === "attentionSequence" && events[open][1]._open && |
|
context.sliceSerialize(events[open][1]).charCodeAt(0) === context.sliceSerialize(events[index2][1]).charCodeAt(0)) { |
|
if ((events[open][1]._close || events[index2][1]._open) && (events[index2][1].end.offset - events[index2][1].start.offset) % 3 && !((events[open][1].end.offset - events[open][1].start.offset + events[index2][1].end.offset - events[index2][1].start.offset) % 3)) { |
|
continue; |
|
} |
|
use = events[open][1].end.offset - events[open][1].start.offset > 1 && events[index2][1].end.offset - events[index2][1].start.offset > 1 ? 2 : 1; |
|
const start = Object.assign({}, events[open][1].end); |
|
const end = Object.assign({}, events[index2][1].start); |
|
movePoint(start, -use); |
|
movePoint(end, use); |
|
openingSequence = { |
|
type: use > 1 ? types.strongSequence : types.emphasisSequence, |
|
start, |
|
end: Object.assign({}, events[open][1].end) |
|
}; |
|
closingSequence = { |
|
type: use > 1 ? types.strongSequence : types.emphasisSequence, |
|
start: Object.assign({}, events[index2][1].start), |
|
end |
|
}; |
|
text3 = { |
|
type: use > 1 ? types.strongText : types.emphasisText, |
|
start: Object.assign({}, events[open][1].end), |
|
end: Object.assign({}, events[index2][1].start) |
|
}; |
|
group = { |
|
type: use > 1 ? types.strong : types.emphasis, |
|
start: Object.assign({}, openingSequence.start), |
|
end: Object.assign({}, closingSequence.end) |
|
}; |
|
events[open][1].end = Object.assign({}, openingSequence.start); |
|
events[index2][1].start = Object.assign({}, closingSequence.end); |
|
nextEvents = []; |
|
if (events[open][1].end.offset - events[open][1].start.offset) { |
|
nextEvents = push(nextEvents, [ |
|
["enter", events[open][1], context], |
|
["exit", events[open][1], context] |
|
]); |
|
} |
|
nextEvents = push(nextEvents, [ |
|
["enter", group, context], |
|
["enter", openingSequence, context], |
|
["exit", openingSequence, context], |
|
["enter", text3, context] |
|
]); |
|
ok( |
|
context.parser.constructs.insideSpan.null, |
|
"expected `insideSpan` to be populated" |
|
); |
|
nextEvents = push( |
|
nextEvents, |
|
resolveAll( |
|
context.parser.constructs.insideSpan.null, |
|
events.slice(open + 1, index2), |
|
context |
|
) |
|
); |
|
nextEvents = push(nextEvents, [ |
|
["exit", text3, context], |
|
["enter", closingSequence, context], |
|
["exit", closingSequence, context], |
|
["exit", group, context] |
|
]); |
|
if (events[index2][1].end.offset - events[index2][1].start.offset) { |
|
offset = 2; |
|
nextEvents = push(nextEvents, [ |
|
["enter", events[index2][1], context], |
|
["exit", events[index2][1], context] |
|
]); |
|
} else { |
|
offset = 0; |
|
} |
|
splice(events, open - 1, index2 - open + 3, nextEvents); |
|
index2 = open + nextEvents.length - offset - 2; |
|
break; |
|
} |
|
} |
|
} |
|
} |
|
index2 = -1; |
|
while (++index2 < events.length) { |
|
if (events[index2][1].type === "attentionSequence") { |
|
events[index2][1].type = "data"; |
|
} |
|
} |
|
return events; |
|
} |
|
function tokenizeAttention(effects, ok2) { |
|
const attentionMarkers2 = this.parser.constructs.attentionMarkers.null; |
|
const previous2 = this.previous; |
|
const before = classifyCharacter(previous2); |
|
let marker; |
|
return start; |
|
function start(code) { |
|
ok( |
|
code === codes.asterisk || code === codes.underscore, |
|
"expected asterisk or underscore" |
|
); |
|
marker = code; |
|
effects.enter("attentionSequence"); |
|
return inside(code); |
|
} |
|
function inside(code) { |
|
if (code === marker) { |
|
effects.consume(code); |
|
return inside; |
|
} |
|
const token = effects.exit("attentionSequence"); |
|
const after = classifyCharacter(code); |
|
ok(attentionMarkers2, "expected `attentionMarkers` to be populated"); |
|
const open = !after || after === constants.characterGroupPunctuation && before || attentionMarkers2.includes(code); |
|
const close = !before || before === constants.characterGroupPunctuation && after || attentionMarkers2.includes(previous2); |
|
token._open = Boolean( |
|
marker === codes.asterisk ? open : open && (before || !close) |
|
); |
|
token._close = Boolean( |
|
marker === codes.asterisk ? close : close && (after || !open) |
|
); |
|
return ok2(code); |
|
} |
|
} |
|
function movePoint(point3, offset) { |
|
point3.column += offset; |
|
point3.offset += offset; |
|
point3._bufferIndex += offset; |
|
} |
|
|
|
|
|
var autolink = { name: "autolink", tokenize: tokenizeAutolink }; |
|
function tokenizeAutolink(effects, ok2, nok) { |
|
let size = 0; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.lessThan, "expected `<`"); |
|
effects.enter(types.autolink); |
|
effects.enter(types.autolinkMarker); |
|
effects.consume(code); |
|
effects.exit(types.autolinkMarker); |
|
effects.enter(types.autolinkProtocol); |
|
return open; |
|
} |
|
function open(code) { |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
return schemeOrEmailAtext; |
|
} |
|
return emailAtext(code); |
|
} |
|
function schemeOrEmailAtext(code) { |
|
if (code === codes.plusSign || code === codes.dash || code === codes.dot || asciiAlphanumeric(code)) { |
|
size = 1; |
|
return schemeInsideOrEmailAtext(code); |
|
} |
|
return emailAtext(code); |
|
} |
|
function schemeInsideOrEmailAtext(code) { |
|
if (code === codes.colon) { |
|
effects.consume(code); |
|
size = 0; |
|
return urlInside; |
|
} |
|
if ((code === codes.plusSign || code === codes.dash || code === codes.dot || asciiAlphanumeric(code)) && size++ < constants.autolinkSchemeSizeMax) { |
|
effects.consume(code); |
|
return schemeInsideOrEmailAtext; |
|
} |
|
size = 0; |
|
return emailAtext(code); |
|
} |
|
function urlInside(code) { |
|
if (code === codes.greaterThan) { |
|
effects.exit(types.autolinkProtocol); |
|
effects.enter(types.autolinkMarker); |
|
effects.consume(code); |
|
effects.exit(types.autolinkMarker); |
|
effects.exit(types.autolink); |
|
return ok2; |
|
} |
|
if (code === codes.eof || code === codes.space || code === codes.lessThan || asciiControl(code)) { |
|
return nok(code); |
|
} |
|
effects.consume(code); |
|
return urlInside; |
|
} |
|
function emailAtext(code) { |
|
if (code === codes.atSign) { |
|
effects.consume(code); |
|
return emailAtSignOrDot; |
|
} |
|
if (asciiAtext(code)) { |
|
effects.consume(code); |
|
return emailAtext; |
|
} |
|
return nok(code); |
|
} |
|
function emailAtSignOrDot(code) { |
|
return asciiAlphanumeric(code) ? emailLabel(code) : nok(code); |
|
} |
|
function emailLabel(code) { |
|
if (code === codes.dot) { |
|
effects.consume(code); |
|
size = 0; |
|
return emailAtSignOrDot; |
|
} |
|
if (code === codes.greaterThan) { |
|
effects.exit(types.autolinkProtocol).type = types.autolinkEmail; |
|
effects.enter(types.autolinkMarker); |
|
effects.consume(code); |
|
effects.exit(types.autolinkMarker); |
|
effects.exit(types.autolink); |
|
return ok2; |
|
} |
|
return emailValue(code); |
|
} |
|
function emailValue(code) { |
|
if ((code === codes.dash || asciiAlphanumeric(code)) && size++ < constants.autolinkDomainSizeMax) { |
|
const next = code === codes.dash ? emailValue : emailLabel; |
|
effects.consume(code); |
|
return next; |
|
} |
|
return nok(code); |
|
} |
|
} |
|
|
|
|
|
var blankLine = { tokenize: tokenizeBlankLine, partial: true }; |
|
function tokenizeBlankLine(effects, ok2, nok) { |
|
return start; |
|
function start(code) { |
|
return markdownSpace(code) ? factorySpace(effects, after, types.linePrefix)(code) : after(code); |
|
} |
|
function after(code) { |
|
return code === codes.eof || markdownLineEnding(code) ? ok2(code) : nok(code); |
|
} |
|
} |
|
|
|
|
|
var blockQuote = { |
|
name: "blockQuote", |
|
tokenize: tokenizeBlockQuoteStart, |
|
continuation: { tokenize: tokenizeBlockQuoteContinuation }, |
|
exit |
|
}; |
|
function tokenizeBlockQuoteStart(effects, ok2, nok) { |
|
const self = this; |
|
return start; |
|
function start(code) { |
|
if (code === codes.greaterThan) { |
|
const state = self.containerState; |
|
ok(state, "expected `containerState` to be defined in container"); |
|
if (!state.open) { |
|
effects.enter(types.blockQuote, { _container: true }); |
|
state.open = true; |
|
} |
|
effects.enter(types.blockQuotePrefix); |
|
effects.enter(types.blockQuoteMarker); |
|
effects.consume(code); |
|
effects.exit(types.blockQuoteMarker); |
|
return after; |
|
} |
|
return nok(code); |
|
} |
|
function after(code) { |
|
if (markdownSpace(code)) { |
|
effects.enter(types.blockQuotePrefixWhitespace); |
|
effects.consume(code); |
|
effects.exit(types.blockQuotePrefixWhitespace); |
|
effects.exit(types.blockQuotePrefix); |
|
return ok2; |
|
} |
|
effects.exit(types.blockQuotePrefix); |
|
return ok2(code); |
|
} |
|
} |
|
function tokenizeBlockQuoteContinuation(effects, ok2, nok) { |
|
const self = this; |
|
return contStart; |
|
function contStart(code) { |
|
if (markdownSpace(code)) { |
|
ok( |
|
self.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
return factorySpace( |
|
effects, |
|
contBefore, |
|
types.linePrefix, |
|
self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : constants.tabSize |
|
)(code); |
|
} |
|
return contBefore(code); |
|
} |
|
function contBefore(code) { |
|
return effects.attempt(blockQuote, ok2, nok)(code); |
|
} |
|
} |
|
function exit(effects) { |
|
effects.exit(types.blockQuote); |
|
} |
|
|
|
|
|
var characterEscape = { |
|
name: "characterEscape", |
|
tokenize: tokenizeCharacterEscape |
|
}; |
|
function tokenizeCharacterEscape(effects, ok2, nok) { |
|
return start; |
|
function start(code) { |
|
ok(code === codes.backslash, "expected `\\`"); |
|
effects.enter(types.characterEscape); |
|
effects.enter(types.escapeMarker); |
|
effects.consume(code); |
|
effects.exit(types.escapeMarker); |
|
return inside; |
|
} |
|
function inside(code) { |
|
if (asciiPunctuation(code)) { |
|
effects.enter(types.characterEscapeValue); |
|
effects.consume(code); |
|
effects.exit(types.characterEscapeValue); |
|
effects.exit(types.characterEscape); |
|
return ok2; |
|
} |
|
return nok(code); |
|
} |
|
} |
|
|
|
|
|
var element = document.createElement("i"); |
|
function decodeNamedCharacterReference(value) { |
|
const characterReference2 = "&" + value + ";"; |
|
element.innerHTML = characterReference2; |
|
const char = element.textContent; |
|
if (char.charCodeAt(char.length - 1) === 59 && value !== "semi") { |
|
return false; |
|
} |
|
return char === characterReference2 ? false : char; |
|
} |
|
|
|
|
|
var characterReference = { |
|
name: "characterReference", |
|
tokenize: tokenizeCharacterReference |
|
}; |
|
function tokenizeCharacterReference(effects, ok2, nok) { |
|
const self = this; |
|
let size = 0; |
|
let max; |
|
let test; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.ampersand, "expected `&`"); |
|
effects.enter(types.characterReference); |
|
effects.enter(types.characterReferenceMarker); |
|
effects.consume(code); |
|
effects.exit(types.characterReferenceMarker); |
|
return open; |
|
} |
|
function open(code) { |
|
if (code === codes.numberSign) { |
|
effects.enter(types.characterReferenceMarkerNumeric); |
|
effects.consume(code); |
|
effects.exit(types.characterReferenceMarkerNumeric); |
|
return numeric; |
|
} |
|
effects.enter(types.characterReferenceValue); |
|
max = constants.characterReferenceNamedSizeMax; |
|
test = asciiAlphanumeric; |
|
return value(code); |
|
} |
|
function numeric(code) { |
|
if (code === codes.uppercaseX || code === codes.lowercaseX) { |
|
effects.enter(types.characterReferenceMarkerHexadecimal); |
|
effects.consume(code); |
|
effects.exit(types.characterReferenceMarkerHexadecimal); |
|
effects.enter(types.characterReferenceValue); |
|
max = constants.characterReferenceHexadecimalSizeMax; |
|
test = asciiHexDigit; |
|
return value; |
|
} |
|
effects.enter(types.characterReferenceValue); |
|
max = constants.characterReferenceDecimalSizeMax; |
|
test = asciiDigit; |
|
return value(code); |
|
} |
|
function value(code) { |
|
if (code === codes.semicolon && size) { |
|
const token = effects.exit(types.characterReferenceValue); |
|
if (test === asciiAlphanumeric && !decodeNamedCharacterReference(self.sliceSerialize(token))) { |
|
return nok(code); |
|
} |
|
effects.enter(types.characterReferenceMarker); |
|
effects.consume(code); |
|
effects.exit(types.characterReferenceMarker); |
|
effects.exit(types.characterReference); |
|
return ok2; |
|
} |
|
if (test(code) && size++ < max) { |
|
effects.consume(code); |
|
return value; |
|
} |
|
return nok(code); |
|
} |
|
} |
|
|
|
|
|
var nonLazyContinuation = { |
|
tokenize: tokenizeNonLazyContinuation, |
|
partial: true |
|
}; |
|
var codeFenced = { |
|
name: "codeFenced", |
|
tokenize: tokenizeCodeFenced, |
|
concrete: true |
|
}; |
|
function tokenizeCodeFenced(effects, ok2, nok) { |
|
const self = this; |
|
const closeStart = { tokenize: tokenizeCloseStart, partial: true }; |
|
let initialPrefix = 0; |
|
let sizeOpen = 0; |
|
let marker; |
|
return start; |
|
function start(code) { |
|
return beforeSequenceOpen(code); |
|
} |
|
function beforeSequenceOpen(code) { |
|
ok( |
|
code === codes.graveAccent || code === codes.tilde, |
|
"expected `` ` `` or `~`" |
|
); |
|
const tail = self.events[self.events.length - 1]; |
|
initialPrefix = tail && tail[1].type === types.linePrefix ? tail[2].sliceSerialize(tail[1], true).length : 0; |
|
marker = code; |
|
effects.enter(types.codeFenced); |
|
effects.enter(types.codeFencedFence); |
|
effects.enter(types.codeFencedFenceSequence); |
|
return sequenceOpen(code); |
|
} |
|
function sequenceOpen(code) { |
|
if (code === marker) { |
|
sizeOpen++; |
|
effects.consume(code); |
|
return sequenceOpen; |
|
} |
|
if (sizeOpen < constants.codeFencedSequenceSizeMin) { |
|
return nok(code); |
|
} |
|
effects.exit(types.codeFencedFenceSequence); |
|
return markdownSpace(code) ? factorySpace(effects, infoBefore, types.whitespace)(code) : infoBefore(code); |
|
} |
|
function infoBefore(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.codeFencedFence); |
|
return self.interrupt ? ok2(code) : effects.check(nonLazyContinuation, atNonLazyBreak, after)(code); |
|
} |
|
effects.enter(types.codeFencedFenceInfo); |
|
effects.enter(types.chunkString, { contentType: constants.contentTypeString }); |
|
return info(code); |
|
} |
|
function info(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.chunkString); |
|
effects.exit(types.codeFencedFenceInfo); |
|
return infoBefore(code); |
|
} |
|
if (markdownSpace(code)) { |
|
effects.exit(types.chunkString); |
|
effects.exit(types.codeFencedFenceInfo); |
|
return factorySpace(effects, metaBefore, types.whitespace)(code); |
|
} |
|
if (code === codes.graveAccent && code === marker) { |
|
return nok(code); |
|
} |
|
effects.consume(code); |
|
return info; |
|
} |
|
function metaBefore(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
return infoBefore(code); |
|
} |
|
effects.enter(types.codeFencedFenceMeta); |
|
effects.enter(types.chunkString, { contentType: constants.contentTypeString }); |
|
return meta(code); |
|
} |
|
function meta(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.chunkString); |
|
effects.exit(types.codeFencedFenceMeta); |
|
return infoBefore(code); |
|
} |
|
if (code === codes.graveAccent && code === marker) { |
|
return nok(code); |
|
} |
|
effects.consume(code); |
|
return meta; |
|
} |
|
function atNonLazyBreak(code) { |
|
ok(markdownLineEnding(code), "expected eol"); |
|
return effects.attempt(closeStart, after, contentBefore)(code); |
|
} |
|
function contentBefore(code) { |
|
ok(markdownLineEnding(code), "expected eol"); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return contentStart; |
|
} |
|
function contentStart(code) { |
|
return initialPrefix > 0 && markdownSpace(code) ? factorySpace( |
|
effects, |
|
beforeContentChunk, |
|
types.linePrefix, |
|
initialPrefix + 1 |
|
)(code) : beforeContentChunk(code); |
|
} |
|
function beforeContentChunk(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
return effects.check(nonLazyContinuation, atNonLazyBreak, after)(code); |
|
} |
|
effects.enter(types.codeFlowValue); |
|
return contentChunk(code); |
|
} |
|
function contentChunk(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.codeFlowValue); |
|
return beforeContentChunk(code); |
|
} |
|
effects.consume(code); |
|
return contentChunk; |
|
} |
|
function after(code) { |
|
effects.exit(types.codeFenced); |
|
return ok2(code); |
|
} |
|
function tokenizeCloseStart(effects2, ok3, nok2) { |
|
let size = 0; |
|
return startBefore; |
|
function startBefore(code) { |
|
ok(markdownLineEnding(code), "expected eol"); |
|
effects2.enter(types.lineEnding); |
|
effects2.consume(code); |
|
effects2.exit(types.lineEnding); |
|
return start2; |
|
} |
|
function start2(code) { |
|
ok( |
|
self.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
effects2.enter(types.codeFencedFence); |
|
return markdownSpace(code) ? factorySpace( |
|
effects2, |
|
beforeSequenceClose, |
|
types.linePrefix, |
|
self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : constants.tabSize |
|
)(code) : beforeSequenceClose(code); |
|
} |
|
function beforeSequenceClose(code) { |
|
if (code === marker) { |
|
effects2.enter(types.codeFencedFenceSequence); |
|
return sequenceClose(code); |
|
} |
|
return nok2(code); |
|
} |
|
function sequenceClose(code) { |
|
if (code === marker) { |
|
size++; |
|
effects2.consume(code); |
|
return sequenceClose; |
|
} |
|
if (size >= sizeOpen) { |
|
effects2.exit(types.codeFencedFenceSequence); |
|
return markdownSpace(code) ? factorySpace(effects2, sequenceCloseAfter, types.whitespace)(code) : sequenceCloseAfter(code); |
|
} |
|
return nok2(code); |
|
} |
|
function sequenceCloseAfter(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects2.exit(types.codeFencedFence); |
|
return ok3(code); |
|
} |
|
return nok2(code); |
|
} |
|
} |
|
} |
|
function tokenizeNonLazyContinuation(effects, ok2, nok) { |
|
const self = this; |
|
return start; |
|
function start(code) { |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
ok(markdownLineEnding(code), "expected eol"); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return lineStart; |
|
} |
|
function lineStart(code) { |
|
return self.parser.lazy[self.now().line] ? nok(code) : ok2(code); |
|
} |
|
} |
|
|
|
|
|
var codeIndented = { |
|
name: "codeIndented", |
|
tokenize: tokenizeCodeIndented |
|
}; |
|
var furtherStart = { tokenize: tokenizeFurtherStart, partial: true }; |
|
function tokenizeCodeIndented(effects, ok2, nok) { |
|
const self = this; |
|
return start; |
|
function start(code) { |
|
ok(markdownSpace(code)); |
|
effects.enter(types.codeIndented); |
|
return factorySpace( |
|
effects, |
|
afterPrefix, |
|
types.linePrefix, |
|
constants.tabSize + 1 |
|
)(code); |
|
} |
|
function afterPrefix(code) { |
|
const tail = self.events[self.events.length - 1]; |
|
return tail && tail[1].type === types.linePrefix && tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize ? atBreak(code) : nok(code); |
|
} |
|
function atBreak(code) { |
|
if (code === codes.eof) { |
|
return after(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
return effects.attempt(furtherStart, atBreak, after)(code); |
|
} |
|
effects.enter(types.codeFlowValue); |
|
return inside(code); |
|
} |
|
function inside(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.codeFlowValue); |
|
return atBreak(code); |
|
} |
|
effects.consume(code); |
|
return inside; |
|
} |
|
function after(code) { |
|
effects.exit(types.codeIndented); |
|
return ok2(code); |
|
} |
|
} |
|
function tokenizeFurtherStart(effects, ok2, nok) { |
|
const self = this; |
|
return furtherStart2; |
|
function furtherStart2(code) { |
|
if (self.parser.lazy[self.now().line]) { |
|
return nok(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return furtherStart2; |
|
} |
|
return factorySpace( |
|
effects, |
|
afterPrefix, |
|
types.linePrefix, |
|
constants.tabSize + 1 |
|
)(code); |
|
} |
|
function afterPrefix(code) { |
|
const tail = self.events[self.events.length - 1]; |
|
return tail && tail[1].type === types.linePrefix && tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize ? ok2(code) : markdownLineEnding(code) ? furtherStart2(code) : nok(code); |
|
} |
|
} |
|
|
|
|
|
var codeText = { |
|
name: "codeText", |
|
tokenize: tokenizeCodeText, |
|
resolve: resolveCodeText, |
|
previous |
|
}; |
|
function resolveCodeText(events) { |
|
let tailExitIndex = events.length - 4; |
|
let headEnterIndex = 3; |
|
let index2; |
|
let enter; |
|
if ((events[headEnterIndex][1].type === types.lineEnding || events[headEnterIndex][1].type === "space") && (events[tailExitIndex][1].type === types.lineEnding || events[tailExitIndex][1].type === "space")) { |
|
index2 = headEnterIndex; |
|
while (++index2 < tailExitIndex) { |
|
if (events[index2][1].type === types.codeTextData) { |
|
events[headEnterIndex][1].type = types.codeTextPadding; |
|
events[tailExitIndex][1].type = types.codeTextPadding; |
|
headEnterIndex += 2; |
|
tailExitIndex -= 2; |
|
break; |
|
} |
|
} |
|
} |
|
index2 = headEnterIndex - 1; |
|
tailExitIndex++; |
|
while (++index2 <= tailExitIndex) { |
|
if (enter === void 0) { |
|
if (index2 !== tailExitIndex && events[index2][1].type !== types.lineEnding) { |
|
enter = index2; |
|
} |
|
} else if (index2 === tailExitIndex || events[index2][1].type === types.lineEnding) { |
|
events[enter][1].type = types.codeTextData; |
|
if (index2 !== enter + 2) { |
|
events[enter][1].end = events[index2 - 1][1].end; |
|
events.splice(enter + 2, index2 - enter - 2); |
|
tailExitIndex -= index2 - enter - 2; |
|
index2 = enter + 2; |
|
} |
|
enter = void 0; |
|
} |
|
} |
|
return events; |
|
} |
|
function previous(code) { |
|
return code !== codes.graveAccent || this.events[this.events.length - 1][1].type === types.characterEscape; |
|
} |
|
function tokenizeCodeText(effects, ok2, nok) { |
|
const self = this; |
|
let sizeOpen = 0; |
|
let size; |
|
let token; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.graveAccent, "expected `` ` ``"); |
|
ok(previous.call(self, self.previous), "expected correct previous"); |
|
effects.enter(types.codeText); |
|
effects.enter(types.codeTextSequence); |
|
return sequenceOpen(code); |
|
} |
|
function sequenceOpen(code) { |
|
if (code === codes.graveAccent) { |
|
effects.consume(code); |
|
sizeOpen++; |
|
return sequenceOpen; |
|
} |
|
effects.exit(types.codeTextSequence); |
|
return between(code); |
|
} |
|
function between(code) { |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
if (code === codes.space) { |
|
effects.enter("space"); |
|
effects.consume(code); |
|
effects.exit("space"); |
|
return between; |
|
} |
|
if (code === codes.graveAccent) { |
|
token = effects.enter(types.codeTextSequence); |
|
size = 0; |
|
return sequenceClose(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return between; |
|
} |
|
effects.enter(types.codeTextData); |
|
return data(code); |
|
} |
|
function data(code) { |
|
if (code === codes.eof || code === codes.space || code === codes.graveAccent || markdownLineEnding(code)) { |
|
effects.exit(types.codeTextData); |
|
return between(code); |
|
} |
|
effects.consume(code); |
|
return data; |
|
} |
|
function sequenceClose(code) { |
|
if (code === codes.graveAccent) { |
|
effects.consume(code); |
|
size++; |
|
return sequenceClose; |
|
} |
|
if (size === sizeOpen) { |
|
effects.exit(types.codeTextSequence); |
|
effects.exit(types.codeText); |
|
return ok2(code); |
|
} |
|
token.type = types.codeTextData; |
|
return data(code); |
|
} |
|
} |
|
|
|
|
|
function subtokenize(events) { |
|
const jumps = {}; |
|
let index2 = -1; |
|
let event; |
|
let lineIndex; |
|
let otherIndex; |
|
let otherEvent; |
|
let parameters; |
|
let subevents; |
|
let more; |
|
while (++index2 < events.length) { |
|
while (index2 in jumps) { |
|
index2 = jumps[index2]; |
|
} |
|
event = events[index2]; |
|
if (index2 && event[1].type === types.chunkFlow && events[index2 - 1][1].type === types.listItemPrefix) { |
|
ok(event[1]._tokenizer, "expected `_tokenizer` on subtokens"); |
|
subevents = event[1]._tokenizer.events; |
|
otherIndex = 0; |
|
if (otherIndex < subevents.length && subevents[otherIndex][1].type === types.lineEndingBlank) { |
|
otherIndex += 2; |
|
} |
|
if (otherIndex < subevents.length && subevents[otherIndex][1].type === types.content) { |
|
while (++otherIndex < subevents.length) { |
|
if (subevents[otherIndex][1].type === types.content) { |
|
break; |
|
} |
|
if (subevents[otherIndex][1].type === types.chunkText) { |
|
subevents[otherIndex][1]._isInFirstContentOfListItem = true; |
|
otherIndex++; |
|
} |
|
} |
|
} |
|
} |
|
if (event[0] === "enter") { |
|
if (event[1].contentType) { |
|
Object.assign(jumps, subcontent(events, index2)); |
|
index2 = jumps[index2]; |
|
more = true; |
|
} |
|
} else if (event[1]._container) { |
|
otherIndex = index2; |
|
lineIndex = void 0; |
|
while (otherIndex--) { |
|
otherEvent = events[otherIndex]; |
|
if (otherEvent[1].type === types.lineEnding || otherEvent[1].type === types.lineEndingBlank) { |
|
if (otherEvent[0] === "enter") { |
|
if (lineIndex) { |
|
events[lineIndex][1].type = types.lineEndingBlank; |
|
} |
|
otherEvent[1].type = types.lineEnding; |
|
lineIndex = otherIndex; |
|
} |
|
} else { |
|
break; |
|
} |
|
} |
|
if (lineIndex) { |
|
event[1].end = Object.assign({}, events[lineIndex][1].start); |
|
parameters = events.slice(lineIndex, index2); |
|
parameters.unshift(event); |
|
splice(events, lineIndex, index2 - lineIndex + 1, parameters); |
|
} |
|
} |
|
} |
|
return !more; |
|
} |
|
function subcontent(events, eventIndex) { |
|
const token = events[eventIndex][1]; |
|
const context = events[eventIndex][2]; |
|
let startPosition = eventIndex - 1; |
|
const startPositions = []; |
|
ok(token.contentType, "expected `contentType` on subtokens"); |
|
const tokenizer = token._tokenizer || context.parser[token.contentType](token.start); |
|
const childEvents = tokenizer.events; |
|
const jumps = []; |
|
const gaps = {}; |
|
let stream; |
|
let previous2; |
|
let index2 = -1; |
|
let current = token; |
|
let adjust = 0; |
|
let start = 0; |
|
const breaks = [start]; |
|
while (current) { |
|
while (events[++startPosition][1] !== current) { |
|
} |
|
ok( |
|
!previous2 || current.previous === previous2, |
|
"expected previous to match" |
|
); |
|
ok(!previous2 || previous2.next === current, "expected next to match"); |
|
startPositions.push(startPosition); |
|
if (!current._tokenizer) { |
|
stream = context.sliceStream(current); |
|
if (!current.next) { |
|
stream.push(codes.eof); |
|
} |
|
if (previous2) { |
|
tokenizer.defineSkip(current.start); |
|
} |
|
if (current._isInFirstContentOfListItem) { |
|
tokenizer._gfmTasklistFirstContentOfListItem = true; |
|
} |
|
tokenizer.write(stream); |
|
if (current._isInFirstContentOfListItem) { |
|
tokenizer._gfmTasklistFirstContentOfListItem = void 0; |
|
} |
|
} |
|
previous2 = current; |
|
current = current.next; |
|
} |
|
current = token; |
|
while (++index2 < childEvents.length) { |
|
if ( |
|
|
|
childEvents[index2][0] === "exit" && childEvents[index2 - 1][0] === "enter" && childEvents[index2][1].type === childEvents[index2 - 1][1].type && childEvents[index2][1].start.line !== childEvents[index2][1].end.line |
|
) { |
|
ok(current, "expected a current token"); |
|
start = index2 + 1; |
|
breaks.push(start); |
|
current._tokenizer = void 0; |
|
current.previous = void 0; |
|
current = current.next; |
|
} |
|
} |
|
tokenizer.events = []; |
|
if (current) { |
|
current._tokenizer = void 0; |
|
current.previous = void 0; |
|
ok(!current.next, "expected no next token"); |
|
} else { |
|
breaks.pop(); |
|
} |
|
index2 = breaks.length; |
|
while (index2--) { |
|
const slice = childEvents.slice(breaks[index2], breaks[index2 + 1]); |
|
const start2 = startPositions.pop(); |
|
ok(start2 !== void 0, "expected a start position when splicing"); |
|
jumps.unshift([start2, start2 + slice.length - 1]); |
|
splice(events, start2, 2, slice); |
|
} |
|
index2 = -1; |
|
while (++index2 < jumps.length) { |
|
gaps[adjust + jumps[index2][0]] = adjust + jumps[index2][1]; |
|
adjust += jumps[index2][1] - jumps[index2][0] - 1; |
|
} |
|
return gaps; |
|
} |
|
|
|
|
|
var content2 = { tokenize: tokenizeContent, resolve: resolveContent }; |
|
var continuationConstruct = { tokenize: tokenizeContinuation, partial: true }; |
|
function resolveContent(events) { |
|
subtokenize(events); |
|
return events; |
|
} |
|
function tokenizeContent(effects, ok2) { |
|
let previous2; |
|
return chunkStart; |
|
function chunkStart(code) { |
|
ok( |
|
code !== codes.eof && !markdownLineEnding(code), |
|
"expected no eof or eol" |
|
); |
|
effects.enter(types.content); |
|
previous2 = effects.enter(types.chunkContent, { |
|
contentType: constants.contentTypeContent |
|
}); |
|
return chunkInside(code); |
|
} |
|
function chunkInside(code) { |
|
if (code === codes.eof) { |
|
return contentEnd(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
return effects.check( |
|
continuationConstruct, |
|
contentContinue, |
|
contentEnd |
|
)(code); |
|
} |
|
effects.consume(code); |
|
return chunkInside; |
|
} |
|
function contentEnd(code) { |
|
effects.exit(types.chunkContent); |
|
effects.exit(types.content); |
|
return ok2(code); |
|
} |
|
function contentContinue(code) { |
|
ok(markdownLineEnding(code), "expected eol"); |
|
effects.consume(code); |
|
effects.exit(types.chunkContent); |
|
ok(previous2, "expected previous token"); |
|
previous2.next = effects.enter(types.chunkContent, { |
|
contentType: constants.contentTypeContent, |
|
previous: previous2 |
|
}); |
|
previous2 = previous2.next; |
|
return chunkInside; |
|
} |
|
} |
|
function tokenizeContinuation(effects, ok2, nok) { |
|
const self = this; |
|
return startLookahead; |
|
function startLookahead(code) { |
|
ok(markdownLineEnding(code), "expected a line ending"); |
|
effects.exit(types.chunkContent); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return factorySpace(effects, prefixed, types.linePrefix); |
|
} |
|
function prefixed(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
return nok(code); |
|
} |
|
ok( |
|
self.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
const tail = self.events[self.events.length - 1]; |
|
if (!self.parser.constructs.disable.null.includes("codeIndented") && tail && tail[1].type === types.linePrefix && tail[2].sliceSerialize(tail[1], true).length >= constants.tabSize) { |
|
return ok2(code); |
|
} |
|
return effects.interrupt(self.parser.constructs.flow, nok, ok2)(code); |
|
} |
|
} |
|
|
|
|
|
function factoryDestination(effects, ok2, nok, type, literalType, literalMarkerType, rawType, stringType, max) { |
|
const limit = max || Number.POSITIVE_INFINITY; |
|
let balance = 0; |
|
return start; |
|
function start(code) { |
|
if (code === codes.lessThan) { |
|
effects.enter(type); |
|
effects.enter(literalType); |
|
effects.enter(literalMarkerType); |
|
effects.consume(code); |
|
effects.exit(literalMarkerType); |
|
return enclosedBefore; |
|
} |
|
if (code === codes.eof || code === codes.space || code === codes.rightParenthesis || asciiControl(code)) { |
|
return nok(code); |
|
} |
|
effects.enter(type); |
|
effects.enter(rawType); |
|
effects.enter(stringType); |
|
effects.enter(types.chunkString, { contentType: constants.contentTypeString }); |
|
return raw(code); |
|
} |
|
function enclosedBefore(code) { |
|
if (code === codes.greaterThan) { |
|
effects.enter(literalMarkerType); |
|
effects.consume(code); |
|
effects.exit(literalMarkerType); |
|
effects.exit(literalType); |
|
effects.exit(type); |
|
return ok2; |
|
} |
|
effects.enter(stringType); |
|
effects.enter(types.chunkString, { contentType: constants.contentTypeString }); |
|
return enclosed(code); |
|
} |
|
function enclosed(code) { |
|
if (code === codes.greaterThan) { |
|
effects.exit(types.chunkString); |
|
effects.exit(stringType); |
|
return enclosedBefore(code); |
|
} |
|
if (code === codes.eof || code === codes.lessThan || markdownLineEnding(code)) { |
|
return nok(code); |
|
} |
|
effects.consume(code); |
|
return code === codes.backslash ? enclosedEscape : enclosed; |
|
} |
|
function enclosedEscape(code) { |
|
if (code === codes.lessThan || code === codes.greaterThan || code === codes.backslash) { |
|
effects.consume(code); |
|
return enclosed; |
|
} |
|
return enclosed(code); |
|
} |
|
function raw(code) { |
|
if (!balance && (code === codes.eof || code === codes.rightParenthesis || markdownLineEndingOrSpace(code))) { |
|
effects.exit(types.chunkString); |
|
effects.exit(stringType); |
|
effects.exit(rawType); |
|
effects.exit(type); |
|
return ok2(code); |
|
} |
|
if (balance < limit && code === codes.leftParenthesis) { |
|
effects.consume(code); |
|
balance++; |
|
return raw; |
|
} |
|
if (code === codes.rightParenthesis) { |
|
effects.consume(code); |
|
balance--; |
|
return raw; |
|
} |
|
if (code === codes.eof || code === codes.space || code === codes.leftParenthesis || asciiControl(code)) { |
|
return nok(code); |
|
} |
|
effects.consume(code); |
|
return code === codes.backslash ? rawEscape : raw; |
|
} |
|
function rawEscape(code) { |
|
if (code === codes.leftParenthesis || code === codes.rightParenthesis || code === codes.backslash) { |
|
effects.consume(code); |
|
return raw; |
|
} |
|
return raw(code); |
|
} |
|
} |
|
|
|
|
|
function factoryLabel(effects, ok2, nok, type, markerType, stringType) { |
|
const self = this; |
|
let size = 0; |
|
let seen; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.leftSquareBracket, "expected `[`"); |
|
effects.enter(type); |
|
effects.enter(markerType); |
|
effects.consume(code); |
|
effects.exit(markerType); |
|
effects.enter(stringType); |
|
return atBreak; |
|
} |
|
function atBreak(code) { |
|
if (size > constants.linkReferenceSizeMax || code === codes.eof || code === codes.leftSquareBracket || code === codes.rightSquareBracket && !seen || |
|
|
|
|
|
|
|
|
|
code === codes.caret && !size && "_hiddenFootnoteSupport" in self.parser.constructs) { |
|
return nok(code); |
|
} |
|
if (code === codes.rightSquareBracket) { |
|
effects.exit(stringType); |
|
effects.enter(markerType); |
|
effects.consume(code); |
|
effects.exit(markerType); |
|
effects.exit(type); |
|
return ok2; |
|
} |
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return atBreak; |
|
} |
|
effects.enter(types.chunkString, { contentType: constants.contentTypeString }); |
|
return labelInside(code); |
|
} |
|
function labelInside(code) { |
|
if (code === codes.eof || code === codes.leftSquareBracket || code === codes.rightSquareBracket || markdownLineEnding(code) || size++ > constants.linkReferenceSizeMax) { |
|
effects.exit(types.chunkString); |
|
return atBreak(code); |
|
} |
|
effects.consume(code); |
|
if (!seen) seen = !markdownSpace(code); |
|
return code === codes.backslash ? labelEscape : labelInside; |
|
} |
|
function labelEscape(code) { |
|
if (code === codes.leftSquareBracket || code === codes.backslash || code === codes.rightSquareBracket) { |
|
effects.consume(code); |
|
size++; |
|
return labelInside; |
|
} |
|
return labelInside(code); |
|
} |
|
} |
|
|
|
|
|
function factoryTitle(effects, ok2, nok, type, markerType, stringType) { |
|
let marker; |
|
return start; |
|
function start(code) { |
|
if (code === codes.quotationMark || code === codes.apostrophe || code === codes.leftParenthesis) { |
|
effects.enter(type); |
|
effects.enter(markerType); |
|
effects.consume(code); |
|
effects.exit(markerType); |
|
marker = code === codes.leftParenthesis ? codes.rightParenthesis : code; |
|
return begin; |
|
} |
|
return nok(code); |
|
} |
|
function begin(code) { |
|
if (code === marker) { |
|
effects.enter(markerType); |
|
effects.consume(code); |
|
effects.exit(markerType); |
|
effects.exit(type); |
|
return ok2; |
|
} |
|
effects.enter(stringType); |
|
return atBreak(code); |
|
} |
|
function atBreak(code) { |
|
if (code === marker) { |
|
effects.exit(stringType); |
|
return begin(marker); |
|
} |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return factorySpace(effects, atBreak, types.linePrefix); |
|
} |
|
effects.enter(types.chunkString, { contentType: constants.contentTypeString }); |
|
return inside(code); |
|
} |
|
function inside(code) { |
|
if (code === marker || code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.chunkString); |
|
return atBreak(code); |
|
} |
|
effects.consume(code); |
|
return code === codes.backslash ? escape : inside; |
|
} |
|
function escape(code) { |
|
if (code === marker || code === codes.backslash) { |
|
effects.consume(code); |
|
return inside; |
|
} |
|
return inside(code); |
|
} |
|
} |
|
|
|
|
|
function factoryWhitespace(effects, ok2) { |
|
let seen; |
|
return start; |
|
function start(code) { |
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
seen = true; |
|
return start; |
|
} |
|
if (markdownSpace(code)) { |
|
return factorySpace( |
|
effects, |
|
start, |
|
seen ? types.linePrefix : types.lineSuffix |
|
)(code); |
|
} |
|
return ok2(code); |
|
} |
|
} |
|
|
|
|
|
var values = ( |
|
|
|
{ |
|
ht: " ", |
|
lf: "\n", |
|
cr: "\r", |
|
space: " ", |
|
exclamationMark: "!", |
|
quotationMark: '"', |
|
numberSign: "#", |
|
dollarSign: "$", |
|
percentSign: "%", |
|
ampersand: "&", |
|
apostrophe: "'", |
|
leftParenthesis: "(", |
|
rightParenthesis: ")", |
|
asterisk: "*", |
|
plusSign: "+", |
|
comma: ",", |
|
dash: "-", |
|
dot: ".", |
|
slash: "/", |
|
digit0: "0", |
|
digit1: "1", |
|
digit2: "2", |
|
digit3: "3", |
|
digit4: "4", |
|
digit5: "5", |
|
digit6: "6", |
|
digit7: "7", |
|
digit8: "8", |
|
digit9: "9", |
|
colon: ":", |
|
semicolon: ";", |
|
lessThan: "<", |
|
equalsTo: "=", |
|
greaterThan: ">", |
|
questionMark: "?", |
|
atSign: "@", |
|
uppercaseA: "A", |
|
uppercaseB: "B", |
|
uppercaseC: "C", |
|
uppercaseD: "D", |
|
uppercaseE: "E", |
|
uppercaseF: "F", |
|
uppercaseG: "G", |
|
uppercaseH: "H", |
|
uppercaseI: "I", |
|
uppercaseJ: "J", |
|
uppercaseK: "K", |
|
uppercaseL: "L", |
|
uppercaseM: "M", |
|
uppercaseN: "N", |
|
uppercaseO: "O", |
|
uppercaseP: "P", |
|
uppercaseQ: "Q", |
|
uppercaseR: "R", |
|
uppercaseS: "S", |
|
uppercaseT: "T", |
|
uppercaseU: "U", |
|
uppercaseV: "V", |
|
uppercaseW: "W", |
|
uppercaseX: "X", |
|
uppercaseY: "Y", |
|
uppercaseZ: "Z", |
|
leftSquareBracket: "[", |
|
backslash: "\\", |
|
rightSquareBracket: "]", |
|
caret: "^", |
|
underscore: "_", |
|
graveAccent: "`", |
|
lowercaseA: "a", |
|
lowercaseB: "b", |
|
lowercaseC: "c", |
|
lowercaseD: "d", |
|
lowercaseE: "e", |
|
lowercaseF: "f", |
|
lowercaseG: "g", |
|
lowercaseH: "h", |
|
lowercaseI: "i", |
|
lowercaseJ: "j", |
|
lowercaseK: "k", |
|
lowercaseL: "l", |
|
lowercaseM: "m", |
|
lowercaseN: "n", |
|
lowercaseO: "o", |
|
lowercaseP: "p", |
|
lowercaseQ: "q", |
|
lowercaseR: "r", |
|
lowercaseS: "s", |
|
lowercaseT: "t", |
|
lowercaseU: "u", |
|
lowercaseV: "v", |
|
lowercaseW: "w", |
|
lowercaseX: "x", |
|
lowercaseY: "y", |
|
lowercaseZ: "z", |
|
leftCurlyBrace: "{", |
|
verticalBar: "|", |
|
rightCurlyBrace: "}", |
|
tilde: "~", |
|
replacementCharacter: "�" |
|
} |
|
); |
|
|
|
|
|
function normalizeIdentifier(value) { |
|
return value.replace(/[\t\n\r ]+/g, values.space).replace(/^ | $/g, "").toLowerCase().toUpperCase(); |
|
} |
|
|
|
|
|
var definition = { name: "definition", tokenize: tokenizeDefinition }; |
|
var titleBefore = { tokenize: tokenizeTitleBefore, partial: true }; |
|
function tokenizeDefinition(effects, ok2, nok) { |
|
const self = this; |
|
let identifier; |
|
return start; |
|
function start(code) { |
|
effects.enter(types.definition); |
|
return before(code); |
|
} |
|
function before(code) { |
|
ok(code === codes.leftSquareBracket, "expected `[`"); |
|
return factoryLabel.call( |
|
self, |
|
effects, |
|
labelAfter, |
|
|
|
nok, |
|
types.definitionLabel, |
|
types.definitionLabelMarker, |
|
types.definitionLabelString |
|
)(code); |
|
} |
|
function labelAfter(code) { |
|
identifier = normalizeIdentifier( |
|
self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1) |
|
); |
|
if (code === codes.colon) { |
|
effects.enter(types.definitionMarker); |
|
effects.consume(code); |
|
effects.exit(types.definitionMarker); |
|
return markerAfter; |
|
} |
|
return nok(code); |
|
} |
|
function markerAfter(code) { |
|
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, destinationBefore)(code) : destinationBefore(code); |
|
} |
|
function destinationBefore(code) { |
|
return factoryDestination( |
|
effects, |
|
destinationAfter, |
|
|
|
nok, |
|
types.definitionDestination, |
|
types.definitionDestinationLiteral, |
|
types.definitionDestinationLiteralMarker, |
|
types.definitionDestinationRaw, |
|
types.definitionDestinationString |
|
)(code); |
|
} |
|
function destinationAfter(code) { |
|
return effects.attempt(titleBefore, after, after)(code); |
|
} |
|
function after(code) { |
|
return markdownSpace(code) ? factorySpace(effects, afterWhitespace, types.whitespace)(code) : afterWhitespace(code); |
|
} |
|
function afterWhitespace(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.definition); |
|
self.parser.defined.push(identifier); |
|
return ok2(code); |
|
} |
|
return nok(code); |
|
} |
|
} |
|
function tokenizeTitleBefore(effects, ok2, nok) { |
|
return titleBefore2; |
|
function titleBefore2(code) { |
|
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, beforeMarker)(code) : nok(code); |
|
} |
|
function beforeMarker(code) { |
|
return factoryTitle( |
|
effects, |
|
titleAfter, |
|
nok, |
|
types.definitionTitle, |
|
types.definitionTitleMarker, |
|
types.definitionTitleString |
|
)(code); |
|
} |
|
function titleAfter(code) { |
|
return markdownSpace(code) ? factorySpace( |
|
effects, |
|
titleAfterOptionalWhitespace, |
|
types.whitespace |
|
)(code) : titleAfterOptionalWhitespace(code); |
|
} |
|
function titleAfterOptionalWhitespace(code) { |
|
return code === codes.eof || markdownLineEnding(code) ? ok2(code) : nok(code); |
|
} |
|
} |
|
|
|
|
|
var hardBreakEscape = { |
|
name: "hardBreakEscape", |
|
tokenize: tokenizeHardBreakEscape |
|
}; |
|
function tokenizeHardBreakEscape(effects, ok2, nok) { |
|
return start; |
|
function start(code) { |
|
ok(code === codes.backslash, "expected `\\`"); |
|
effects.enter(types.hardBreakEscape); |
|
effects.consume(code); |
|
return after; |
|
} |
|
function after(code) { |
|
if (markdownLineEnding(code)) { |
|
effects.exit(types.hardBreakEscape); |
|
return ok2(code); |
|
} |
|
return nok(code); |
|
} |
|
} |
|
|
|
|
|
var headingAtx = { |
|
name: "headingAtx", |
|
tokenize: tokenizeHeadingAtx, |
|
resolve: resolveHeadingAtx |
|
}; |
|
function resolveHeadingAtx(events, context) { |
|
let contentEnd = events.length - 2; |
|
let contentStart = 3; |
|
let content3; |
|
let text3; |
|
if (events[contentStart][1].type === types.whitespace) { |
|
contentStart += 2; |
|
} |
|
if (contentEnd - 2 > contentStart && events[contentEnd][1].type === types.whitespace) { |
|
contentEnd -= 2; |
|
} |
|
if (events[contentEnd][1].type === types.atxHeadingSequence && (contentStart === contentEnd - 1 || contentEnd - 4 > contentStart && events[contentEnd - 2][1].type === types.whitespace)) { |
|
contentEnd -= contentStart + 1 === contentEnd ? 2 : 4; |
|
} |
|
if (contentEnd > contentStart) { |
|
content3 = { |
|
type: types.atxHeadingText, |
|
start: events[contentStart][1].start, |
|
end: events[contentEnd][1].end |
|
}; |
|
text3 = { |
|
type: types.chunkText, |
|
start: events[contentStart][1].start, |
|
end: events[contentEnd][1].end, |
|
contentType: constants.contentTypeText |
|
}; |
|
splice(events, contentStart, contentEnd - contentStart + 1, [ |
|
["enter", content3, context], |
|
["enter", text3, context], |
|
["exit", text3, context], |
|
["exit", content3, context] |
|
]); |
|
} |
|
return events; |
|
} |
|
function tokenizeHeadingAtx(effects, ok2, nok) { |
|
let size = 0; |
|
return start; |
|
function start(code) { |
|
effects.enter(types.atxHeading); |
|
return before(code); |
|
} |
|
function before(code) { |
|
ok(code === codes.numberSign, "expected `#`"); |
|
effects.enter(types.atxHeadingSequence); |
|
return sequenceOpen(code); |
|
} |
|
function sequenceOpen(code) { |
|
if (code === codes.numberSign && size++ < constants.atxHeadingOpeningFenceSizeMax) { |
|
effects.consume(code); |
|
return sequenceOpen; |
|
} |
|
if (code === codes.eof || markdownLineEndingOrSpace(code)) { |
|
effects.exit(types.atxHeadingSequence); |
|
return atBreak(code); |
|
} |
|
return nok(code); |
|
} |
|
function atBreak(code) { |
|
if (code === codes.numberSign) { |
|
effects.enter(types.atxHeadingSequence); |
|
return sequenceFurther(code); |
|
} |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.atxHeading); |
|
return ok2(code); |
|
} |
|
if (markdownSpace(code)) { |
|
return factorySpace(effects, atBreak, types.whitespace)(code); |
|
} |
|
effects.enter(types.atxHeadingText); |
|
return data(code); |
|
} |
|
function sequenceFurther(code) { |
|
if (code === codes.numberSign) { |
|
effects.consume(code); |
|
return sequenceFurther; |
|
} |
|
effects.exit(types.atxHeadingSequence); |
|
return atBreak(code); |
|
} |
|
function data(code) { |
|
if (code === codes.eof || code === codes.numberSign || markdownLineEndingOrSpace(code)) { |
|
effects.exit(types.atxHeadingText); |
|
return atBreak(code); |
|
} |
|
effects.consume(code); |
|
return data; |
|
} |
|
} |
|
|
|
|
|
var htmlBlockNames = [ |
|
"address", |
|
"article", |
|
"aside", |
|
"base", |
|
"basefont", |
|
"blockquote", |
|
"body", |
|
"caption", |
|
"center", |
|
"col", |
|
"colgroup", |
|
"dd", |
|
"details", |
|
"dialog", |
|
"dir", |
|
"div", |
|
"dl", |
|
"dt", |
|
"fieldset", |
|
"figcaption", |
|
"figure", |
|
"footer", |
|
"form", |
|
"frame", |
|
"frameset", |
|
"h1", |
|
"h2", |
|
"h3", |
|
"h4", |
|
"h5", |
|
"h6", |
|
"head", |
|
"header", |
|
"hr", |
|
"html", |
|
"iframe", |
|
"legend", |
|
"li", |
|
"link", |
|
"main", |
|
"menu", |
|
"menuitem", |
|
"nav", |
|
"noframes", |
|
"ol", |
|
"optgroup", |
|
"option", |
|
"p", |
|
"param", |
|
"search", |
|
"section", |
|
"summary", |
|
"table", |
|
"tbody", |
|
"td", |
|
"tfoot", |
|
"th", |
|
"thead", |
|
"title", |
|
"tr", |
|
"track", |
|
"ul" |
|
]; |
|
var htmlRawNames = ["pre", "script", "style", "textarea"]; |
|
|
|
|
|
var htmlFlow = { |
|
name: "htmlFlow", |
|
tokenize: tokenizeHtmlFlow, |
|
resolveTo: resolveToHtmlFlow, |
|
concrete: true |
|
}; |
|
var blankLineBefore = { tokenize: tokenizeBlankLineBefore, partial: true }; |
|
var nonLazyContinuationStart = { |
|
tokenize: tokenizeNonLazyContinuationStart, |
|
partial: true |
|
}; |
|
function resolveToHtmlFlow(events) { |
|
let index2 = events.length; |
|
while (index2--) { |
|
if (events[index2][0] === "enter" && events[index2][1].type === types.htmlFlow) { |
|
break; |
|
} |
|
} |
|
if (index2 > 1 && events[index2 - 2][1].type === types.linePrefix) { |
|
events[index2][1].start = events[index2 - 2][1].start; |
|
events[index2 + 1][1].start = events[index2 - 2][1].start; |
|
events.splice(index2 - 2, 2); |
|
} |
|
return events; |
|
} |
|
function tokenizeHtmlFlow(effects, ok2, nok) { |
|
const self = this; |
|
let marker; |
|
let closingTag; |
|
let buffer; |
|
let index2; |
|
let markerB; |
|
return start; |
|
function start(code) { |
|
return before(code); |
|
} |
|
function before(code) { |
|
ok(code === codes.lessThan, "expected `<`"); |
|
effects.enter(types.htmlFlow); |
|
effects.enter(types.htmlFlowData); |
|
effects.consume(code); |
|
return open; |
|
} |
|
function open(code) { |
|
if (code === codes.exclamationMark) { |
|
effects.consume(code); |
|
return declarationOpen; |
|
} |
|
if (code === codes.slash) { |
|
effects.consume(code); |
|
closingTag = true; |
|
return tagCloseStart; |
|
} |
|
if (code === codes.questionMark) { |
|
effects.consume(code); |
|
marker = constants.htmlInstruction; |
|
return self.interrupt ? ok2 : continuationDeclarationInside; |
|
} |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
buffer = String.fromCharCode(code); |
|
return tagName; |
|
} |
|
return nok(code); |
|
} |
|
function declarationOpen(code) { |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
marker = constants.htmlComment; |
|
return commentOpenInside; |
|
} |
|
if (code === codes.leftSquareBracket) { |
|
effects.consume(code); |
|
marker = constants.htmlCdata; |
|
index2 = 0; |
|
return cdataOpenInside; |
|
} |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
marker = constants.htmlDeclaration; |
|
return self.interrupt ? ok2 : continuationDeclarationInside; |
|
} |
|
return nok(code); |
|
} |
|
function commentOpenInside(code) { |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
return self.interrupt ? ok2 : continuationDeclarationInside; |
|
} |
|
return nok(code); |
|
} |
|
function cdataOpenInside(code) { |
|
const value = constants.cdataOpeningString; |
|
if (code === value.charCodeAt(index2++)) { |
|
effects.consume(code); |
|
if (index2 === value.length) { |
|
return self.interrupt ? ok2 : continuation; |
|
} |
|
return cdataOpenInside; |
|
} |
|
return nok(code); |
|
} |
|
function tagCloseStart(code) { |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
buffer = String.fromCharCode(code); |
|
return tagName; |
|
} |
|
return nok(code); |
|
} |
|
function tagName(code) { |
|
if (code === codes.eof || code === codes.slash || code === codes.greaterThan || markdownLineEndingOrSpace(code)) { |
|
const slash = code === codes.slash; |
|
const name = buffer.toLowerCase(); |
|
if (!slash && !closingTag && htmlRawNames.includes(name)) { |
|
marker = constants.htmlRaw; |
|
return self.interrupt ? ok2(code) : continuation(code); |
|
} |
|
if (htmlBlockNames.includes(buffer.toLowerCase())) { |
|
marker = constants.htmlBasic; |
|
if (slash) { |
|
effects.consume(code); |
|
return basicSelfClosing; |
|
} |
|
return self.interrupt ? ok2(code) : continuation(code); |
|
} |
|
marker = constants.htmlComplete; |
|
return self.interrupt && !self.parser.lazy[self.now().line] ? nok(code) : closingTag ? completeClosingTagAfter(code) : completeAttributeNameBefore(code); |
|
} |
|
if (code === codes.dash || asciiAlphanumeric(code)) { |
|
effects.consume(code); |
|
buffer += String.fromCharCode(code); |
|
return tagName; |
|
} |
|
return nok(code); |
|
} |
|
function basicSelfClosing(code) { |
|
if (code === codes.greaterThan) { |
|
effects.consume(code); |
|
return self.interrupt ? ok2 : continuation; |
|
} |
|
return nok(code); |
|
} |
|
function completeClosingTagAfter(code) { |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return completeClosingTagAfter; |
|
} |
|
return completeEnd(code); |
|
} |
|
function completeAttributeNameBefore(code) { |
|
if (code === codes.slash) { |
|
effects.consume(code); |
|
return completeEnd; |
|
} |
|
if (code === codes.colon || code === codes.underscore || asciiAlpha(code)) { |
|
effects.consume(code); |
|
return completeAttributeName; |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return completeAttributeNameBefore; |
|
} |
|
return completeEnd(code); |
|
} |
|
function completeAttributeName(code) { |
|
if (code === codes.dash || code === codes.dot || code === codes.colon || code === codes.underscore || asciiAlphanumeric(code)) { |
|
effects.consume(code); |
|
return completeAttributeName; |
|
} |
|
return completeAttributeNameAfter(code); |
|
} |
|
function completeAttributeNameAfter(code) { |
|
if (code === codes.equalsTo) { |
|
effects.consume(code); |
|
return completeAttributeValueBefore; |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return completeAttributeNameAfter; |
|
} |
|
return completeAttributeNameBefore(code); |
|
} |
|
function completeAttributeValueBefore(code) { |
|
if (code === codes.eof || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent) { |
|
return nok(code); |
|
} |
|
if (code === codes.quotationMark || code === codes.apostrophe) { |
|
effects.consume(code); |
|
markerB = code; |
|
return completeAttributeValueQuoted; |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return completeAttributeValueBefore; |
|
} |
|
return completeAttributeValueUnquoted(code); |
|
} |
|
function completeAttributeValueQuoted(code) { |
|
if (code === markerB) { |
|
effects.consume(code); |
|
markerB = null; |
|
return completeAttributeValueQuotedAfter; |
|
} |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
return nok(code); |
|
} |
|
effects.consume(code); |
|
return completeAttributeValueQuoted; |
|
} |
|
function completeAttributeValueUnquoted(code) { |
|
if (code === codes.eof || code === codes.quotationMark || code === codes.apostrophe || code === codes.slash || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent || markdownLineEndingOrSpace(code)) { |
|
return completeAttributeNameAfter(code); |
|
} |
|
effects.consume(code); |
|
return completeAttributeValueUnquoted; |
|
} |
|
function completeAttributeValueQuotedAfter(code) { |
|
if (code === codes.slash || code === codes.greaterThan || markdownSpace(code)) { |
|
return completeAttributeNameBefore(code); |
|
} |
|
return nok(code); |
|
} |
|
function completeEnd(code) { |
|
if (code === codes.greaterThan) { |
|
effects.consume(code); |
|
return completeAfter; |
|
} |
|
return nok(code); |
|
} |
|
function completeAfter(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
return continuation(code); |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return completeAfter; |
|
} |
|
return nok(code); |
|
} |
|
function continuation(code) { |
|
if (code === codes.dash && marker === constants.htmlComment) { |
|
effects.consume(code); |
|
return continuationCommentInside; |
|
} |
|
if (code === codes.lessThan && marker === constants.htmlRaw) { |
|
effects.consume(code); |
|
return continuationRawTagOpen; |
|
} |
|
if (code === codes.greaterThan && marker === constants.htmlDeclaration) { |
|
effects.consume(code); |
|
return continuationClose; |
|
} |
|
if (code === codes.questionMark && marker === constants.htmlInstruction) { |
|
effects.consume(code); |
|
return continuationDeclarationInside; |
|
} |
|
if (code === codes.rightSquareBracket && marker === constants.htmlCdata) { |
|
effects.consume(code); |
|
return continuationCdataInside; |
|
} |
|
if (markdownLineEnding(code) && (marker === constants.htmlBasic || marker === constants.htmlComplete)) { |
|
effects.exit(types.htmlFlowData); |
|
return effects.check( |
|
blankLineBefore, |
|
continuationAfter, |
|
continuationStart |
|
)(code); |
|
} |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.htmlFlowData); |
|
return continuationStart(code); |
|
} |
|
effects.consume(code); |
|
return continuation; |
|
} |
|
function continuationStart(code) { |
|
return effects.check( |
|
nonLazyContinuationStart, |
|
continuationStartNonLazy, |
|
continuationAfter |
|
)(code); |
|
} |
|
function continuationStartNonLazy(code) { |
|
ok(markdownLineEnding(code)); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return continuationBefore; |
|
} |
|
function continuationBefore(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
return continuationStart(code); |
|
} |
|
effects.enter(types.htmlFlowData); |
|
return continuation(code); |
|
} |
|
function continuationCommentInside(code) { |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
return continuationDeclarationInside; |
|
} |
|
return continuation(code); |
|
} |
|
function continuationRawTagOpen(code) { |
|
if (code === codes.slash) { |
|
effects.consume(code); |
|
buffer = ""; |
|
return continuationRawEndTag; |
|
} |
|
return continuation(code); |
|
} |
|
function continuationRawEndTag(code) { |
|
if (code === codes.greaterThan) { |
|
const name = buffer.toLowerCase(); |
|
if (htmlRawNames.includes(name)) { |
|
effects.consume(code); |
|
return continuationClose; |
|
} |
|
return continuation(code); |
|
} |
|
if (asciiAlpha(code) && buffer.length < constants.htmlRawSizeMax) { |
|
effects.consume(code); |
|
buffer += String.fromCharCode(code); |
|
return continuationRawEndTag; |
|
} |
|
return continuation(code); |
|
} |
|
function continuationCdataInside(code) { |
|
if (code === codes.rightSquareBracket) { |
|
effects.consume(code); |
|
return continuationDeclarationInside; |
|
} |
|
return continuation(code); |
|
} |
|
function continuationDeclarationInside(code) { |
|
if (code === codes.greaterThan) { |
|
effects.consume(code); |
|
return continuationClose; |
|
} |
|
if (code === codes.dash && marker === constants.htmlComment) { |
|
effects.consume(code); |
|
return continuationDeclarationInside; |
|
} |
|
return continuation(code); |
|
} |
|
function continuationClose(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.htmlFlowData); |
|
return continuationAfter(code); |
|
} |
|
effects.consume(code); |
|
return continuationClose; |
|
} |
|
function continuationAfter(code) { |
|
effects.exit(types.htmlFlow); |
|
return ok2(code); |
|
} |
|
} |
|
function tokenizeNonLazyContinuationStart(effects, ok2, nok) { |
|
const self = this; |
|
return start; |
|
function start(code) { |
|
if (markdownLineEnding(code)) { |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return after; |
|
} |
|
return nok(code); |
|
} |
|
function after(code) { |
|
return self.parser.lazy[self.now().line] ? nok(code) : ok2(code); |
|
} |
|
} |
|
function tokenizeBlankLineBefore(effects, ok2, nok) { |
|
return start; |
|
function start(code) { |
|
ok(markdownLineEnding(code), "expected a line ending"); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return effects.attempt(blankLine, ok2, nok); |
|
} |
|
} |
|
|
|
|
|
var htmlText = { name: "htmlText", tokenize: tokenizeHtmlText }; |
|
function tokenizeHtmlText(effects, ok2, nok) { |
|
const self = this; |
|
let marker; |
|
let index2; |
|
let returnState; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.lessThan, "expected `<`"); |
|
effects.enter(types.htmlText); |
|
effects.enter(types.htmlTextData); |
|
effects.consume(code); |
|
return open; |
|
} |
|
function open(code) { |
|
if (code === codes.exclamationMark) { |
|
effects.consume(code); |
|
return declarationOpen; |
|
} |
|
if (code === codes.slash) { |
|
effects.consume(code); |
|
return tagCloseStart; |
|
} |
|
if (code === codes.questionMark) { |
|
effects.consume(code); |
|
return instruction; |
|
} |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
return tagOpen; |
|
} |
|
return nok(code); |
|
} |
|
function declarationOpen(code) { |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
return commentOpenInside; |
|
} |
|
if (code === codes.leftSquareBracket) { |
|
effects.consume(code); |
|
index2 = 0; |
|
return cdataOpenInside; |
|
} |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
return declaration; |
|
} |
|
return nok(code); |
|
} |
|
function commentOpenInside(code) { |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
return commentEnd; |
|
} |
|
return nok(code); |
|
} |
|
function comment(code) { |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
return commentClose; |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = comment; |
|
return lineEndingBefore(code); |
|
} |
|
effects.consume(code); |
|
return comment; |
|
} |
|
function commentClose(code) { |
|
if (code === codes.dash) { |
|
effects.consume(code); |
|
return commentEnd; |
|
} |
|
return comment(code); |
|
} |
|
function commentEnd(code) { |
|
return code === codes.greaterThan ? end(code) : code === codes.dash ? commentClose(code) : comment(code); |
|
} |
|
function cdataOpenInside(code) { |
|
const value = constants.cdataOpeningString; |
|
if (code === value.charCodeAt(index2++)) { |
|
effects.consume(code); |
|
return index2 === value.length ? cdata : cdataOpenInside; |
|
} |
|
return nok(code); |
|
} |
|
function cdata(code) { |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
if (code === codes.rightSquareBracket) { |
|
effects.consume(code); |
|
return cdataClose; |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = cdata; |
|
return lineEndingBefore(code); |
|
} |
|
effects.consume(code); |
|
return cdata; |
|
} |
|
function cdataClose(code) { |
|
if (code === codes.rightSquareBracket) { |
|
effects.consume(code); |
|
return cdataEnd; |
|
} |
|
return cdata(code); |
|
} |
|
function cdataEnd(code) { |
|
if (code === codes.greaterThan) { |
|
return end(code); |
|
} |
|
if (code === codes.rightSquareBracket) { |
|
effects.consume(code); |
|
return cdataEnd; |
|
} |
|
return cdata(code); |
|
} |
|
function declaration(code) { |
|
if (code === codes.eof || code === codes.greaterThan) { |
|
return end(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = declaration; |
|
return lineEndingBefore(code); |
|
} |
|
effects.consume(code); |
|
return declaration; |
|
} |
|
function instruction(code) { |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
if (code === codes.questionMark) { |
|
effects.consume(code); |
|
return instructionClose; |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = instruction; |
|
return lineEndingBefore(code); |
|
} |
|
effects.consume(code); |
|
return instruction; |
|
} |
|
function instructionClose(code) { |
|
return code === codes.greaterThan ? end(code) : instruction(code); |
|
} |
|
function tagCloseStart(code) { |
|
if (asciiAlpha(code)) { |
|
effects.consume(code); |
|
return tagClose; |
|
} |
|
return nok(code); |
|
} |
|
function tagClose(code) { |
|
if (code === codes.dash || asciiAlphanumeric(code)) { |
|
effects.consume(code); |
|
return tagClose; |
|
} |
|
return tagCloseBetween(code); |
|
} |
|
function tagCloseBetween(code) { |
|
if (markdownLineEnding(code)) { |
|
returnState = tagCloseBetween; |
|
return lineEndingBefore(code); |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return tagCloseBetween; |
|
} |
|
return end(code); |
|
} |
|
function tagOpen(code) { |
|
if (code === codes.dash || asciiAlphanumeric(code)) { |
|
effects.consume(code); |
|
return tagOpen; |
|
} |
|
if (code === codes.slash || code === codes.greaterThan || markdownLineEndingOrSpace(code)) { |
|
return tagOpenBetween(code); |
|
} |
|
return nok(code); |
|
} |
|
function tagOpenBetween(code) { |
|
if (code === codes.slash) { |
|
effects.consume(code); |
|
return end; |
|
} |
|
if (code === codes.colon || code === codes.underscore || asciiAlpha(code)) { |
|
effects.consume(code); |
|
return tagOpenAttributeName; |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = tagOpenBetween; |
|
return lineEndingBefore(code); |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return tagOpenBetween; |
|
} |
|
return end(code); |
|
} |
|
function tagOpenAttributeName(code) { |
|
if (code === codes.dash || code === codes.dot || code === codes.colon || code === codes.underscore || asciiAlphanumeric(code)) { |
|
effects.consume(code); |
|
return tagOpenAttributeName; |
|
} |
|
return tagOpenAttributeNameAfter(code); |
|
} |
|
function tagOpenAttributeNameAfter(code) { |
|
if (code === codes.equalsTo) { |
|
effects.consume(code); |
|
return tagOpenAttributeValueBefore; |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = tagOpenAttributeNameAfter; |
|
return lineEndingBefore(code); |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return tagOpenAttributeNameAfter; |
|
} |
|
return tagOpenBetween(code); |
|
} |
|
function tagOpenAttributeValueBefore(code) { |
|
if (code === codes.eof || code === codes.lessThan || code === codes.equalsTo || code === codes.greaterThan || code === codes.graveAccent) { |
|
return nok(code); |
|
} |
|
if (code === codes.quotationMark || code === codes.apostrophe) { |
|
effects.consume(code); |
|
marker = code; |
|
return tagOpenAttributeValueQuoted; |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = tagOpenAttributeValueBefore; |
|
return lineEndingBefore(code); |
|
} |
|
if (markdownSpace(code)) { |
|
effects.consume(code); |
|
return tagOpenAttributeValueBefore; |
|
} |
|
effects.consume(code); |
|
return tagOpenAttributeValueUnquoted; |
|
} |
|
function tagOpenAttributeValueQuoted(code) { |
|
if (code === marker) { |
|
effects.consume(code); |
|
marker = void 0; |
|
return tagOpenAttributeValueQuotedAfter; |
|
} |
|
if (code === codes.eof) { |
|
return nok(code); |
|
} |
|
if (markdownLineEnding(code)) { |
|
returnState = tagOpenAttributeValueQuoted; |
|
return lineEndingBefore(code); |
|
} |
|
effects.consume(code); |
|
return tagOpenAttributeValueQuoted; |
|
} |
|
function tagOpenAttributeValueUnquoted(code) { |
|
if (code === codes.eof || code === codes.quotationMark || code === codes.apostrophe || code === codes.lessThan || code === codes.equalsTo || code === codes.graveAccent) { |
|
return nok(code); |
|
} |
|
if (code === codes.slash || code === codes.greaterThan || markdownLineEndingOrSpace(code)) { |
|
return tagOpenBetween(code); |
|
} |
|
effects.consume(code); |
|
return tagOpenAttributeValueUnquoted; |
|
} |
|
function tagOpenAttributeValueQuotedAfter(code) { |
|
if (code === codes.slash || code === codes.greaterThan || markdownLineEndingOrSpace(code)) { |
|
return tagOpenBetween(code); |
|
} |
|
return nok(code); |
|
} |
|
function end(code) { |
|
if (code === codes.greaterThan) { |
|
effects.consume(code); |
|
effects.exit(types.htmlTextData); |
|
effects.exit(types.htmlText); |
|
return ok2; |
|
} |
|
return nok(code); |
|
} |
|
function lineEndingBefore(code) { |
|
ok(returnState, "expected return state"); |
|
ok(markdownLineEnding(code), "expected eol"); |
|
effects.exit(types.htmlTextData); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return lineEndingAfter; |
|
} |
|
function lineEndingAfter(code) { |
|
ok( |
|
self.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
return markdownSpace(code) ? factorySpace( |
|
effects, |
|
lineEndingAfterPrefix, |
|
types.linePrefix, |
|
self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : constants.tabSize |
|
)(code) : lineEndingAfterPrefix(code); |
|
} |
|
function lineEndingAfterPrefix(code) { |
|
effects.enter(types.htmlTextData); |
|
return returnState(code); |
|
} |
|
} |
|
|
|
|
|
var labelEnd = { |
|
name: "labelEnd", |
|
tokenize: tokenizeLabelEnd, |
|
resolveTo: resolveToLabelEnd, |
|
resolveAll: resolveAllLabelEnd |
|
}; |
|
var resourceConstruct = { tokenize: tokenizeResource }; |
|
var referenceFullConstruct = { tokenize: tokenizeReferenceFull }; |
|
var referenceCollapsedConstruct = { tokenize: tokenizeReferenceCollapsed }; |
|
function resolveAllLabelEnd(events) { |
|
let index2 = -1; |
|
while (++index2 < events.length) { |
|
const token = events[index2][1]; |
|
if (token.type === types.labelImage || token.type === types.labelLink || token.type === types.labelEnd) { |
|
events.splice(index2 + 1, token.type === types.labelImage ? 4 : 2); |
|
token.type = types.data; |
|
index2++; |
|
} |
|
} |
|
return events; |
|
} |
|
function resolveToLabelEnd(events, context) { |
|
let index2 = events.length; |
|
let offset = 0; |
|
let token; |
|
let open; |
|
let close; |
|
let media; |
|
while (index2--) { |
|
token = events[index2][1]; |
|
if (open) { |
|
if (token.type === types.link || token.type === types.labelLink && token._inactive) { |
|
break; |
|
} |
|
if (events[index2][0] === "enter" && token.type === types.labelLink) { |
|
token._inactive = true; |
|
} |
|
} else if (close) { |
|
if (events[index2][0] === "enter" && (token.type === types.labelImage || token.type === types.labelLink) && !token._balanced) { |
|
open = index2; |
|
if (token.type !== types.labelLink) { |
|
offset = 2; |
|
break; |
|
} |
|
} |
|
} else if (token.type === types.labelEnd) { |
|
close = index2; |
|
} |
|
} |
|
ok(open !== void 0, "`open` is supposed to be found"); |
|
ok(close !== void 0, "`close` is supposed to be found"); |
|
const group = { |
|
type: events[open][1].type === types.labelLink ? types.link : types.image, |
|
start: Object.assign({}, events[open][1].start), |
|
end: Object.assign({}, events[events.length - 1][1].end) |
|
}; |
|
const label = { |
|
type: types.label, |
|
start: Object.assign({}, events[open][1].start), |
|
end: Object.assign({}, events[close][1].end) |
|
}; |
|
const text3 = { |
|
type: types.labelText, |
|
start: Object.assign({}, events[open + offset + 2][1].end), |
|
end: Object.assign({}, events[close - 2][1].start) |
|
}; |
|
media = [ |
|
["enter", group, context], |
|
["enter", label, context] |
|
]; |
|
media = push(media, events.slice(open + 1, open + offset + 3)); |
|
media = push(media, [["enter", text3, context]]); |
|
ok( |
|
context.parser.constructs.insideSpan.null, |
|
"expected `insideSpan.null` to be populated" |
|
); |
|
media = push( |
|
media, |
|
resolveAll( |
|
context.parser.constructs.insideSpan.null, |
|
events.slice(open + offset + 4, close - 3), |
|
context |
|
) |
|
); |
|
media = push(media, [ |
|
["exit", text3, context], |
|
events[close - 2], |
|
events[close - 1], |
|
["exit", label, context] |
|
]); |
|
media = push(media, events.slice(close + 1)); |
|
media = push(media, [["exit", group, context]]); |
|
splice(events, open, events.length, media); |
|
return events; |
|
} |
|
function tokenizeLabelEnd(effects, ok2, nok) { |
|
const self = this; |
|
let index2 = self.events.length; |
|
let labelStart; |
|
let defined; |
|
while (index2--) { |
|
if ((self.events[index2][1].type === types.labelImage || self.events[index2][1].type === types.labelLink) && !self.events[index2][1]._balanced) { |
|
labelStart = self.events[index2][1]; |
|
break; |
|
} |
|
} |
|
return start; |
|
function start(code) { |
|
ok(code === codes.rightSquareBracket, "expected `]`"); |
|
if (!labelStart) { |
|
return nok(code); |
|
} |
|
if (labelStart._inactive) { |
|
return labelEndNok(code); |
|
} |
|
defined = self.parser.defined.includes( |
|
normalizeIdentifier( |
|
self.sliceSerialize({ start: labelStart.end, end: self.now() }) |
|
) |
|
); |
|
effects.enter(types.labelEnd); |
|
effects.enter(types.labelMarker); |
|
effects.consume(code); |
|
effects.exit(types.labelMarker); |
|
effects.exit(types.labelEnd); |
|
return after; |
|
} |
|
function after(code) { |
|
if (code === codes.leftParenthesis) { |
|
return effects.attempt( |
|
resourceConstruct, |
|
labelEndOk, |
|
defined ? labelEndOk : labelEndNok |
|
)(code); |
|
} |
|
if (code === codes.leftSquareBracket) { |
|
return effects.attempt( |
|
referenceFullConstruct, |
|
labelEndOk, |
|
defined ? referenceNotFull : labelEndNok |
|
)(code); |
|
} |
|
return defined ? labelEndOk(code) : labelEndNok(code); |
|
} |
|
function referenceNotFull(code) { |
|
return effects.attempt( |
|
referenceCollapsedConstruct, |
|
labelEndOk, |
|
labelEndNok |
|
)(code); |
|
} |
|
function labelEndOk(code) { |
|
return ok2(code); |
|
} |
|
function labelEndNok(code) { |
|
labelStart._balanced = true; |
|
return nok(code); |
|
} |
|
} |
|
function tokenizeResource(effects, ok2, nok) { |
|
return resourceStart; |
|
function resourceStart(code) { |
|
ok(code === codes.leftParenthesis, "expected left paren"); |
|
effects.enter(types.resource); |
|
effects.enter(types.resourceMarker); |
|
effects.consume(code); |
|
effects.exit(types.resourceMarker); |
|
return resourceBefore; |
|
} |
|
function resourceBefore(code) { |
|
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, resourceOpen)(code) : resourceOpen(code); |
|
} |
|
function resourceOpen(code) { |
|
if (code === codes.rightParenthesis) { |
|
return resourceEnd(code); |
|
} |
|
return factoryDestination( |
|
effects, |
|
resourceDestinationAfter, |
|
resourceDestinationMissing, |
|
types.resourceDestination, |
|
types.resourceDestinationLiteral, |
|
types.resourceDestinationLiteralMarker, |
|
types.resourceDestinationRaw, |
|
types.resourceDestinationString, |
|
constants.linkResourceDestinationBalanceMax |
|
)(code); |
|
} |
|
function resourceDestinationAfter(code) { |
|
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, resourceBetween)(code) : resourceEnd(code); |
|
} |
|
function resourceDestinationMissing(code) { |
|
return nok(code); |
|
} |
|
function resourceBetween(code) { |
|
if (code === codes.quotationMark || code === codes.apostrophe || code === codes.leftParenthesis) { |
|
return factoryTitle( |
|
effects, |
|
resourceTitleAfter, |
|
nok, |
|
types.resourceTitle, |
|
types.resourceTitleMarker, |
|
types.resourceTitleString |
|
)(code); |
|
} |
|
return resourceEnd(code); |
|
} |
|
function resourceTitleAfter(code) { |
|
return markdownLineEndingOrSpace(code) ? factoryWhitespace(effects, resourceEnd)(code) : resourceEnd(code); |
|
} |
|
function resourceEnd(code) { |
|
if (code === codes.rightParenthesis) { |
|
effects.enter(types.resourceMarker); |
|
effects.consume(code); |
|
effects.exit(types.resourceMarker); |
|
effects.exit(types.resource); |
|
return ok2; |
|
} |
|
return nok(code); |
|
} |
|
} |
|
function tokenizeReferenceFull(effects, ok2, nok) { |
|
const self = this; |
|
return referenceFull; |
|
function referenceFull(code) { |
|
ok(code === codes.leftSquareBracket, "expected left bracket"); |
|
return factoryLabel.call( |
|
self, |
|
effects, |
|
referenceFullAfter, |
|
referenceFullMissing, |
|
types.reference, |
|
types.referenceMarker, |
|
types.referenceString |
|
)(code); |
|
} |
|
function referenceFullAfter(code) { |
|
return self.parser.defined.includes( |
|
normalizeIdentifier( |
|
self.sliceSerialize(self.events[self.events.length - 1][1]).slice(1, -1) |
|
) |
|
) ? ok2(code) : nok(code); |
|
} |
|
function referenceFullMissing(code) { |
|
return nok(code); |
|
} |
|
} |
|
function tokenizeReferenceCollapsed(effects, ok2, nok) { |
|
return referenceCollapsedStart; |
|
function referenceCollapsedStart(code) { |
|
ok(code === codes.leftSquareBracket, "expected left bracket"); |
|
effects.enter(types.reference); |
|
effects.enter(types.referenceMarker); |
|
effects.consume(code); |
|
effects.exit(types.referenceMarker); |
|
return referenceCollapsedOpen; |
|
} |
|
function referenceCollapsedOpen(code) { |
|
if (code === codes.rightSquareBracket) { |
|
effects.enter(types.referenceMarker); |
|
effects.consume(code); |
|
effects.exit(types.referenceMarker); |
|
effects.exit(types.reference); |
|
return ok2; |
|
} |
|
return nok(code); |
|
} |
|
} |
|
|
|
|
|
var labelStartImage = { |
|
name: "labelStartImage", |
|
tokenize: tokenizeLabelStartImage, |
|
resolveAll: labelEnd.resolveAll |
|
}; |
|
function tokenizeLabelStartImage(effects, ok2, nok) { |
|
const self = this; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.exclamationMark, "expected `!`"); |
|
effects.enter(types.labelImage); |
|
effects.enter(types.labelImageMarker); |
|
effects.consume(code); |
|
effects.exit(types.labelImageMarker); |
|
return open; |
|
} |
|
function open(code) { |
|
if (code === codes.leftSquareBracket) { |
|
effects.enter(types.labelMarker); |
|
effects.consume(code); |
|
effects.exit(types.labelMarker); |
|
effects.exit(types.labelImage); |
|
return after; |
|
} |
|
return nok(code); |
|
} |
|
function after(code) { |
|
return code === codes.caret && "_hiddenFootnoteSupport" in self.parser.constructs ? nok(code) : ok2(code); |
|
} |
|
} |
|
|
|
|
|
var labelStartLink = { |
|
name: "labelStartLink", |
|
tokenize: tokenizeLabelStartLink, |
|
resolveAll: labelEnd.resolveAll |
|
}; |
|
function tokenizeLabelStartLink(effects, ok2, nok) { |
|
const self = this; |
|
return start; |
|
function start(code) { |
|
ok(code === codes.leftSquareBracket, "expected `[`"); |
|
effects.enter(types.labelLink); |
|
effects.enter(types.labelMarker); |
|
effects.consume(code); |
|
effects.exit(types.labelMarker); |
|
effects.exit(types.labelLink); |
|
return after; |
|
} |
|
function after(code) { |
|
return code === codes.caret && "_hiddenFootnoteSupport" in self.parser.constructs ? nok(code) : ok2(code); |
|
} |
|
} |
|
|
|
|
|
var lineEnding = { name: "lineEnding", tokenize: tokenizeLineEnding }; |
|
function tokenizeLineEnding(effects, ok2) { |
|
return start; |
|
function start(code) { |
|
ok(markdownLineEnding(code), "expected eol"); |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
return factorySpace(effects, ok2, types.linePrefix); |
|
} |
|
} |
|
|
|
|
|
var thematicBreak = { |
|
name: "thematicBreak", |
|
tokenize: tokenizeThematicBreak |
|
}; |
|
function tokenizeThematicBreak(effects, ok2, nok) { |
|
let size = 0; |
|
let marker; |
|
return start; |
|
function start(code) { |
|
effects.enter(types.thematicBreak); |
|
return before(code); |
|
} |
|
function before(code) { |
|
ok( |
|
code === codes.asterisk || code === codes.dash || code === codes.underscore, |
|
"expected `*`, `-`, or `_`" |
|
); |
|
marker = code; |
|
return atBreak(code); |
|
} |
|
function atBreak(code) { |
|
if (code === marker) { |
|
effects.enter(types.thematicBreakSequence); |
|
return sequence(code); |
|
} |
|
if (size >= constants.thematicBreakMarkerCountMin && (code === codes.eof || markdownLineEnding(code))) { |
|
effects.exit(types.thematicBreak); |
|
return ok2(code); |
|
} |
|
return nok(code); |
|
} |
|
function sequence(code) { |
|
if (code === marker) { |
|
effects.consume(code); |
|
size++; |
|
return sequence; |
|
} |
|
effects.exit(types.thematicBreakSequence); |
|
return markdownSpace(code) ? factorySpace(effects, atBreak, types.whitespace)(code) : atBreak(code); |
|
} |
|
} |
|
|
|
|
|
var list = { |
|
name: "list", |
|
tokenize: tokenizeListStart, |
|
continuation: { tokenize: tokenizeListContinuation }, |
|
exit: tokenizeListEnd |
|
}; |
|
var listItemPrefixWhitespaceConstruct = { |
|
tokenize: tokenizeListItemPrefixWhitespace, |
|
partial: true |
|
}; |
|
var indentConstruct = { tokenize: tokenizeIndent, partial: true }; |
|
function tokenizeListStart(effects, ok2, nok) { |
|
const self = this; |
|
const tail = self.events[self.events.length - 1]; |
|
let initialSize = tail && tail[1].type === types.linePrefix ? tail[2].sliceSerialize(tail[1], true).length : 0; |
|
let size = 0; |
|
return start; |
|
function start(code) { |
|
ok(self.containerState, "expected state"); |
|
const kind = self.containerState.type || (code === codes.asterisk || code === codes.plusSign || code === codes.dash ? types.listUnordered : types.listOrdered); |
|
if (kind === types.listUnordered ? !self.containerState.marker || code === self.containerState.marker : asciiDigit(code)) { |
|
if (!self.containerState.type) { |
|
self.containerState.type = kind; |
|
effects.enter(kind, { _container: true }); |
|
} |
|
if (kind === types.listUnordered) { |
|
effects.enter(types.listItemPrefix); |
|
return code === codes.asterisk || code === codes.dash ? effects.check(thematicBreak, nok, atMarker)(code) : atMarker(code); |
|
} |
|
if (!self.interrupt || code === codes.digit1) { |
|
effects.enter(types.listItemPrefix); |
|
effects.enter(types.listItemValue); |
|
return inside(code); |
|
} |
|
} |
|
return nok(code); |
|
} |
|
function inside(code) { |
|
ok(self.containerState, "expected state"); |
|
if (asciiDigit(code) && ++size < constants.listItemValueSizeMax) { |
|
effects.consume(code); |
|
return inside; |
|
} |
|
if ((!self.interrupt || size < 2) && (self.containerState.marker ? code === self.containerState.marker : code === codes.rightParenthesis || code === codes.dot)) { |
|
effects.exit(types.listItemValue); |
|
return atMarker(code); |
|
} |
|
return nok(code); |
|
} |
|
function atMarker(code) { |
|
ok(self.containerState, "expected state"); |
|
ok(code !== codes.eof, "eof (`null`) is not a marker"); |
|
effects.enter(types.listItemMarker); |
|
effects.consume(code); |
|
effects.exit(types.listItemMarker); |
|
self.containerState.marker = self.containerState.marker || code; |
|
return effects.check( |
|
blankLine, |
|
|
|
self.interrupt ? nok : onBlank, |
|
effects.attempt( |
|
listItemPrefixWhitespaceConstruct, |
|
endOfPrefix, |
|
otherPrefix |
|
) |
|
); |
|
} |
|
function onBlank(code) { |
|
ok(self.containerState, "expected state"); |
|
self.containerState.initialBlankLine = true; |
|
initialSize++; |
|
return endOfPrefix(code); |
|
} |
|
function otherPrefix(code) { |
|
if (markdownSpace(code)) { |
|
effects.enter(types.listItemPrefixWhitespace); |
|
effects.consume(code); |
|
effects.exit(types.listItemPrefixWhitespace); |
|
return endOfPrefix; |
|
} |
|
return nok(code); |
|
} |
|
function endOfPrefix(code) { |
|
ok(self.containerState, "expected state"); |
|
self.containerState.size = initialSize + self.sliceSerialize(effects.exit(types.listItemPrefix), true).length; |
|
return ok2(code); |
|
} |
|
} |
|
function tokenizeListContinuation(effects, ok2, nok) { |
|
const self = this; |
|
ok(self.containerState, "expected state"); |
|
self.containerState._closeFlow = void 0; |
|
return effects.check(blankLine, onBlank, notBlank); |
|
function onBlank(code) { |
|
ok(self.containerState, "expected state"); |
|
ok(typeof self.containerState.size === "number", "expected size"); |
|
self.containerState.furtherBlankLines = self.containerState.furtherBlankLines || self.containerState.initialBlankLine; |
|
return factorySpace( |
|
effects, |
|
ok2, |
|
types.listItemIndent, |
|
self.containerState.size + 1 |
|
)(code); |
|
} |
|
function notBlank(code) { |
|
ok(self.containerState, "expected state"); |
|
if (self.containerState.furtherBlankLines || !markdownSpace(code)) { |
|
self.containerState.furtherBlankLines = void 0; |
|
self.containerState.initialBlankLine = void 0; |
|
return notInCurrentItem(code); |
|
} |
|
self.containerState.furtherBlankLines = void 0; |
|
self.containerState.initialBlankLine = void 0; |
|
return effects.attempt(indentConstruct, ok2, notInCurrentItem)(code); |
|
} |
|
function notInCurrentItem(code) { |
|
ok(self.containerState, "expected state"); |
|
self.containerState._closeFlow = true; |
|
self.interrupt = void 0; |
|
ok( |
|
self.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
return factorySpace( |
|
effects, |
|
effects.attempt(list, ok2, nok), |
|
types.linePrefix, |
|
self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : constants.tabSize |
|
)(code); |
|
} |
|
} |
|
function tokenizeIndent(effects, ok2, nok) { |
|
const self = this; |
|
ok(self.containerState, "expected state"); |
|
ok(typeof self.containerState.size === "number", "expected size"); |
|
return factorySpace( |
|
effects, |
|
afterPrefix, |
|
types.listItemIndent, |
|
self.containerState.size + 1 |
|
); |
|
function afterPrefix(code) { |
|
ok(self.containerState, "expected state"); |
|
const tail = self.events[self.events.length - 1]; |
|
return tail && tail[1].type === types.listItemIndent && tail[2].sliceSerialize(tail[1], true).length === self.containerState.size ? ok2(code) : nok(code); |
|
} |
|
} |
|
function tokenizeListEnd(effects) { |
|
ok(this.containerState, "expected state"); |
|
ok(typeof this.containerState.type === "string", "expected type"); |
|
effects.exit(this.containerState.type); |
|
} |
|
function tokenizeListItemPrefixWhitespace(effects, ok2, nok) { |
|
const self = this; |
|
ok( |
|
self.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
return factorySpace( |
|
effects, |
|
afterPrefix, |
|
types.listItemPrefixWhitespace, |
|
self.parser.constructs.disable.null.includes("codeIndented") ? void 0 : constants.tabSize + 1 |
|
); |
|
function afterPrefix(code) { |
|
const tail = self.events[self.events.length - 1]; |
|
return !markdownSpace(code) && tail && tail[1].type === types.listItemPrefixWhitespace ? ok2(code) : nok(code); |
|
} |
|
} |
|
|
|
|
|
var setextUnderline = { |
|
name: "setextUnderline", |
|
tokenize: tokenizeSetextUnderline, |
|
resolveTo: resolveToSetextUnderline |
|
}; |
|
function resolveToSetextUnderline(events, context) { |
|
let index2 = events.length; |
|
let content3; |
|
let text3; |
|
let definition2; |
|
while (index2--) { |
|
if (events[index2][0] === "enter") { |
|
if (events[index2][1].type === types.content) { |
|
content3 = index2; |
|
break; |
|
} |
|
if (events[index2][1].type === types.paragraph) { |
|
text3 = index2; |
|
} |
|
} else { |
|
if (events[index2][1].type === types.content) { |
|
events.splice(index2, 1); |
|
} |
|
if (!definition2 && events[index2][1].type === types.definition) { |
|
definition2 = index2; |
|
} |
|
} |
|
} |
|
ok(text3 !== void 0, "expected a `text` index to be found"); |
|
ok(content3 !== void 0, "expected a `text` index to be found"); |
|
const heading = { |
|
type: types.setextHeading, |
|
start: Object.assign({}, events[text3][1].start), |
|
end: Object.assign({}, events[events.length - 1][1].end) |
|
}; |
|
events[text3][1].type = types.setextHeadingText; |
|
if (definition2) { |
|
events.splice(text3, 0, ["enter", heading, context]); |
|
events.splice(definition2 + 1, 0, ["exit", events[content3][1], context]); |
|
events[content3][1].end = Object.assign({}, events[definition2][1].end); |
|
} else { |
|
events[content3][1] = heading; |
|
} |
|
events.push(["exit", heading, context]); |
|
return events; |
|
} |
|
function tokenizeSetextUnderline(effects, ok2, nok) { |
|
const self = this; |
|
let marker; |
|
return start; |
|
function start(code) { |
|
let index2 = self.events.length; |
|
let paragraph; |
|
ok( |
|
code === codes.dash || code === codes.equalsTo, |
|
"expected `=` or `-`" |
|
); |
|
while (index2--) { |
|
if (self.events[index2][1].type !== types.lineEnding && self.events[index2][1].type !== types.linePrefix && self.events[index2][1].type !== types.content) { |
|
paragraph = self.events[index2][1].type === types.paragraph; |
|
break; |
|
} |
|
} |
|
if (!self.parser.lazy[self.now().line] && (self.interrupt || paragraph)) { |
|
effects.enter(types.setextHeadingLine); |
|
marker = code; |
|
return before(code); |
|
} |
|
return nok(code); |
|
} |
|
function before(code) { |
|
effects.enter(types.setextHeadingLineSequence); |
|
return inside(code); |
|
} |
|
function inside(code) { |
|
if (code === marker) { |
|
effects.consume(code); |
|
return inside; |
|
} |
|
effects.exit(types.setextHeadingLineSequence); |
|
return markdownSpace(code) ? factorySpace(effects, after, types.lineSuffix)(code) : after(code); |
|
} |
|
function after(code) { |
|
if (code === codes.eof || markdownLineEnding(code)) { |
|
effects.exit(types.setextHeadingLine); |
|
return ok2(code); |
|
} |
|
return nok(code); |
|
} |
|
} |
|
|
|
|
|
var flow = { tokenize: initializeFlow }; |
|
function initializeFlow(effects) { |
|
const self = this; |
|
const initial = effects.attempt( |
|
|
|
blankLine, |
|
atBlankEnding, |
|
|
|
effects.attempt( |
|
this.parser.constructs.flowInitial, |
|
afterConstruct, |
|
factorySpace( |
|
effects, |
|
effects.attempt( |
|
this.parser.constructs.flow, |
|
afterConstruct, |
|
effects.attempt(content2, afterConstruct) |
|
), |
|
types.linePrefix |
|
) |
|
) |
|
); |
|
return initial; |
|
function atBlankEnding(code) { |
|
ok( |
|
code === codes.eof || markdownLineEnding(code), |
|
"expected eol or eof" |
|
); |
|
if (code === codes.eof) { |
|
effects.consume(code); |
|
return; |
|
} |
|
effects.enter(types.lineEndingBlank); |
|
effects.consume(code); |
|
effects.exit(types.lineEndingBlank); |
|
self.currentConstruct = void 0; |
|
return initial; |
|
} |
|
function afterConstruct(code) { |
|
ok( |
|
code === codes.eof || markdownLineEnding(code), |
|
"expected eol or eof" |
|
); |
|
if (code === codes.eof) { |
|
effects.consume(code); |
|
return; |
|
} |
|
effects.enter(types.lineEnding); |
|
effects.consume(code); |
|
effects.exit(types.lineEnding); |
|
self.currentConstruct = void 0; |
|
return initial; |
|
} |
|
} |
|
|
|
|
|
var resolver = { resolveAll: createResolver() }; |
|
var string = initializeFactory("string"); |
|
var text = initializeFactory("text"); |
|
function initializeFactory(field) { |
|
return { |
|
tokenize: initializeText, |
|
resolveAll: createResolver( |
|
field === "text" ? resolveAllLineSuffixes : void 0 |
|
) |
|
}; |
|
function initializeText(effects) { |
|
const self = this; |
|
const constructs2 = this.parser.constructs[field]; |
|
const text3 = effects.attempt(constructs2, start, notText); |
|
return start; |
|
function start(code) { |
|
return atBreak(code) ? text3(code) : notText(code); |
|
} |
|
function notText(code) { |
|
if (code === codes.eof) { |
|
effects.consume(code); |
|
return; |
|
} |
|
effects.enter(types.data); |
|
effects.consume(code); |
|
return data; |
|
} |
|
function data(code) { |
|
if (atBreak(code)) { |
|
effects.exit(types.data); |
|
return text3(code); |
|
} |
|
effects.consume(code); |
|
return data; |
|
} |
|
function atBreak(code) { |
|
if (code === codes.eof) { |
|
return true; |
|
} |
|
const list2 = constructs2[code]; |
|
let index2 = -1; |
|
if (list2) { |
|
ok(Array.isArray(list2), "expected `disable.null` to be populated"); |
|
while (++index2 < list2.length) { |
|
const item = list2[index2]; |
|
if (!item.previous || item.previous.call(self, self.previous)) { |
|
return true; |
|
} |
|
} |
|
} |
|
return false; |
|
} |
|
} |
|
} |
|
function createResolver(extraResolver) { |
|
return resolveAllText; |
|
function resolveAllText(events, context) { |
|
let index2 = -1; |
|
let enter; |
|
while (++index2 <= events.length) { |
|
if (enter === void 0) { |
|
if (events[index2] && events[index2][1].type === types.data) { |
|
enter = index2; |
|
index2++; |
|
} |
|
} else if (!events[index2] || events[index2][1].type !== types.data) { |
|
if (index2 !== enter + 2) { |
|
events[enter][1].end = events[index2 - 1][1].end; |
|
events.splice(enter + 2, index2 - enter - 2); |
|
index2 = enter + 2; |
|
} |
|
enter = void 0; |
|
} |
|
} |
|
return extraResolver ? extraResolver(events, context) : events; |
|
} |
|
} |
|
function resolveAllLineSuffixes(events, context) { |
|
let eventIndex = 0; |
|
while (++eventIndex <= events.length) { |
|
if ((eventIndex === events.length || events[eventIndex][1].type === types.lineEnding) && events[eventIndex - 1][1].type === types.data) { |
|
const data = events[eventIndex - 1][1]; |
|
const chunks = context.sliceStream(data); |
|
let index2 = chunks.length; |
|
let bufferIndex = -1; |
|
let size = 0; |
|
let tabs; |
|
while (index2--) { |
|
const chunk = chunks[index2]; |
|
if (typeof chunk === "string") { |
|
bufferIndex = chunk.length; |
|
while (chunk.charCodeAt(bufferIndex - 1) === codes.space) { |
|
size++; |
|
bufferIndex--; |
|
} |
|
if (bufferIndex) break; |
|
bufferIndex = -1; |
|
} else if (chunk === codes.horizontalTab) { |
|
tabs = true; |
|
size++; |
|
} else if (chunk === codes.virtualSpace) { |
|
} else { |
|
index2++; |
|
break; |
|
} |
|
} |
|
if (size) { |
|
const token = { |
|
type: eventIndex === events.length || tabs || size < constants.hardBreakPrefixSizeMin ? types.lineSuffix : types.hardBreakTrailing, |
|
start: { |
|
line: data.end.line, |
|
column: data.end.column - size, |
|
offset: data.end.offset - size, |
|
_index: data.start._index + index2, |
|
_bufferIndex: index2 ? bufferIndex : data.start._bufferIndex + bufferIndex |
|
}, |
|
end: Object.assign({}, data.end) |
|
}; |
|
data.end = Object.assign({}, token.start); |
|
if (data.start.offset === data.end.offset) { |
|
Object.assign(data, token); |
|
} else { |
|
events.splice( |
|
eventIndex, |
|
0, |
|
["enter", token, context], |
|
["exit", token, context] |
|
); |
|
eventIndex += 2; |
|
} |
|
} |
|
eventIndex++; |
|
} |
|
} |
|
return events; |
|
} |
|
|
|
|
|
var import_debug = __toESM(require_browser(), 1); |
|
var debug = (0, import_debug.default)("micromark"); |
|
function createTokenizer(parser, initialize, from) { |
|
let point3 = Object.assign( |
|
from ? Object.assign({}, from) : { line: 1, column: 1, offset: 0 }, |
|
{ _index: 0, _bufferIndex: -1 } |
|
); |
|
const columnStart = {}; |
|
const resolveAllConstructs = []; |
|
let chunks = []; |
|
let stack = []; |
|
let consumed = true; |
|
const effects = { |
|
consume, |
|
enter, |
|
exit: exit2, |
|
attempt: constructFactory(onsuccessfulconstruct), |
|
check: constructFactory(onsuccessfulcheck), |
|
interrupt: constructFactory(onsuccessfulcheck, { interrupt: true }) |
|
}; |
|
const context = { |
|
previous: codes.eof, |
|
code: codes.eof, |
|
containerState: {}, |
|
events: [], |
|
parser, |
|
sliceStream, |
|
sliceSerialize, |
|
now, |
|
defineSkip, |
|
write |
|
}; |
|
let state = initialize.tokenize.call(context, effects); |
|
let expectedCode; |
|
if (initialize.resolveAll) { |
|
resolveAllConstructs.push(initialize); |
|
} |
|
return context; |
|
function write(slice) { |
|
chunks = push(chunks, slice); |
|
main(); |
|
if (chunks[chunks.length - 1] !== codes.eof) { |
|
return []; |
|
} |
|
addResult(initialize, 0); |
|
context.events = resolveAll(resolveAllConstructs, context.events, context); |
|
return context.events; |
|
} |
|
function sliceSerialize(token, expandTabs) { |
|
return serializeChunks(sliceStream(token), expandTabs); |
|
} |
|
function sliceStream(token) { |
|
return sliceChunks(chunks, token); |
|
} |
|
function now() { |
|
const { line: line2, column, offset, _index, _bufferIndex } = point3; |
|
return { line: line2, column, offset, _index, _bufferIndex }; |
|
} |
|
function defineSkip(value) { |
|
columnStart[value.line] = value.column; |
|
accountForPotentialSkip(); |
|
debug("position: define skip: `%j`", point3); |
|
} |
|
function main() { |
|
let chunkIndex; |
|
while (point3._index < chunks.length) { |
|
const chunk = chunks[point3._index]; |
|
if (typeof chunk === "string") { |
|
chunkIndex = point3._index; |
|
if (point3._bufferIndex < 0) { |
|
point3._bufferIndex = 0; |
|
} |
|
while (point3._index === chunkIndex && point3._bufferIndex < chunk.length) { |
|
go(chunk.charCodeAt(point3._bufferIndex)); |
|
} |
|
} else { |
|
go(chunk); |
|
} |
|
} |
|
} |
|
function go(code) { |
|
ok(consumed === true, "expected character to be consumed"); |
|
consumed = void 0; |
|
debug("main: passing `%s` to %s", code, state && state.name); |
|
expectedCode = code; |
|
ok(typeof state === "function", "expected state"); |
|
state = state(code); |
|
} |
|
function consume(code) { |
|
ok(code === expectedCode, "expected given code to equal expected code"); |
|
debug("consume: `%s`", code); |
|
ok( |
|
consumed === void 0, |
|
"expected code to not have been consumed: this might be because `return x(code)` instead of `return x` was used" |
|
); |
|
ok( |
|
code === null ? context.events.length === 0 || context.events[context.events.length - 1][0] === "exit" : context.events[context.events.length - 1][0] === "enter", |
|
"expected last token to be open" |
|
); |
|
if (markdownLineEnding(code)) { |
|
point3.line++; |
|
point3.column = 1; |
|
point3.offset += code === codes.carriageReturnLineFeed ? 2 : 1; |
|
accountForPotentialSkip(); |
|
debug("position: after eol: `%j`", point3); |
|
} else if (code !== codes.virtualSpace) { |
|
point3.column++; |
|
point3.offset++; |
|
} |
|
if (point3._bufferIndex < 0) { |
|
point3._index++; |
|
} else { |
|
point3._bufferIndex++; |
|
if (point3._bufferIndex === chunks[point3._index].length) { |
|
point3._bufferIndex = -1; |
|
point3._index++; |
|
} |
|
} |
|
context.previous = code; |
|
consumed = true; |
|
} |
|
function enter(type, fields) { |
|
const token = fields || {}; |
|
token.type = type; |
|
token.start = now(); |
|
ok(typeof type === "string", "expected string type"); |
|
ok(type.length > 0, "expected non-empty string"); |
|
debug("enter: `%s`", type); |
|
context.events.push(["enter", token, context]); |
|
stack.push(token); |
|
return token; |
|
} |
|
function exit2(type) { |
|
ok(typeof type === "string", "expected string type"); |
|
ok(type.length > 0, "expected non-empty string"); |
|
const token = stack.pop(); |
|
ok(token, "cannot close w/o open tokens"); |
|
token.end = now(); |
|
ok(type === token.type, "expected exit token to match current token"); |
|
ok( |
|
!(token.start._index === token.end._index && token.start._bufferIndex === token.end._bufferIndex), |
|
"expected non-empty token (`" + type + "`)" |
|
); |
|
debug("exit: `%s`", token.type); |
|
context.events.push(["exit", token, context]); |
|
return token; |
|
} |
|
function onsuccessfulconstruct(construct, info) { |
|
addResult(construct, info.from); |
|
} |
|
function onsuccessfulcheck(_, info) { |
|
info.restore(); |
|
} |
|
function constructFactory(onreturn, fields) { |
|
return hook; |
|
function hook(constructs2, returnState, bogusState) { |
|
let listOfConstructs; |
|
let constructIndex; |
|
let currentConstruct; |
|
let info; |
|
return Array.isArray(constructs2) ? ( |
|
|
|
handleListOfConstructs(constructs2) |
|
) : "tokenize" in constructs2 ? ( |
|
|
|
handleListOfConstructs([constructs2]) |
|
) : handleMapOfConstructs(constructs2); |
|
function handleMapOfConstructs(map) { |
|
return start; |
|
function start(code) { |
|
const def = code !== null && map[code]; |
|
const all2 = code !== null && map.null; |
|
const list2 = [ |
|
|
|
|
|
...Array.isArray(def) ? def : def ? [def] : [], |
|
...Array.isArray(all2) ? all2 : all2 ? [all2] : [] |
|
]; |
|
return handleListOfConstructs(list2)(code); |
|
} |
|
} |
|
function handleListOfConstructs(list2) { |
|
listOfConstructs = list2; |
|
constructIndex = 0; |
|
if (list2.length === 0) { |
|
ok(bogusState, "expected `bogusState` to be given"); |
|
return bogusState; |
|
} |
|
return handleConstruct(list2[constructIndex]); |
|
} |
|
function handleConstruct(construct) { |
|
return start; |
|
function start(code) { |
|
info = store(); |
|
currentConstruct = construct; |
|
if (!construct.partial) { |
|
context.currentConstruct = construct; |
|
} |
|
ok( |
|
context.parser.constructs.disable.null, |
|
"expected `disable.null` to be populated" |
|
); |
|
if (construct.name && context.parser.constructs.disable.null.includes(construct.name)) { |
|
return nok(code); |
|
} |
|
return construct.tokenize.call( |
|
|
|
|
|
|
|
fields ? Object.assign(Object.create(context), fields) : context, |
|
effects, |
|
ok2, |
|
nok |
|
)(code); |
|
} |
|
} |
|
function ok2(code) { |
|
ok(code === expectedCode, "expected code"); |
|
consumed = true; |
|
onreturn(currentConstruct, info); |
|
return returnState; |
|
} |
|
function nok(code) { |
|
ok(code === expectedCode, "expected code"); |
|
consumed = true; |
|
info.restore(); |
|
if (++constructIndex < listOfConstructs.length) { |
|
return handleConstruct(listOfConstructs[constructIndex]); |
|
} |
|
return bogusState; |
|
} |
|
} |
|
} |
|
function addResult(construct, from2) { |
|
if (construct.resolveAll && !resolveAllConstructs.includes(construct)) { |
|
resolveAllConstructs.push(construct); |
|
} |
|
if (construct.resolve) { |
|
splice( |
|
context.events, |
|
from2, |
|
context.events.length - from2, |
|
construct.resolve(context.events.slice(from2), context) |
|
); |
|
} |
|
if (construct.resolveTo) { |
|
context.events = construct.resolveTo(context.events, context); |
|
} |
|
ok( |
|
construct.partial || context.events.length === 0 || context.events[context.events.length - 1][0] === "exit", |
|
"expected last token to end" |
|
); |
|
} |
|
function store() { |
|
const startPoint = now(); |
|
const startPrevious = context.previous; |
|
const startCurrentConstruct = context.currentConstruct; |
|
const startEventsIndex = context.events.length; |
|
const startStack = Array.from(stack); |
|
return { restore, from: startEventsIndex }; |
|
function restore() { |
|
point3 = startPoint; |
|
context.previous = startPrevious; |
|
context.currentConstruct = startCurrentConstruct; |
|
context.events.length = startEventsIndex; |
|
stack = startStack; |
|
accountForPotentialSkip(); |
|
debug("position: restore: `%j`", point3); |
|
} |
|
} |
|
function accountForPotentialSkip() { |
|
if (point3.line in columnStart && point3.column < 2) { |
|
point3.column = columnStart[point3.line]; |
|
point3.offset += columnStart[point3.line] - 1; |
|
} |
|
} |
|
} |
|
function sliceChunks(chunks, token) { |
|
const startIndex = token.start._index; |
|
const startBufferIndex = token.start._bufferIndex; |
|
const endIndex = token.end._index; |
|
const endBufferIndex = token.end._bufferIndex; |
|
let view; |
|
if (startIndex === endIndex) { |
|
ok(endBufferIndex > -1, "expected non-negative end buffer index"); |
|
ok(startBufferIndex > -1, "expected non-negative start buffer index"); |
|
view = [chunks[startIndex].slice(startBufferIndex, endBufferIndex)]; |
|
} else { |
|
view = chunks.slice(startIndex, endIndex); |
|
if (startBufferIndex > -1) { |
|
const head = view[0]; |
|
if (typeof head === "string") { |
|
view[0] = head.slice(startBufferIndex); |
|
} else { |
|
ok(startBufferIndex === 0, "expected `startBufferIndex` to be `0`"); |
|
view.shift(); |
|
} |
|
} |
|
if (endBufferIndex > 0) { |
|
view.push(chunks[endIndex].slice(0, endBufferIndex)); |
|
} |
|
} |
|
return view; |
|
} |
|
function serializeChunks(chunks, expandTabs) { |
|
let index2 = -1; |
|
const result = []; |
|
let atTab; |
|
while (++index2 < chunks.length) { |
|
const chunk = chunks[index2]; |
|
let value; |
|
if (typeof chunk === "string") { |
|
value = chunk; |
|
} else |
|
switch (chunk) { |
|
case codes.carriageReturn: { |
|
value = values.cr; |
|
break; |
|
} |
|
case codes.lineFeed: { |
|
value = values.lf; |
|
break; |
|
} |
|
case codes.carriageReturnLineFeed: { |
|
value = values.cr + values.lf; |
|
break; |
|
} |
|
case codes.horizontalTab: { |
|
value = expandTabs ? values.space : values.ht; |
|
break; |
|
} |
|
case codes.virtualSpace: { |
|
if (!expandTabs && atTab) continue; |
|
value = values.space; |
|
break; |
|
} |
|
default: { |
|
ok(typeof chunk === "number", "expected number"); |
|
value = String.fromCharCode(chunk); |
|
} |
|
} |
|
atTab = chunk === codes.horizontalTab; |
|
result.push(value); |
|
} |
|
return result.join(""); |
|
} |
|
|
|
|
|
var constructs_exports = {}; |
|
__export(constructs_exports, { |
|
attentionMarkers: () => attentionMarkers, |
|
contentInitial: () => contentInitial, |
|
disable: () => disable, |
|
document: () => document3, |
|
flow: () => flow2, |
|
flowInitial: () => flowInitial, |
|
insideSpan: () => insideSpan, |
|
string: () => string2, |
|
text: () => text2 |
|
}); |
|
var document3 = { |
|
[codes.asterisk]: list, |
|
[codes.plusSign]: list, |
|
[codes.dash]: list, |
|
[codes.digit0]: list, |
|
[codes.digit1]: list, |
|
[codes.digit2]: list, |
|
[codes.digit3]: list, |
|
[codes.digit4]: list, |
|
[codes.digit5]: list, |
|
[codes.digit6]: list, |
|
[codes.digit7]: list, |
|
[codes.digit8]: list, |
|
[codes.digit9]: list, |
|
[codes.greaterThan]: blockQuote |
|
}; |
|
var contentInitial = { |
|
[codes.leftSquareBracket]: definition |
|
}; |
|
var flowInitial = { |
|
[codes.horizontalTab]: codeIndented, |
|
[codes.virtualSpace]: codeIndented, |
|
[codes.space]: codeIndented |
|
}; |
|
var flow2 = { |
|
[codes.numberSign]: headingAtx, |
|
[codes.asterisk]: thematicBreak, |
|
[codes.dash]: [setextUnderline, thematicBreak], |
|
[codes.lessThan]: htmlFlow, |
|
[codes.equalsTo]: setextUnderline, |
|
[codes.underscore]: thematicBreak, |
|
[codes.graveAccent]: codeFenced, |
|
[codes.tilde]: codeFenced |
|
}; |
|
var string2 = { |
|
[codes.ampersand]: characterReference, |
|
[codes.backslash]: characterEscape |
|
}; |
|
var text2 = { |
|
[codes.carriageReturn]: lineEnding, |
|
[codes.lineFeed]: lineEnding, |
|
[codes.carriageReturnLineFeed]: lineEnding, |
|
[codes.exclamationMark]: labelStartImage, |
|
[codes.ampersand]: characterReference, |
|
[codes.asterisk]: attention, |
|
[codes.lessThan]: [autolink, htmlText], |
|
[codes.leftSquareBracket]: labelStartLink, |
|
[codes.backslash]: [hardBreakEscape, characterEscape], |
|
[codes.rightSquareBracket]: labelEnd, |
|
[codes.underscore]: attention, |
|
[codes.graveAccent]: codeText |
|
}; |
|
var insideSpan = { null: [attention, resolver] }; |
|
var attentionMarkers = { null: [codes.asterisk, codes.underscore] }; |
|
var disable = { null: [] }; |
|
|
|
|
|
function parse(options) { |
|
const settings = options || {}; |
|
const constructs2 = ( |
|
|
|
combineExtensions([constructs_exports, ...settings.extensions || []]) |
|
); |
|
const parser = { |
|
defined: [], |
|
lazy: {}, |
|
constructs: constructs2, |
|
content: create(content), |
|
document: create(document2), |
|
flow: create(flow), |
|
string: create(string), |
|
text: create(text) |
|
}; |
|
return parser; |
|
function create(initial) { |
|
return creator; |
|
function creator(from) { |
|
return createTokenizer(parser, initial, from); |
|
} |
|
} |
|
} |
|
|
|
|
|
var search = /[\0\t\n\r]/g; |
|
function preprocess() { |
|
let column = 1; |
|
let buffer = ""; |
|
let start = true; |
|
let atCarriageReturn; |
|
return preprocessor; |
|
function preprocessor(value, encoding, end) { |
|
const chunks = []; |
|
let match; |
|
let next; |
|
let startPosition; |
|
let endPosition; |
|
let code; |
|
value = buffer + value.toString(encoding); |
|
startPosition = 0; |
|
buffer = ""; |
|
if (start) { |
|
if (value.charCodeAt(0) === codes.byteOrderMarker) { |
|
startPosition++; |
|
} |
|
start = void 0; |
|
} |
|
while (startPosition < value.length) { |
|
search.lastIndex = startPosition; |
|
match = search.exec(value); |
|
endPosition = match && match.index !== void 0 ? match.index : value.length; |
|
code = value.charCodeAt(endPosition); |
|
if (!match) { |
|
buffer = value.slice(startPosition); |
|
break; |
|
} |
|
if (code === codes.lf && startPosition === endPosition && atCarriageReturn) { |
|
chunks.push(codes.carriageReturnLineFeed); |
|
atCarriageReturn = void 0; |
|
} else { |
|
if (atCarriageReturn) { |
|
chunks.push(codes.carriageReturn); |
|
atCarriageReturn = void 0; |
|
} |
|
if (startPosition < endPosition) { |
|
chunks.push(value.slice(startPosition, endPosition)); |
|
column += endPosition - startPosition; |
|
} |
|
switch (code) { |
|
case codes.nul: { |
|
chunks.push(codes.replacementCharacter); |
|
column++; |
|
break; |
|
} |
|
case codes.ht: { |
|
next = Math.ceil(column / constants.tabSize) * constants.tabSize; |
|
chunks.push(codes.horizontalTab); |
|
while (column++ < next) chunks.push(codes.virtualSpace); |
|
break; |
|
} |
|
case codes.lf: { |
|
chunks.push(codes.lineFeed); |
|
column = 1; |
|
break; |
|
} |
|
default: { |
|
atCarriageReturn = true; |
|
column = 1; |
|
} |
|
} |
|
} |
|
startPosition = endPosition + 1; |
|
} |
|
if (end) { |
|
if (atCarriageReturn) chunks.push(codes.carriageReturn); |
|
if (buffer) chunks.push(buffer); |
|
chunks.push(codes.eof); |
|
} |
|
return chunks; |
|
} |
|
} |
|
|
|
|
|
function postprocess(events) { |
|
while (!subtokenize(events)) { |
|
} |
|
return events; |
|
} |
|
|
|
|
|
function decodeNumericCharacterReference(value, base) { |
|
const code = Number.parseInt(value, base); |
|
if ( |
|
|
|
code < codes.ht || code === codes.vt || code > codes.cr && code < codes.space || |
|
code > codes.tilde && code < 160 || |
|
code > 55295 && code < 57344 || |
|
code > 64975 && code < 65008 || |
|
(code & 65535) === 65535 || (code & 65535) === 65534 || |
|
|
|
code > 1114111 |
|
) { |
|
return values.replacementCharacter; |
|
} |
|
return String.fromCharCode(code); |
|
} |
|
|
|
|
|
var characterEscapeOrReference = /\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi; |
|
function decodeString(value) { |
|
return value.replace(characterEscapeOrReference, decode); |
|
} |
|
function decode($0, $1, $2) { |
|
if ($1) { |
|
return $1; |
|
} |
|
const head = $2.charCodeAt(0); |
|
if (head === codes.numberSign) { |
|
const head2 = $2.charCodeAt(1); |
|
const hex = head2 === codes.lowercaseX || head2 === codes.uppercaseX; |
|
return decodeNumericCharacterReference( |
|
$2.slice(hex ? 2 : 1), |
|
hex ? constants.numericBaseHexadecimal : constants.numericBaseDecimal |
|
); |
|
} |
|
return decodeNamedCharacterReference($2) || $0; |
|
} |
|
|
|
|
|
function stringifyPosition(value) { |
|
if (!value || typeof value !== "object") { |
|
return ""; |
|
} |
|
if ("position" in value || "type" in value) { |
|
return position(value.position); |
|
} |
|
if ("start" in value || "end" in value) { |
|
return position(value); |
|
} |
|
if ("line" in value || "column" in value) { |
|
return point(value); |
|
} |
|
return ""; |
|
} |
|
function point(point3) { |
|
return index(point3 && point3.line) + ":" + index(point3 && point3.column); |
|
} |
|
function position(pos) { |
|
return point(pos && pos.start) + "-" + point(pos && pos.end); |
|
} |
|
function index(value) { |
|
return value && typeof value === "number" ? value : 1; |
|
} |
|
|
|
|
|
var own = {}.hasOwnProperty; |
|
var fromMarkdown = ( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function(value, encoding, options) { |
|
if (typeof encoding !== "string") { |
|
options = encoding; |
|
encoding = void 0; |
|
} |
|
return compiler(options)( |
|
postprocess( |
|
parse(options).document().write(preprocess()(value, encoding, true)) |
|
) |
|
); |
|
} |
|
); |
|
function compiler(options) { |
|
const config = { |
|
transforms: [], |
|
canContainEols: ["emphasis", "fragment", "heading", "paragraph", "strong"], |
|
enter: { |
|
autolink: opener(link), |
|
autolinkProtocol: onenterdata, |
|
autolinkEmail: onenterdata, |
|
atxHeading: opener(heading), |
|
blockQuote: opener(blockQuote2), |
|
characterEscape: onenterdata, |
|
characterReference: onenterdata, |
|
codeFenced: opener(codeFlow), |
|
codeFencedFenceInfo: buffer, |
|
codeFencedFenceMeta: buffer, |
|
codeIndented: opener(codeFlow, buffer), |
|
codeText: opener(codeText2, buffer), |
|
codeTextData: onenterdata, |
|
data: onenterdata, |
|
codeFlowValue: onenterdata, |
|
definition: opener(definition2), |
|
definitionDestinationString: buffer, |
|
definitionLabelString: buffer, |
|
definitionTitleString: buffer, |
|
emphasis: opener(emphasis), |
|
hardBreakEscape: opener(hardBreak), |
|
hardBreakTrailing: opener(hardBreak), |
|
htmlFlow: opener(html, buffer), |
|
htmlFlowData: onenterdata, |
|
htmlText: opener(html, buffer), |
|
htmlTextData: onenterdata, |
|
image: opener(image), |
|
label: buffer, |
|
link: opener(link), |
|
listItem: opener(listItem), |
|
listItemValue: onenterlistitemvalue, |
|
listOrdered: opener(list2, onenterlistordered), |
|
listUnordered: opener(list2), |
|
paragraph: opener(paragraph), |
|
reference: onenterreference, |
|
referenceString: buffer, |
|
resourceDestinationString: buffer, |
|
resourceTitleString: buffer, |
|
setextHeading: opener(heading), |
|
strong: opener(strong), |
|
thematicBreak: opener(thematicBreak2) |
|
}, |
|
exit: { |
|
atxHeading: closer(), |
|
atxHeadingSequence: onexitatxheadingsequence, |
|
autolink: closer(), |
|
autolinkEmail: onexitautolinkemail, |
|
autolinkProtocol: onexitautolinkprotocol, |
|
blockQuote: closer(), |
|
characterEscapeValue: onexitdata, |
|
characterReferenceMarkerHexadecimal: onexitcharacterreferencemarker, |
|
characterReferenceMarkerNumeric: onexitcharacterreferencemarker, |
|
characterReferenceValue: onexitcharacterreferencevalue, |
|
codeFenced: closer(onexitcodefenced), |
|
codeFencedFence: onexitcodefencedfence, |
|
codeFencedFenceInfo: onexitcodefencedfenceinfo, |
|
codeFencedFenceMeta: onexitcodefencedfencemeta, |
|
codeFlowValue: onexitdata, |
|
codeIndented: closer(onexitcodeindented), |
|
codeText: closer(onexitcodetext), |
|
codeTextData: onexitdata, |
|
data: onexitdata, |
|
definition: closer(), |
|
definitionDestinationString: onexitdefinitiondestinationstring, |
|
definitionLabelString: onexitdefinitionlabelstring, |
|
definitionTitleString: onexitdefinitiontitlestring, |
|
emphasis: closer(), |
|
hardBreakEscape: closer(onexithardbreak), |
|
hardBreakTrailing: closer(onexithardbreak), |
|
htmlFlow: closer(onexithtmlflow), |
|
htmlFlowData: onexitdata, |
|
htmlText: closer(onexithtmltext), |
|
htmlTextData: onexitdata, |
|
image: closer(onexitimage), |
|
label: onexitlabel, |
|
labelText: onexitlabeltext, |
|
lineEnding: onexitlineending, |
|
link: closer(onexitlink), |
|
listItem: closer(), |
|
listOrdered: closer(), |
|
listUnordered: closer(), |
|
paragraph: closer(), |
|
referenceString: onexitreferencestring, |
|
resourceDestinationString: onexitresourcedestinationstring, |
|
resourceTitleString: onexitresourcetitlestring, |
|
resource: onexitresource, |
|
setextHeading: closer(onexitsetextheading), |
|
setextHeadingLineSequence: onexitsetextheadinglinesequence, |
|
setextHeadingText: onexitsetextheadingtext, |
|
strong: closer(), |
|
thematicBreak: closer() |
|
} |
|
}; |
|
configure(config, (options || {}).mdastExtensions || []); |
|
const data = {}; |
|
return compile; |
|
function compile(events) { |
|
let tree = { type: "root", children: [] }; |
|
const context = { |
|
stack: [tree], |
|
tokenStack: [], |
|
config, |
|
enter, |
|
exit: exit2, |
|
buffer, |
|
resume, |
|
setData, |
|
getData |
|
}; |
|
const listStack = []; |
|
let index2 = -1; |
|
while (++index2 < events.length) { |
|
if (events[index2][1].type === types.listOrdered || events[index2][1].type === types.listUnordered) { |
|
if (events[index2][0] === "enter") { |
|
listStack.push(index2); |
|
} else { |
|
const tail = listStack.pop(); |
|
ok(typeof tail === "number", "expected list ot be open"); |
|
index2 = prepareList(events, tail, index2); |
|
} |
|
} |
|
} |
|
index2 = -1; |
|
while (++index2 < events.length) { |
|
const handler = config[events[index2][0]]; |
|
if (own.call(handler, events[index2][1].type)) { |
|
handler[events[index2][1].type].call( |
|
Object.assign( |
|
{ sliceSerialize: events[index2][2].sliceSerialize }, |
|
context |
|
), |
|
events[index2][1] |
|
); |
|
} |
|
} |
|
if (context.tokenStack.length > 0) { |
|
const tail = context.tokenStack[context.tokenStack.length - 1]; |
|
const handler = tail[1] || defaultOnError; |
|
handler.call(context, void 0, tail[0]); |
|
} |
|
tree.position = { |
|
start: point2( |
|
events.length > 0 ? events[0][1].start : { line: 1, column: 1, offset: 0 } |
|
), |
|
end: point2( |
|
events.length > 0 ? events[events.length - 2][1].end : { line: 1, column: 1, offset: 0 } |
|
) |
|
}; |
|
index2 = -1; |
|
while (++index2 < config.transforms.length) { |
|
tree = config.transforms[index2](tree) || tree; |
|
} |
|
return tree; |
|
} |
|
function prepareList(events, start, length) { |
|
let index2 = start - 1; |
|
let containerBalance = -1; |
|
let listSpread = false; |
|
let listItem2; |
|
let lineIndex; |
|
let firstBlankLineIndex; |
|
let atMarker; |
|
while (++index2 <= length) { |
|
const event = events[index2]; |
|
if (event[1].type === types.listUnordered || event[1].type === types.listOrdered || event[1].type === types.blockQuote) { |
|
if (event[0] === "enter") { |
|
containerBalance++; |
|
} else { |
|
containerBalance--; |
|
} |
|
atMarker = void 0; |
|
} else if (event[1].type === types.lineEndingBlank) { |
|
if (event[0] === "enter") { |
|
if (listItem2 && !atMarker && !containerBalance && !firstBlankLineIndex) { |
|
firstBlankLineIndex = index2; |
|
} |
|
atMarker = void 0; |
|
} |
|
} else if (event[1].type === types.linePrefix || event[1].type === types.listItemValue || event[1].type === types.listItemMarker || event[1].type === types.listItemPrefix || event[1].type === types.listItemPrefixWhitespace) { |
|
} else { |
|
atMarker = void 0; |
|
} |
|
if (!containerBalance && event[0] === "enter" && event[1].type === types.listItemPrefix || containerBalance === -1 && event[0] === "exit" && (event[1].type === types.listUnordered || event[1].type === types.listOrdered)) { |
|
if (listItem2) { |
|
let tailIndex = index2; |
|
lineIndex = void 0; |
|
while (tailIndex--) { |
|
const tailEvent = events[tailIndex]; |
|
if (tailEvent[1].type === types.lineEnding || tailEvent[1].type === types.lineEndingBlank) { |
|
if (tailEvent[0] === "exit") continue; |
|
if (lineIndex) { |
|
events[lineIndex][1].type = types.lineEndingBlank; |
|
listSpread = true; |
|
} |
|
tailEvent[1].type = types.lineEnding; |
|
lineIndex = tailIndex; |
|
} else if (tailEvent[1].type === types.linePrefix || tailEvent[1].type === types.blockQuotePrefix || tailEvent[1].type === types.blockQuotePrefixWhitespace || tailEvent[1].type === types.blockQuoteMarker || tailEvent[1].type === types.listItemIndent) { |
|
} else { |
|
break; |
|
} |
|
} |
|
if (firstBlankLineIndex && (!lineIndex || firstBlankLineIndex < lineIndex)) { |
|
listItem2._spread = true; |
|
} |
|
listItem2.end = Object.assign( |
|
{}, |
|
lineIndex ? events[lineIndex][1].start : event[1].end |
|
); |
|
events.splice(lineIndex || index2, 0, ["exit", listItem2, event[2]]); |
|
index2++; |
|
length++; |
|
} |
|
if (event[1].type === types.listItemPrefix) { |
|
listItem2 = { |
|
type: "listItem", |
|
_spread: false, |
|
start: Object.assign({}, event[1].start), |
|
|
|
end: void 0 |
|
}; |
|
events.splice(index2, 0, ["enter", listItem2, event[2]]); |
|
index2++; |
|
length++; |
|
firstBlankLineIndex = void 0; |
|
atMarker = true; |
|
} |
|
} |
|
} |
|
events[start][1]._spread = listSpread; |
|
return length; |
|
} |
|
function setData(key, value) { |
|
data[key] = value; |
|
} |
|
function getData(key) { |
|
return data[key]; |
|
} |
|
function opener(create, and) { |
|
return open; |
|
function open(token) { |
|
enter.call(this, create(token), token); |
|
if (and) and.call(this, token); |
|
} |
|
} |
|
function buffer() { |
|
this.stack.push({ type: "fragment", children: [] }); |
|
} |
|
function enter(node2, token, errorHandler) { |
|
const parent = this.stack[this.stack.length - 1]; |
|
ok(parent, "expected `parent`"); |
|
ok("children" in parent, "expected `parent`"); |
|
parent.children.push(node2); |
|
this.stack.push(node2); |
|
this.tokenStack.push([token, errorHandler]); |
|
node2.position = { start: point2(token.start) }; |
|
return node2; |
|
} |
|
function closer(and) { |
|
return close; |
|
function close(token) { |
|
if (and) and.call(this, token); |
|
exit2.call(this, token); |
|
} |
|
} |
|
function exit2(token, onExitError) { |
|
const node2 = this.stack.pop(); |
|
ok(node2, "expected `node`"); |
|
const open = this.tokenStack.pop(); |
|
if (!open) { |
|
throw new Error( |
|
"Cannot close `" + token.type + "` (" + stringifyPosition({ start: token.start, end: token.end }) + "): it’s not open" |
|
); |
|
} else if (open[0].type !== token.type) { |
|
if (onExitError) { |
|
onExitError.call(this, token, open[0]); |
|
} else { |
|
const handler = open[1] || defaultOnError; |
|
handler.call(this, token, open[0]); |
|
} |
|
} |
|
ok(node2.type !== "fragment", "unexpected fragment `exit`ed"); |
|
ok(node2.position, "expected `position` to be defined"); |
|
node2.position.end = point2(token.end); |
|
return node2; |
|
} |
|
function resume() { |
|
return toString(this.stack.pop()); |
|
} |
|
function onenterlistordered() { |
|
setData("expectingFirstListItemValue", true); |
|
} |
|
function onenterlistitemvalue(token) { |
|
if (getData("expectingFirstListItemValue")) { |
|
const ancestor = this.stack[this.stack.length - 2]; |
|
ok(ancestor, "expected nodes on stack"); |
|
ok(ancestor.type === "list", "expected list on stack"); |
|
ancestor.start = Number.parseInt( |
|
this.sliceSerialize(token), |
|
constants.numericBaseDecimal |
|
); |
|
setData("expectingFirstListItemValue"); |
|
} |
|
} |
|
function onexitcodefencedfenceinfo() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "code", "expected code on stack"); |
|
node2.lang = data2; |
|
} |
|
function onexitcodefencedfencemeta() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "code", "expected code on stack"); |
|
node2.meta = data2; |
|
} |
|
function onexitcodefencedfence() { |
|
if (getData("flowCodeInside")) return; |
|
this.buffer(); |
|
setData("flowCodeInside", true); |
|
} |
|
function onexitcodefenced() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "code", "expected code on stack"); |
|
node2.value = data2.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g, ""); |
|
setData("flowCodeInside"); |
|
} |
|
function onexitcodeindented() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "code", "expected code on stack"); |
|
node2.value = data2.replace(/(\r?\n|\r)$/g, ""); |
|
} |
|
function onexitdefinitionlabelstring(token) { |
|
const label = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "definition", "expected definition on stack"); |
|
node2.label = label; |
|
node2.identifier = normalizeIdentifier( |
|
this.sliceSerialize(token) |
|
).toLowerCase(); |
|
} |
|
function onexitdefinitiontitlestring() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "definition", "expected definition on stack"); |
|
node2.title = data2; |
|
} |
|
function onexitdefinitiondestinationstring() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "definition", "expected definition on stack"); |
|
node2.url = data2; |
|
} |
|
function onexitatxheadingsequence(token) { |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "heading", "expected heading on stack"); |
|
if (!node2.depth) { |
|
const depth = this.sliceSerialize(token).length; |
|
ok( |
|
depth === 1 || depth === 2 || depth === 3 || depth === 4 || depth === 5 || depth === 6, |
|
"expected `depth` between `1` and `6`" |
|
); |
|
node2.depth = depth; |
|
} |
|
} |
|
function onexitsetextheadingtext() { |
|
setData("setextHeadingSlurpLineEnding", true); |
|
} |
|
function onexitsetextheadinglinesequence(token) { |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "heading", "expected heading on stack"); |
|
node2.depth = this.sliceSerialize(token).charCodeAt(0) === codes.equalsTo ? 1 : 2; |
|
} |
|
function onexitsetextheading() { |
|
setData("setextHeadingSlurpLineEnding"); |
|
} |
|
function onenterdata(token) { |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok("children" in node2, "expected parent on stack"); |
|
let tail = node2.children[node2.children.length - 1]; |
|
if (!tail || tail.type !== "text") { |
|
tail = text3(); |
|
tail.position = { start: point2(token.start) }; |
|
node2.children.push(tail); |
|
} |
|
this.stack.push(tail); |
|
} |
|
function onexitdata(token) { |
|
const tail = this.stack.pop(); |
|
ok(tail, "expected a `node` to be on the stack"); |
|
ok("value" in tail, "expected a `literal` to be on the stack"); |
|
ok(tail.position, "expected `node` to have an open position"); |
|
tail.value += this.sliceSerialize(token); |
|
tail.position.end = point2(token.end); |
|
} |
|
function onexitlineending(token) { |
|
const context = this.stack[this.stack.length - 1]; |
|
ok(context, "expected `node`"); |
|
if (getData("atHardBreak")) { |
|
ok("children" in context, "expected `parent`"); |
|
const tail = context.children[context.children.length - 1]; |
|
ok(tail.position, "expected tail to have a starting position"); |
|
tail.position.end = point2(token.end); |
|
setData("atHardBreak"); |
|
return; |
|
} |
|
if (!getData("setextHeadingSlurpLineEnding") && config.canContainEols.includes(context.type)) { |
|
onenterdata.call(this, token); |
|
onexitdata.call(this, token); |
|
} |
|
} |
|
function onexithardbreak() { |
|
setData("atHardBreak", true); |
|
} |
|
function onexithtmlflow() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "html", "expected html on stack"); |
|
node2.value = data2; |
|
} |
|
function onexithtmltext() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "html", "expected html on stack"); |
|
node2.value = data2; |
|
} |
|
function onexitcodetext() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "inlineCode", "expected inline code on stack"); |
|
node2.value = data2; |
|
} |
|
function onexitlink() { |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "link", "expected link on stack"); |
|
if (getData("inReference")) { |
|
const referenceType = getData("referenceType") || "shortcut"; |
|
node2.type += "Reference"; |
|
node2.referenceType = referenceType; |
|
delete node2.url; |
|
delete node2.title; |
|
} else { |
|
delete node2.identifier; |
|
delete node2.label; |
|
} |
|
setData("referenceType"); |
|
} |
|
function onexitimage() { |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "image", "expected image on stack"); |
|
if (getData("inReference")) { |
|
const referenceType = getData("referenceType") || "shortcut"; |
|
node2.type += "Reference"; |
|
node2.referenceType = referenceType; |
|
delete node2.url; |
|
delete node2.title; |
|
} else { |
|
delete node2.identifier; |
|
delete node2.label; |
|
} |
|
setData("referenceType"); |
|
} |
|
function onexitlabeltext(token) { |
|
const string3 = this.sliceSerialize(token); |
|
const ancestor = this.stack[this.stack.length - 2]; |
|
ok(ancestor, "expected ancestor on stack"); |
|
ok( |
|
ancestor.type === "image" || ancestor.type === "link", |
|
"expected image or link on stack" |
|
); |
|
ancestor.label = decodeString(string3); |
|
ancestor.identifier = normalizeIdentifier(string3).toLowerCase(); |
|
} |
|
function onexitlabel() { |
|
const fragment = this.stack[this.stack.length - 1]; |
|
ok(fragment, "expected node on stack"); |
|
ok(fragment.type === "fragment", "expected fragment on stack"); |
|
const value = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok( |
|
node2.type === "image" || node2.type === "link", |
|
"expected image or link on stack" |
|
); |
|
setData("inReference", true); |
|
if (node2.type === "link") { |
|
const children = fragment.children; |
|
node2.children = children; |
|
} else { |
|
node2.alt = value; |
|
} |
|
} |
|
function onexitresourcedestinationstring() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok( |
|
node2.type === "image" || node2.type === "link", |
|
"expected image or link on stack" |
|
); |
|
node2.url = data2; |
|
} |
|
function onexitresourcetitlestring() { |
|
const data2 = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok( |
|
node2.type === "image" || node2.type === "link", |
|
"expected image or link on stack" |
|
); |
|
node2.title = data2; |
|
} |
|
function onexitresource() { |
|
setData("inReference"); |
|
} |
|
function onenterreference() { |
|
setData("referenceType", "collapsed"); |
|
} |
|
function onexitreferencestring(token) { |
|
const label = this.resume(); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok( |
|
node2.type === "image" || node2.type === "link", |
|
"expected image reference or link reference on stack" |
|
); |
|
node2.label = label; |
|
node2.identifier = normalizeIdentifier( |
|
this.sliceSerialize(token) |
|
).toLowerCase(); |
|
setData("referenceType", "full"); |
|
} |
|
function onexitcharacterreferencemarker(token) { |
|
ok( |
|
token.type === "characterReferenceMarkerNumeric" || token.type === "characterReferenceMarkerHexadecimal" |
|
); |
|
setData("characterReferenceType", token.type); |
|
} |
|
function onexitcharacterreferencevalue(token) { |
|
const data2 = this.sliceSerialize(token); |
|
const type = getData("characterReferenceType"); |
|
let value; |
|
if (type) { |
|
value = decodeNumericCharacterReference( |
|
data2, |
|
type === types.characterReferenceMarkerNumeric ? constants.numericBaseDecimal : constants.numericBaseHexadecimal |
|
); |
|
setData("characterReferenceType"); |
|
} else { |
|
const result = decodeNamedCharacterReference(data2); |
|
ok(result !== false, "expected reference to decode"); |
|
value = result; |
|
} |
|
const tail = this.stack.pop(); |
|
ok(tail, "expected `node`"); |
|
ok(tail.position, "expected `node.position`"); |
|
ok("value" in tail, "expected `node.value`"); |
|
tail.value += value; |
|
tail.position.end = point2(token.end); |
|
} |
|
function onexitautolinkprotocol(token) { |
|
onexitdata.call(this, token); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "link", "expected link on stack"); |
|
node2.url = this.sliceSerialize(token); |
|
} |
|
function onexitautolinkemail(token) { |
|
onexitdata.call(this, token); |
|
const node2 = this.stack[this.stack.length - 1]; |
|
ok(node2, "expected node on stack"); |
|
ok(node2.type === "link", "expected link on stack"); |
|
node2.url = "mailto:" + this.sliceSerialize(token); |
|
} |
|
function blockQuote2() { |
|
return { type: "blockquote", children: [] }; |
|
} |
|
function codeFlow() { |
|
return { type: "code", lang: null, meta: null, value: "" }; |
|
} |
|
function codeText2() { |
|
return { type: "inlineCode", value: "" }; |
|
} |
|
function definition2() { |
|
return { |
|
type: "definition", |
|
identifier: "", |
|
label: null, |
|
title: null, |
|
url: "" |
|
}; |
|
} |
|
function emphasis() { |
|
return { type: "emphasis", children: [] }; |
|
} |
|
function heading() { |
|
return { type: "heading", depth: void 0, children: [] }; |
|
} |
|
function hardBreak() { |
|
return { type: "break" }; |
|
} |
|
function html() { |
|
return { type: "html", value: "" }; |
|
} |
|
function image() { |
|
return { type: "image", title: null, url: "", alt: null }; |
|
} |
|
function link() { |
|
return { type: "link", title: null, url: "", children: [] }; |
|
} |
|
function list2(token) { |
|
return { |
|
type: "list", |
|
ordered: token.type === "listOrdered", |
|
start: null, |
|
spread: token._spread, |
|
children: [] |
|
}; |
|
} |
|
function listItem(token) { |
|
return { |
|
type: "listItem", |
|
spread: token._spread, |
|
checked: null, |
|
children: [] |
|
}; |
|
} |
|
function paragraph() { |
|
return { type: "paragraph", children: [] }; |
|
} |
|
function strong() { |
|
return { type: "strong", children: [] }; |
|
} |
|
function text3() { |
|
return { type: "text", value: "" }; |
|
} |
|
function thematicBreak2() { |
|
return { type: "thematicBreak" }; |
|
} |
|
} |
|
function point2(d) { |
|
return { line: d.line, column: d.column, offset: d.offset }; |
|
} |
|
function configure(combined, extensions) { |
|
let index2 = -1; |
|
while (++index2 < extensions.length) { |
|
const value = extensions[index2]; |
|
if (Array.isArray(value)) { |
|
configure(combined, value); |
|
} else { |
|
extension(combined, value); |
|
} |
|
} |
|
} |
|
function extension(combined, extension2) { |
|
let key; |
|
for (key in extension2) { |
|
if (own.call(extension2, key)) { |
|
if (key === "canContainEols") { |
|
const right = extension2[key]; |
|
if (right) { |
|
combined[key].push(...right); |
|
} |
|
} else if (key === "transforms") { |
|
const right = extension2[key]; |
|
if (right) { |
|
combined[key].push(...right); |
|
} |
|
} else if (key === "enter" || key === "exit") { |
|
const right = extension2[key]; |
|
if (right) { |
|
Object.assign(combined[key], right); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
function defaultOnError(left, right) { |
|
if (left) { |
|
throw new Error( |
|
"Cannot close `" + left.type + "` (" + stringifyPosition({ start: left.start, end: left.end }) + "): a different token (`" + right.type + "`, " + stringifyPosition({ start: right.start, end: right.end }) + ") is open" |
|
); |
|
} else { |
|
throw new Error( |
|
"Cannot close document, a token (`" + right.type + "`, " + stringifyPosition({ start: right.start, end: right.end }) + ") is still open" |
|
); |
|
} |
|
} |
|
|
|
|
|
function preprocessMarkdown(markdown) { |
|
const withoutMultipleNewlines = markdown.replace(/\n{2,}/g, "\n"); |
|
const withoutExtraSpaces = dedent(withoutMultipleNewlines); |
|
return withoutExtraSpaces; |
|
} |
|
function markdownToLines(markdown) { |
|
const preprocessedMarkdown = preprocessMarkdown(markdown); |
|
const { children } = fromMarkdown(preprocessedMarkdown); |
|
const lines2 = [[]]; |
|
let currentLine = 0; |
|
function processNode(node2, parentType = "normal") { |
|
if (node2.type === "text") { |
|
const textLines = node2.value.split("\n"); |
|
textLines.forEach((textLine, index2) => { |
|
if (index2 !== 0) { |
|
currentLine++; |
|
lines2.push([]); |
|
} |
|
textLine.split(" ").forEach((word) => { |
|
if (word) { |
|
lines2[currentLine].push({ content: word, type: parentType }); |
|
} |
|
}); |
|
}); |
|
} else if (node2.type === "strong" || node2.type === "emphasis") { |
|
node2.children.forEach((contentNode) => { |
|
processNode(contentNode, node2.type); |
|
}); |
|
} |
|
} |
|
children.forEach((treeNode) => { |
|
if (treeNode.type === "paragraph") { |
|
treeNode.children.forEach((contentNode) => { |
|
processNode(contentNode); |
|
}); |
|
} |
|
}); |
|
return lines2; |
|
} |
|
function markdownToHTML(markdown) { |
|
const { children } = fromMarkdown(markdown); |
|
function output(node2) { |
|
if (node2.type === "text") { |
|
return node2.value.replace(/\n/g, "<br/>"); |
|
} else if (node2.type === "strong") { |
|
return `<strong>${node2.children.map(output).join("")}</strong>`; |
|
} else if (node2.type === "emphasis") { |
|
return `<em>${node2.children.map(output).join("")}</em>`; |
|
} else if (node2.type === "paragraph") { |
|
return `<p>${node2.children.map(output).join("")}</p>`; |
|
} |
|
return `Unsupported markdown: ${node2.type}`; |
|
} |
|
return children.map(output).join(""); |
|
} |
|
function splitTextToChars(text3) { |
|
if (Intl.Segmenter) { |
|
return [...new Intl.Segmenter().segment(text3)].map((s) => s.segment); |
|
} |
|
return [...text3]; |
|
} |
|
function splitWordToFitWidth(checkFit, word) { |
|
const characters = splitTextToChars(word.content); |
|
return splitWordToFitWidthRecursion(checkFit, [], characters, word.type); |
|
} |
|
function splitWordToFitWidthRecursion(checkFit, usedChars, remainingChars, type) { |
|
if (remainingChars.length === 0) { |
|
return [ |
|
{ content: usedChars.join(""), type }, |
|
{ content: "", type } |
|
]; |
|
} |
|
const [nextChar, ...rest] = remainingChars; |
|
const newWord = [...usedChars, nextChar]; |
|
if (checkFit([{ content: newWord.join(""), type }])) { |
|
return splitWordToFitWidthRecursion(checkFit, newWord, rest, type); |
|
} |
|
if (usedChars.length === 0 && nextChar) { |
|
usedChars.push(nextChar); |
|
remainingChars.shift(); |
|
} |
|
return [ |
|
{ content: usedChars.join(""), type }, |
|
{ content: remainingChars.join(""), type } |
|
]; |
|
} |
|
function splitLineToFitWidth(line2, checkFit) { |
|
if (line2.some(({ content: content3 }) => content3.includes("\n"))) { |
|
throw new Error("splitLineToFitWidth does not support newlines in the line"); |
|
} |
|
return splitLineToFitWidthRecursion(line2, checkFit); |
|
} |
|
function splitLineToFitWidthRecursion(words, checkFit, lines2 = [], newLine = []) { |
|
if (words.length === 0) { |
|
if (newLine.length > 0) { |
|
lines2.push(newLine); |
|
} |
|
return lines2.length > 0 ? lines2 : []; |
|
} |
|
let joiner = ""; |
|
if (words[0].content === " ") { |
|
joiner = " "; |
|
words.shift(); |
|
} |
|
const nextWord = words.shift() ?? { content: " ", type: "normal" }; |
|
const lineWithNextWord = [...newLine]; |
|
if (joiner !== "") { |
|
lineWithNextWord.push({ content: joiner, type: "normal" }); |
|
} |
|
lineWithNextWord.push(nextWord); |
|
if (checkFit(lineWithNextWord)) { |
|
return splitLineToFitWidthRecursion(words, checkFit, lines2, lineWithNextWord); |
|
} |
|
if (newLine.length > 0) { |
|
lines2.push(newLine); |
|
words.unshift(nextWord); |
|
} else if (nextWord.content) { |
|
const [line2, rest] = splitWordToFitWidth(checkFit, nextWord); |
|
lines2.push([line2]); |
|
if (rest.content) { |
|
words.unshift(rest); |
|
} |
|
} |
|
return splitLineToFitWidthRecursion(words, checkFit, lines2); |
|
} |
|
function applyStyle(dom, styleFn) { |
|
if (styleFn) { |
|
dom.attr("style", styleFn); |
|
} |
|
} |
|
function addHtmlSpan(element2, node2, width, classes, addBackground = false) { |
|
const fo = element2.append("foreignObject"); |
|
const div = fo.append("xhtml:div"); |
|
const label = node2.label; |
|
const labelClass = node2.isNode ? "nodeLabel" : "edgeLabel"; |
|
div.html( |
|
` |
|
<span class="${labelClass} ${classes}" ` + (node2.labelStyle ? 'style="' + node2.labelStyle + '"' : "") + ">" + label + "</span>" |
|
); |
|
applyStyle(div, node2.labelStyle); |
|
div.style("display", "table-cell"); |
|
div.style("white-space", "nowrap"); |
|
div.style("max-width", width + "px"); |
|
div.attr("xmlns", "http://www.w3.org/1999/xhtml"); |
|
if (addBackground) { |
|
div.attr("class", "labelBkg"); |
|
} |
|
let bbox = div.node().getBoundingClientRect(); |
|
if (bbox.width === width) { |
|
div.style("display", "table"); |
|
div.style("white-space", "break-spaces"); |
|
div.style("width", width + "px"); |
|
bbox = div.node().getBoundingClientRect(); |
|
} |
|
fo.style("width", bbox.width); |
|
fo.style("height", bbox.height); |
|
return fo.node(); |
|
} |
|
function createTspan(textElement, lineIndex, lineHeight) { |
|
return textElement.append("tspan").attr("class", "text-outer-tspan").attr("x", 0).attr("y", lineIndex * lineHeight - 0.1 + "em").attr("dy", lineHeight + "em"); |
|
} |
|
function computeWidthOfText(parentNode, lineHeight, line2) { |
|
const testElement = parentNode.append("text"); |
|
const testSpan = createTspan(testElement, 1, lineHeight); |
|
updateTextContentAndStyles(testSpan, line2); |
|
const textLength = testSpan.node().getComputedTextLength(); |
|
testElement.remove(); |
|
return textLength; |
|
} |
|
function computeDimensionOfText(parentNode, lineHeight, text3) { |
|
var _a; |
|
const testElement = parentNode.append("text"); |
|
const testSpan = createTspan(testElement, 1, lineHeight); |
|
updateTextContentAndStyles(testSpan, [{ content: text3, type: "normal" }]); |
|
const textDimension = (_a = testSpan.node()) == null ? void 0 : _a.getBoundingClientRect(); |
|
if (textDimension) { |
|
testElement.remove(); |
|
} |
|
return textDimension; |
|
} |
|
function createFormattedText(width, g, structuredText, addBackground = false) { |
|
const lineHeight = 1.1; |
|
const labelGroup = g.append("g"); |
|
const bkg = labelGroup.insert("rect").attr("class", "background"); |
|
const textElement = labelGroup.append("text").attr("y", "-10.1"); |
|
let lineIndex = 0; |
|
for (const line2 of structuredText) { |
|
const checkWidth = (line22) => computeWidthOfText(labelGroup, lineHeight, line22) <= width; |
|
const linesUnderWidth = checkWidth(line2) ? [line2] : splitLineToFitWidth(line2, checkWidth); |
|
for (const preparedLine of linesUnderWidth) { |
|
const tspan = createTspan(textElement, lineIndex, lineHeight); |
|
updateTextContentAndStyles(tspan, preparedLine); |
|
lineIndex++; |
|
} |
|
} |
|
if (addBackground) { |
|
const bbox = textElement.node().getBBox(); |
|
const padding = 2; |
|
bkg.attr("x", -padding).attr("y", -padding).attr("width", bbox.width + 2 * padding).attr("height", bbox.height + 2 * padding); |
|
return labelGroup.node(); |
|
} else { |
|
return textElement.node(); |
|
} |
|
} |
|
function updateTextContentAndStyles(tspan, wrappedLine) { |
|
tspan.text(""); |
|
wrappedLine.forEach((word, index2) => { |
|
const innerTspan = tspan.append("tspan").attr("font-style", word.type === "emphasis" ? "italic" : "normal").attr("class", "text-inner-tspan").attr("font-weight", word.type === "strong" ? "bold" : "normal"); |
|
if (index2 === 0) { |
|
innerTspan.text(word.content); |
|
} else { |
|
innerTspan.text(" " + word.content); |
|
} |
|
}); |
|
} |
|
var createText = (el, text3 = "", { |
|
style = "", |
|
isTitle = false, |
|
classes = "", |
|
useHtmlLabels = true, |
|
isNode = true, |
|
width = 200, |
|
addSvgBackground = false |
|
} = {}) => { |
|
log$1.info("createText", text3, style, isTitle, classes, useHtmlLabels, isNode, addSvgBackground); |
|
if (useHtmlLabels) { |
|
const htmlText2 = markdownToHTML(text3); |
|
const node2 = { |
|
isNode, |
|
label: decodeEntities(htmlText2).replace( |
|
/fa[blrs]?:fa-[\w-]+/g, |
|
|
|
(s) => `<i class='${s.replace(":", " ")}'></i>` |
|
), |
|
labelStyle: style.replace("fill:", "color:") |
|
}; |
|
const vertexNode = addHtmlSpan(el, node2, width, classes, addSvgBackground); |
|
return vertexNode; |
|
} else { |
|
const structuredText = markdownToLines(text3); |
|
const svgLabel = createFormattedText(width, el, structuredText, addSvgBackground); |
|
return svgLabel; |
|
} |
|
}; |
|
|
|
export { |
|
computeDimensionOfText, |
|
createText |
|
}; |
|
|
|
|