artalk 2.5.2 → 2.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Artalk.es.js CHANGED
@@ -540,6 +540,7 @@ function getDefaults() {
540
540
  headerIds: true,
541
541
  headerPrefix: "",
542
542
  highlight: null,
543
+ hooks: null,
543
544
  langPrefix: "language-",
544
545
  mangle: true,
545
546
  pedantic: false,
@@ -664,18 +665,6 @@ function resolveUrl(base, href) {
664
665
  }
665
666
  const noopTest = { exec: function noopTest2() {
666
667
  } };
667
- function merge(obj) {
668
- let i = 1, target, key;
669
- for (; i < arguments.length; i++) {
670
- target = arguments[i];
671
- for (key in target) {
672
- if (Object.prototype.hasOwnProperty.call(target, key)) {
673
- obj[key] = target[key];
674
- }
675
- }
676
- }
677
- return obj;
678
- }
679
668
  function splitCells(tableRow, count) {
680
669
  const row = tableRow.replace(/\|/g, (match, offset, str) => {
681
670
  let escaped = false, curr = offset;
@@ -1410,7 +1399,7 @@ class Tokenizer {
1410
1399
  const block = {
1411
1400
  newline: /^(?: *(?:\n|$))+/,
1412
1401
  code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
1413
- fences: /^ {0,3}(`{3,}(?=[^`\n]*\n)|~{3,})([^\n]*)\n(?:|([\s\S]*?)\n)(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1402
+ fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
1414
1403
  hr: /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,
1415
1404
  heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
1416
1405
  blockquote: /^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/,
@@ -1435,14 +1424,14 @@ block._comment = /<!--(?!-?>)[\s\S]*?(?:-->|$)/;
1435
1424
  block.html = edit$1(block.html, "i").replace("comment", block._comment).replace("tag", block._tag).replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex();
1436
1425
  block.paragraph = edit$1(block._paragraph).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("|table", "").replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
1437
1426
  block.blockquote = edit$1(block.blockquote).replace("paragraph", block.paragraph).getRegex();
1438
- block.normal = merge({}, block);
1439
- block.gfm = merge({}, block.normal, {
1427
+ block.normal = __spreadValues({}, block);
1428
+ block.gfm = __spreadProps(__spreadValues({}, block.normal), {
1440
1429
  table: "^ *([^\\n ].*\\|.*)\\n {0,3}(?:\\| *)?(:?-+:? *(?:\\| *:?-+:? *)*)(?:\\| *)?(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)"
1441
1430
  // Cells
1442
1431
  });
1443
1432
  block.gfm.table = edit$1(block.gfm.table).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("blockquote", " {0,3}>").replace("code", " {4}[^\\n]").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
1444
1433
  block.gfm.paragraph = edit$1(block._paragraph).replace("hr", block.hr).replace("heading", " {0,3}#{1,6} ").replace("|lheading", "").replace("table", block.gfm.table).replace("blockquote", " {0,3}>").replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list", " {0,3}(?:[*+-]|1[.)]) ").replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag", block._tag).getRegex();
1445
- block.pedantic = merge({}, block.normal, {
1434
+ block.pedantic = __spreadProps(__spreadValues({}, block.normal), {
1446
1435
  html: edit$1(
1447
1436
  `^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`
1448
1437
  ).replace("comment", block._comment).replace(/tag/g, "(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),
@@ -1498,8 +1487,8 @@ inline.link = edit$1(inline.link).replace("label", inline._label).replace("href"
1498
1487
  inline.reflink = edit$1(inline.reflink).replace("label", inline._label).replace("ref", block._label).getRegex();
1499
1488
  inline.nolink = edit$1(inline.nolink).replace("ref", block._label).getRegex();
1500
1489
  inline.reflinkSearch = edit$1(inline.reflinkSearch, "g").replace("reflink", inline.reflink).replace("nolink", inline.nolink).getRegex();
1501
- inline.normal = merge({}, inline);
1502
- inline.pedantic = merge({}, inline.normal, {
1490
+ inline.normal = __spreadValues({}, inline);
1491
+ inline.pedantic = __spreadProps(__spreadValues({}, inline.normal), {
1503
1492
  strong: {
1504
1493
  start: /^__|\*\*/,
1505
1494
  middle: /^__(?=\S)([\s\S]*?\S)__(?!_)|^\*\*(?=\S)([\s\S]*?\S)\*\*(?!\*)/,
@@ -1515,7 +1504,7 @@ inline.pedantic = merge({}, inline.normal, {
1515
1504
  link: edit$1(/^!?\[(label)\]\((.*?)\)/).replace("label", inline._label).getRegex(),
1516
1505
  reflink: edit$1(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label", inline._label).getRegex()
1517
1506
  });
1518
- inline.gfm = merge({}, inline.normal, {
1507
+ inline.gfm = __spreadProps(__spreadValues({}, inline.normal), {
1519
1508
  escape: edit$1(inline.escape).replace("])", "~|])").getRegex(),
1520
1509
  _extended_email: /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/,
1521
1510
  url: /^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,
@@ -1524,7 +1513,7 @@ inline.gfm = merge({}, inline.normal, {
1524
1513
  text: /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/
1525
1514
  });
1526
1515
  inline.gfm.url = edit$1(inline.gfm.url, "i").replace("email", inline.gfm._extended_email).getRegex();
1527
- inline.breaks = merge({}, inline.gfm, {
1516
+ inline.breaks = __spreadProps(__spreadValues({}, inline.gfm), {
1528
1517
  br: edit$1(inline.br).replace("{2,}", "*").getRegex(),
1529
1518
  text: edit$1(inline.gfm.text).replace("\\b_", "\\b_| {2,}\\n").replace(/\{2,\}/g, "*").getRegex()
1530
1519
  });
@@ -2375,98 +2364,157 @@ class Parser {
2375
2364
  return out;
2376
2365
  }
2377
2366
  }
2378
- function marked$1(src, opt, callback) {
2379
- if (typeof src === "undefined" || src === null) {
2380
- throw new Error("marked(): input parameter is undefined or null");
2367
+ class Hooks {
2368
+ constructor(options) {
2369
+ this.options = options || defaults$3;
2381
2370
  }
2382
- if (typeof src !== "string") {
2383
- throw new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected");
2371
+ /**
2372
+ * Process markdown before marked
2373
+ */
2374
+ preprocess(markdown) {
2375
+ return markdown;
2384
2376
  }
2385
- if (typeof opt === "function") {
2386
- callback = opt;
2387
- opt = null;
2377
+ /**
2378
+ * Process HTML after marked is finished
2379
+ */
2380
+ postprocess(html) {
2381
+ return html;
2388
2382
  }
2389
- opt = merge({}, marked$1.defaults, opt || {});
2390
- checkSanitizeDeprecation(opt);
2391
- if (callback) {
2392
- const highlight = opt.highlight;
2393
- let tokens;
2394
- try {
2395
- tokens = Lexer.lex(src, opt);
2396
- } catch (e) {
2397
- return callback(e);
2383
+ }
2384
+ __publicField(Hooks, "passThroughHooks", /* @__PURE__ */ new Set([
2385
+ "preprocess",
2386
+ "postprocess"
2387
+ ]));
2388
+ function onError(silent, async, callback) {
2389
+ return (e) => {
2390
+ e.message += "\nPlease report this to https://github.com/markedjs/marked.";
2391
+ if (silent) {
2392
+ const msg = "<p>An error occurred:</p><pre>" + escape(e.message + "", true) + "</pre>";
2393
+ if (async) {
2394
+ return Promise.resolve(msg);
2395
+ }
2396
+ if (callback) {
2397
+ callback(null, msg);
2398
+ return;
2399
+ }
2400
+ return msg;
2398
2401
  }
2399
- const done = function(err) {
2400
- let out;
2401
- if (!err) {
2402
- try {
2403
- if (opt.walkTokens) {
2404
- marked$1.walkTokens(tokens, opt.walkTokens);
2405
- }
2406
- out = Parser.parse(tokens, opt);
2407
- } catch (e) {
2408
- err = e;
2402
+ if (async) {
2403
+ return Promise.reject(e);
2404
+ }
2405
+ if (callback) {
2406
+ callback(e);
2407
+ return;
2408
+ }
2409
+ throw e;
2410
+ };
2411
+ }
2412
+ function parseMarkdown(lexer, parser2) {
2413
+ return (src, opt, callback) => {
2414
+ if (typeof opt === "function") {
2415
+ callback = opt;
2416
+ opt = null;
2417
+ }
2418
+ const origOpt = __spreadValues({}, opt);
2419
+ opt = __spreadValues(__spreadValues({}, marked$1.defaults), origOpt);
2420
+ const throwError = onError(opt.silent, opt.async, callback);
2421
+ if (typeof src === "undefined" || src === null) {
2422
+ return throwError(new Error("marked(): input parameter is undefined or null"));
2423
+ }
2424
+ if (typeof src !== "string") {
2425
+ return throwError(new Error("marked(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected"));
2426
+ }
2427
+ checkSanitizeDeprecation(opt);
2428
+ if (opt.hooks) {
2429
+ opt.hooks.options = opt;
2430
+ }
2431
+ if (callback) {
2432
+ const highlight = opt.highlight;
2433
+ let tokens;
2434
+ try {
2435
+ if (opt.hooks) {
2436
+ src = opt.hooks.preprocess(src);
2409
2437
  }
2438
+ tokens = lexer(src, opt);
2439
+ } catch (e) {
2440
+ return throwError(e);
2410
2441
  }
2411
- opt.highlight = highlight;
2412
- return err ? callback(err) : callback(null, out);
2413
- };
2414
- if (!highlight || highlight.length < 3) {
2415
- return done();
2416
- }
2417
- delete opt.highlight;
2418
- if (!tokens.length)
2419
- return done();
2420
- let pending = 0;
2421
- marked$1.walkTokens(tokens, function(token) {
2422
- if (token.type === "code") {
2423
- pending++;
2424
- setTimeout(() => {
2425
- highlight(token.text, token.lang, function(err, code) {
2426
- if (err) {
2427
- return done(err);
2428
- }
2429
- if (code != null && code !== token.text) {
2430
- token.text = code;
2431
- token.escaped = true;
2442
+ const done = function(err) {
2443
+ let out;
2444
+ if (!err) {
2445
+ try {
2446
+ if (opt.walkTokens) {
2447
+ marked$1.walkTokens(tokens, opt.walkTokens);
2432
2448
  }
2433
- pending--;
2434
- if (pending === 0) {
2435
- done();
2449
+ out = parser2(tokens, opt);
2450
+ if (opt.hooks) {
2451
+ out = opt.hooks.postprocess(out);
2436
2452
  }
2437
- });
2438
- }, 0);
2453
+ } catch (e) {
2454
+ err = e;
2455
+ }
2456
+ }
2457
+ opt.highlight = highlight;
2458
+ return err ? throwError(err) : callback(null, out);
2459
+ };
2460
+ if (!highlight || highlight.length < 3) {
2461
+ return done();
2462
+ }
2463
+ delete opt.highlight;
2464
+ if (!tokens.length)
2465
+ return done();
2466
+ let pending = 0;
2467
+ marked$1.walkTokens(tokens, function(token) {
2468
+ if (token.type === "code") {
2469
+ pending++;
2470
+ setTimeout(() => {
2471
+ highlight(token.text, token.lang, function(err, code) {
2472
+ if (err) {
2473
+ return done(err);
2474
+ }
2475
+ if (code != null && code !== token.text) {
2476
+ token.text = code;
2477
+ token.escaped = true;
2478
+ }
2479
+ pending--;
2480
+ if (pending === 0) {
2481
+ done();
2482
+ }
2483
+ });
2484
+ }, 0);
2485
+ }
2486
+ });
2487
+ if (pending === 0) {
2488
+ done();
2439
2489
  }
2440
- });
2441
- if (pending === 0) {
2442
- done();
2490
+ return;
2443
2491
  }
2444
- return;
2445
- }
2446
- function onError(e) {
2447
- e.message += "\nPlease report this to https://github.com/markedjs/marked.";
2448
- if (opt.silent) {
2449
- return "<p>An error occurred:</p><pre>" + escape(e.message + "", true) + "</pre>";
2492
+ if (opt.async) {
2493
+ return Promise.resolve(opt.hooks ? opt.hooks.preprocess(src) : src).then((src2) => lexer(src2, opt)).then((tokens) => opt.walkTokens ? Promise.all(marked$1.walkTokens(tokens, opt.walkTokens)).then(() => tokens) : tokens).then((tokens) => parser2(tokens, opt)).then((html) => opt.hooks ? opt.hooks.postprocess(html) : html).catch(throwError);
2450
2494
  }
2451
- throw e;
2452
- }
2453
- try {
2454
- const tokens = Lexer.lex(src, opt);
2455
- if (opt.walkTokens) {
2456
- if (opt.async) {
2457
- return Promise.all(marked$1.walkTokens(tokens, opt.walkTokens)).then(() => {
2458
- return Parser.parse(tokens, opt);
2459
- }).catch(onError);
2495
+ try {
2496
+ if (opt.hooks) {
2497
+ src = opt.hooks.preprocess(src);
2460
2498
  }
2461
- marked$1.walkTokens(tokens, opt.walkTokens);
2499
+ const tokens = lexer(src, opt);
2500
+ if (opt.walkTokens) {
2501
+ marked$1.walkTokens(tokens, opt.walkTokens);
2502
+ }
2503
+ let html = parser2(tokens, opt);
2504
+ if (opt.hooks) {
2505
+ html = opt.hooks.postprocess(html);
2506
+ }
2507
+ return html;
2508
+ } catch (e) {
2509
+ return throwError(e);
2462
2510
  }
2463
- return Parser.parse(tokens, opt);
2464
- } catch (e) {
2465
- onError(e);
2466
- }
2511
+ };
2512
+ }
2513
+ function marked$1(src, opt, callback) {
2514
+ return parseMarkdown(Lexer.lex, Parser.parse)(src, opt, callback);
2467
2515
  }
2468
2516
  marked$1.options = marked$1.setOptions = function(opt) {
2469
- merge(marked$1.defaults, opt);
2517
+ marked$1.defaults = __spreadValues(__spreadValues({}, marked$1.defaults), opt);
2470
2518
  changeDefaults(marked$1.defaults);
2471
2519
  return marked$1;
2472
2520
  };
@@ -2475,8 +2523,8 @@ marked$1.defaults = defaults$3;
2475
2523
  marked$1.use = function(...args) {
2476
2524
  const extensions = marked$1.defaults.extensions || { renderers: {}, childTokens: {} };
2477
2525
  args.forEach((pack) => {
2478
- const opts = merge({}, pack);
2479
- opts.async = marked$1.defaults.async || opts.async;
2526
+ const opts = __spreadValues({}, pack);
2527
+ opts.async = marked$1.defaults.async || opts.async || false;
2480
2528
  if (pack.extensions) {
2481
2529
  pack.extensions.forEach((ext) => {
2482
2530
  if (!ext.name) {
@@ -2555,6 +2603,32 @@ marked$1.use = function(...args) {
2555
2603
  }
2556
2604
  opts.tokenizer = tokenizer;
2557
2605
  }
2606
+ if (pack.hooks) {
2607
+ const hooks = marked$1.defaults.hooks || new Hooks();
2608
+ for (const prop in pack.hooks) {
2609
+ const prevHook = hooks[prop];
2610
+ if (Hooks.passThroughHooks.has(prop)) {
2611
+ hooks[prop] = (arg) => {
2612
+ if (marked$1.defaults.async) {
2613
+ return Promise.resolve(pack.hooks[prop].call(hooks, arg)).then((ret2) => {
2614
+ return prevHook.call(hooks, ret2);
2615
+ });
2616
+ }
2617
+ const ret = pack.hooks[prop].call(hooks, arg);
2618
+ return prevHook.call(hooks, ret);
2619
+ };
2620
+ } else {
2621
+ hooks[prop] = (...args2) => {
2622
+ let ret = pack.hooks[prop].apply(hooks, args2);
2623
+ if (ret === false) {
2624
+ ret = prevHook.apply(hooks, args2);
2625
+ }
2626
+ return ret;
2627
+ };
2628
+ }
2629
+ }
2630
+ opts.hooks = hooks;
2631
+ }
2558
2632
  if (pack.walkTokens) {
2559
2633
  const walkTokens = marked$1.defaults.walkTokens;
2560
2634
  opts.walkTokens = function(token) {
@@ -2602,29 +2676,7 @@ marked$1.walkTokens = function(tokens, callback) {
2602
2676
  }
2603
2677
  return values;
2604
2678
  };
2605
- marked$1.parseInline = function(src, opt) {
2606
- if (typeof src === "undefined" || src === null) {
2607
- throw new Error("marked.parseInline(): input parameter is undefined or null");
2608
- }
2609
- if (typeof src !== "string") {
2610
- throw new Error("marked.parseInline(): input parameter is of type " + Object.prototype.toString.call(src) + ", string expected");
2611
- }
2612
- opt = merge({}, marked$1.defaults, opt || {});
2613
- checkSanitizeDeprecation(opt);
2614
- try {
2615
- const tokens = Lexer.lexInline(src, opt);
2616
- if (opt.walkTokens) {
2617
- marked$1.walkTokens(tokens, opt.walkTokens);
2618
- }
2619
- return Parser.parseInline(tokens, opt);
2620
- } catch (e) {
2621
- e.message += "\nPlease report this to https://github.com/markedjs/marked.";
2622
- if (opt.silent) {
2623
- return "<p>An error occurred:</p><pre>" + escape(e.message + "", true) + "</pre>";
2624
- }
2625
- throw e;
2626
- }
2627
- };
2679
+ marked$1.parseInline = parseMarkdown(Lexer.lexInline, Parser.parseInline);
2628
2680
  marked$1.Parser = Parser;
2629
2681
  marked$1.parser = Parser.parse;
2630
2682
  marked$1.Renderer = Renderer;
@@ -2633,6 +2685,7 @@ marked$1.Lexer = Lexer;
2633
2685
  marked$1.lexer = Lexer.lex;
2634
2686
  marked$1.Tokenizer = Tokenizer;
2635
2687
  marked$1.Slugger = Slugger;
2688
+ marked$1.Hooks = Hooks;
2636
2689
  marked$1.parse = marked$1;
2637
2690
  marked$1.options;
2638
2691
  marked$1.setOptions;
@@ -3419,7 +3472,7 @@ function t(key, args = {}) {
3419
3472
  str = str.replace(/\{\s*(\w+?)\s*\}/g, (_, token) => args[token] || "");
3420
3473
  return str;
3421
3474
  }
3422
- const version = "2.5.2";
3475
+ const version = "2.5.4";
3423
3476
  class User {
3424
3477
  constructor() {
3425
3478
  __publicField(this, "ctx");