securemark 0.289.6 → 0.290.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.290.0
4
+
5
+ - Change template syntax to allow linebreaks.
6
+
3
7
  ## 0.289.6
4
8
 
5
9
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.289.6 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.290.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("Prism"), require("DOMPurify"));
@@ -322,250 +322,6 @@ __exportStar(__webpack_require__(1311), exports);
322
322
 
323
323
  /***/ },
324
324
 
325
- /***/ 8663
326
- (__unused_webpack_module, exports) {
327
-
328
- "use strict";
329
-
330
-
331
- Object.defineProperty(exports, "__esModule", ({
332
- value: true
333
- }));
334
- exports.Clock = void 0;
335
- const BASE = 32;
336
- const DIGIT = Math.log2(BASE);
337
- const MASK = BASE - 1;
338
- const empty = Symbol('empty');
339
- class Clock {
340
- // Capacity is rounded up to multiples of 32.
341
- constructor(capacity,
342
- // ヒット率99%で平均100bitの走査となるためこれを極端に超えない走査数に制限
343
- limit = BASE * 10) {
344
- this.capacity = capacity;
345
- this.limit = limit;
346
- this.dict = new Map();
347
- this.keys = [];
348
- this.values = [];
349
- this.hand = 0;
350
- this.$length = 0;
351
- this.initial = 1;
352
- this.capacity = ((capacity - 1 | MASK) >>> 0) + 1;
353
- this.refs = new Int32Array(this.capacity >>> DIGIT);
354
- }
355
- get length() {
356
- return this.$length;
357
- }
358
- get size() {
359
- return this.$length;
360
- }
361
- mark(index) {
362
- const i = index >>> DIGIT;
363
- const before = this.refs[i];
364
- const after = before | 1 << (index & MASK);
365
- if (after === before) return;
366
- this.refs[i] = after;
367
- }
368
- unmark(index) {
369
- const i = index >>> DIGIT;
370
- const before = this.refs[i];
371
- const after = before & ~(1 << (index & MASK));
372
- if (after === before) return;
373
- this.refs[i] = after;
374
- }
375
- locate(hand, key, value) {
376
- const {
377
- capacity,
378
- dict,
379
- keys,
380
- values
381
- } = this;
382
- this.$length === capacity || this.initial === 0 && values[hand] !== empty ? dict.delete(keys[hand]) : ++this.$length;
383
- dict.set(key, hand);
384
- keys[hand] = key;
385
- values[hand] = value;
386
- this.hand = ++hand === capacity ? this.initial = 0 : hand;
387
- }
388
- add(key, value) {
389
- const {
390
- capacity,
391
- limit,
392
- refs
393
- } = this;
394
- for (let {
395
- hand
396
- } = this, i = hand >>> DIGIT, r = hand & MASK, c = 0;;) {
397
- const b = refs[i];
398
- if (b >>> r === ~0 >>> r && c < limit) {
399
- const d = BASE - r;
400
- c += d;
401
- hand += d;
402
- refs[i] = b & (1 << r) - 1;
403
- r = 0;
404
- if (hand < capacity) {
405
- ++i;
406
- } else {
407
- hand -= capacity;
408
- i = 0;
409
- }
410
- continue;
411
- }
412
- const l = c < limit ? search(b, r) : r;
413
- if (l !== r) {
414
- hand += l - r;
415
- refs[i] = b & ~((1 << l) - 1 >>> r << r);
416
- }
417
- this.locate(hand, key, value);
418
- return hand;
419
- }
420
- }
421
- put(key, value) {
422
- const index = this.dict.get(key);
423
- if (index === undefined) return this.add(key, value);
424
- this.values[index] = value;
425
- return index;
426
- }
427
- set(key, value) {
428
- this.put(key, value);
429
- return this;
430
- }
431
- get(key) {
432
- const index = this.dict.get(key);
433
- if (index === undefined) return;
434
- this.mark(index);
435
- return this.values[index];
436
- }
437
- has(key) {
438
- return this.dict.has(key);
439
- }
440
- delete(key) {
441
- const index = this.dict.get(key);
442
- if (index === undefined) return false;
443
- // 末尾と削除対象を交換して削除する。
444
- // 次の挿入の前に次の削除が行われると交換できないが稀なため対処しない。
445
- const {
446
- hand,
447
- dict,
448
- keys,
449
- values,
450
- refs
451
- } = this;
452
- dict.delete(key);
453
- --this.$length;
454
- const k = keys[index] = keys[hand];
455
- const v = values[index] = values[hand];
456
- keys[hand] = undefined;
457
- values[hand] = empty;
458
- if (index !== hand && v !== empty) {
459
- dict.set(k, index);
460
- (refs[hand >>> DIGIT] & 1 << (hand & MASK)) === 0 ? this.unmark(index) : this.mark(index);
461
- }
462
- this.unmark(hand);
463
- return true;
464
- }
465
- clear() {
466
- this.dict = new Map();
467
- this.keys = [];
468
- this.values = [];
469
- this.refs.fill(0);
470
- this.hand = 0;
471
- this.$length = 0;
472
- this.initial = 1;
473
- }
474
- *[Symbol.iterator]() {
475
- const {
476
- keys,
477
- values
478
- } = this;
479
- for (const index of this.dict.values()) {
480
- yield [keys[index], values[index]];
481
- }
482
- }
483
- }
484
- exports.Clock = Clock;
485
- function search(b, r) {
486
- for (let l = r;; ++l) {
487
- if ((b & 1 << l) === 0) return l;
488
- }
489
- }
490
- function bsearch(b, r) {
491
- const n = ~b >>> r << r >>> 0;
492
- const l = potision(0x05f66a47 * (n & -n) >>> 27);
493
- return l;
494
- }
495
- //const potisions = new Uint8Array([
496
- // 0, 1, 2, 26, 23, 3, 15, 27, 24, 21, 19, 4, 12, 16, 28, 6, 31, 25, 22, 14, 20, 18, 11, 5, 30, 13, 17, 10, 29, 9, 8, 7,
497
- //]);
498
- function potision(n) {
499
- switch (n) {
500
- case 0:
501
- return 0;
502
- case 1:
503
- return 1;
504
- case 2:
505
- return 2;
506
- case 3:
507
- return 26;
508
- case 4:
509
- return 23;
510
- case 5:
511
- return 3;
512
- case 6:
513
- return 15;
514
- case 7:
515
- return 27;
516
- case 8:
517
- return 24;
518
- case 9:
519
- return 21;
520
- case 10:
521
- return 19;
522
- case 11:
523
- return 4;
524
- case 12:
525
- return 12;
526
- case 13:
527
- return 16;
528
- case 14:
529
- return 28;
530
- case 15:
531
- return 6;
532
- case 16:
533
- return 31;
534
- case 17:
535
- return 25;
536
- case 18:
537
- return 22;
538
- case 19:
539
- return 14;
540
- case 20:
541
- return 20;
542
- case 21:
543
- return 18;
544
- case 22:
545
- return 11;
546
- case 23:
547
- return 5;
548
- case 24:
549
- return 30;
550
- case 25:
551
- return 13;
552
- case 26:
553
- return 17;
554
- case 27:
555
- return 10;
556
- case 28:
557
- return 29;
558
- case 29:
559
- return 9;
560
- case 30:
561
- return 8;
562
- default:
563
- return 7;
564
- }
565
- }
566
-
567
- /***/ },
568
-
569
325
  /***/ 1934
570
326
  (__unused_webpack_module, exports) {
571
327
 
@@ -6651,7 +6407,6 @@ const source_1 = __webpack_require__(8745);
6651
6407
  const visibility_1 = __webpack_require__(6364);
6652
6408
  const util_1 = __webpack_require__(4992);
6653
6409
  const memoize_1 = __webpack_require__(6925);
6654
- const clock_1 = __webpack_require__(8663);
6655
6410
  const array_1 = __webpack_require__(6876);
6656
6411
  const dom_1 = __webpack_require__(394);
6657
6412
  const tags = Object.freeze(['bdo', 'bdi']);
@@ -6662,9 +6417,11 @@ const attrspecs = {
6662
6417
  };
6663
6418
  Object.setPrototypeOf(attrspecs, null);
6664
6419
  Object.values(attrspecs).forEach(o => Object.setPrototypeOf(o, null));
6665
- exports.html = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(/^<[a-z]+(?=[^\S\n]|>)/i, (0, combinator_1.union)([(0, combinator_1.focus)(/^<wbr[^\S\n]*>/i, () => [[(0, dom_1.html)('wbr')], '']), (0, combinator_1.surround)(
6420
+ exports.html = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(/^<[a-z]+(?=[^\S\n]|>)/i, (0, combinator_1.union)([(0, combinator_1.surround)(
6421
+ // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
6422
+ (0, source_1.str)(/^<(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)(?=[^\S\n]|>)/i), (0, combinator_1.some)((0, combinator_1.union)([exports.attribute])), (0, source_1.str)(/^[^\S\n]*>/), true, ([as, bs = [], cs], rest) => as[0].slice(1) === 'wbr' && bs.length === 0 ? [[(0, dom_1.html)(as[0].slice(1))], rest] : [[elem(as[0].slice(1), (0, array_1.push)((0, array_1.unshift)(as, bs), cs), [], [])], rest], undefined, [3 | 8 /* Backtrack.bracket */]), (0, combinator_1.match)(new RegExp(String.raw`^<(${TAGS.join('|')})(?=[^\S\n]|>)`), (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^[^\S\n]*>/), true, undefined, undefined, [3 | 8 /* Backtrack.bracket */]), (0, combinator_1.precedence)(3, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, combinator_1.subsequence)([(0, combinator_1.focus)(/^[^\S\n]*\n/, (0, combinator_1.some)(inline_1.inline)), (0, combinator_1.some)((0, combinator_1.open)(/^\n?/, (0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('\n', `</${tag}>`), [[(0, visibility_1.blankWith)('\n', `</${tag}>`), 3]]), true))]))), (0, source_1.str)(`</${tag}>`), true, ([as, bs = [], cs], rest) => [[elem(tag, as, bs, cs)], rest], ([as, bs = []], rest) => [[elem(tag, as, bs, [])], rest]), ([, tag]) => tag, new Map())), (0, combinator_1.surround)(
6666
6423
  // https://html.spec.whatwg.org/multipage/syntax.html#void-elements
6667
- (0, source_1.str)(/^<(?:area|base|br|col|embed|hr|img|input|link|meta|source|track|wbr)(?=[^\S\n]|>)/i), (0, combinator_1.some)((0, combinator_1.union)([exports.attribute])), (0, source_1.str)(/^[^\S\n]*>/), true, ([as, bs = [], cs], rest) => [[elem(as[0].slice(1), (0, array_1.push)((0, array_1.unshift)(as, bs), cs), [], [])], rest], undefined, [3 | 8 /* Backtrack.bracket */]), (0, combinator_1.match)(new RegExp(String.raw`^<(${TAGS.join('|')})(?=[^\S\n]|>)`), (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^[^\S\n]*>/), true, undefined, undefined, [3 | 8 /* Backtrack.bracket */]), (0, combinator_1.precedence)(3, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, combinator_1.subsequence)([(0, combinator_1.focus)(/^[^\S\n]*\n/, (0, combinator_1.some)(inline_1.inline)), (0, combinator_1.some)((0, combinator_1.open)(/^\n?/, (0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('\n', `</${tag}>`), [[(0, visibility_1.blankWith)('\n', `</${tag}>`), 3]]), true))]))), (0, source_1.str)(`</${tag}>`), true, ([as, bs = [], cs], rest) => [[elem(tag, as, bs, cs)], rest], ([as, bs = []], rest) => [[elem(tag, as, bs, [])], rest]), ([, tag]) => tag, new Map())), (0, combinator_1.match)(/^<([a-z]+)(?=[^\S\n]|>)/i, (0, memoize_1.memoize)(([, tag]) => (0, combinator_1.surround)((0, combinator_1.surround)((0, source_1.str)(`<${tag}`), (0, combinator_1.some)(exports.attribute), (0, source_1.str)(/^[^\S\n]*>/), true, undefined, undefined, [3 | 8 /* Backtrack.bracket */]), (0, combinator_1.precedence)(3, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, combinator_1.subsequence)([(0, combinator_1.focus)(/^[^\S\n]*\n/, (0, combinator_1.some)(inline_1.inline)), (0, combinator_1.some)(inline_1.inline, `</${tag}>`, [[`</${tag}>`, 3]])]))), (0, source_1.str)(`</${tag}>`), true, ([as, bs = [], cs], rest) => [[elem(tag, as, bs, cs)], rest], ([as, bs = []], rest) => [[elem(tag, as, bs, [])], rest]), ([, tag]) => tag, new clock_1.Clock(10000)))])));
6424
+ (0, source_1.str)(/^<[a-z]+(?=[^\S\n]|>)/i), (0, combinator_1.some)((0, combinator_1.union)([exports.attribute])), (0, source_1.str)(/^[^\S\n]*>/), true, ([as, bs = [], cs], rest) => [[elem(as[0].slice(1), (0, array_1.push)((0, array_1.unshift)(as, bs), cs), [], [])], rest], undefined, [3 | 8 /* Backtrack.bracket */])])));
6668
6425
  exports.attribute = (0, combinator_1.union)([(0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="[^"\n]*")?(?=[^\S\n]|>)/i)]);
6669
6426
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Element
6670
6427
  // [...document.querySelectorAll('tbody > tr > td:first-child')].map(el => el.textContent.slice(1, -1))
@@ -6822,14 +6579,21 @@ exports.uri = (0, combinator_1.union)([(0, combinator_1.open)(/^[^\S\n]+/, (0, s
6822
6579
  exports.option = (0, combinator_1.union)([(0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+nofollow(?=[^\S\n]|})/), () => [` rel="nofollow"`]), (0, source_1.str)(/^[^\S\n]+[a-z]+(?:-[a-z]+)*(?:="(?:\\[^\n]|[^\\\n"])*")?(?=[^\S\n]|})/), (0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[^\s{}]+/), opt => [` \\${opt.slice(1)}`])]);
6823
6580
  function parse(content, params, context) {
6824
6581
  const INSECURE_URI = params.shift();
6825
- const uri = new url_1.ReadonlyURL(resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location), context.host?.href || location.href);
6582
+ let uri;
6583
+ try {
6584
+ uri = new url_1.ReadonlyURL(resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location), context.host?.href || location.href);
6585
+ } catch {}
6826
6586
  const el = elem(INSECURE_URI, content, uri, context.host?.origin || location.origin);
6827
6587
  return el.classList.contains('invalid') ? el : (0, dom_1.define)(el, (0, html_1.attributes)('link', [], optspec, params));
6828
6588
  }
6829
6589
  function elem(INSECURE_URI, content, uri, origin) {
6830
6590
  let type;
6831
6591
  let message;
6832
- switch (uri.protocol) {
6592
+ switch (uri?.protocol) {
6593
+ case undefined:
6594
+ type = 'argument';
6595
+ message = 'Invalid URI';
6596
+ break;
6833
6597
  case 'http:':
6834
6598
  case 'https:':
6835
6599
  switch (true) {
@@ -6863,10 +6627,13 @@ function elem(INSECURE_URI, content, uri, origin) {
6863
6627
  message = 'Invalid content';
6864
6628
  }
6865
6629
  break;
6630
+ default:
6631
+ type = 'argument';
6632
+ message = 'Invalid protocol';
6866
6633
  }
6867
6634
  return (0, dom_1.html)('a', {
6868
6635
  class: 'invalid',
6869
- ...(0, util_1.invalid)('link', type ??= 'argument', message ??= 'Invalid protocol')
6636
+ ...(0, util_1.invalid)('link', type, message)
6870
6637
  }, content.length === 0 ? INSECURE_URI : content);
6871
6638
  }
6872
6639
  function resolve(uri, host, source) {
@@ -6996,15 +6763,19 @@ const optspec = {
6996
6763
  Object.setPrototypeOf(optspec, null);
6997
6764
  exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(4 /* State.media */, false, (0, combinator_1.validate)(['![', '!{'], (0, combinator_1.creation)(10, (0, combinator_1.open)('!', (0, combinator_1.bind)((0, combinator_1.verify)((0, combinator_1.fmap)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.precedence)(1, (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ']')), ']', true, ([, ns = []], rest, context) => context.linebreak === undefined ? [ns, rest] : undefined, undefined, [3 | 4 /* Backtrack.escbracket */])), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([link_1.uri, (0, combinator_1.some)(option)]), /^[^\S\n]*}/, false, undefined, undefined, [3 | 64 /* Backtrack.link */]))]), ([as, bs]) => bs ? [[as.join('').trim() || as.join('')], bs] : [[''], as]), ([[text]]) => text === '' || text.trim() !== ''), ([[text], params], rest, context) => {
6998
6765
  const INSECURE_URI = params.shift();
6999
- const url = new url_1.ReadonlyURL((0, link_1.resolve)(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location), context.host?.href || location.href);
6766
+ // altが空だとエラーが見えないため埋める。
6767
+ text ||= INSECURE_URI;
6768
+ let uri;
6769
+ try {
6770
+ uri = new url_1.ReadonlyURL((0, link_1.resolve)(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location), context.host?.href || location.href);
6771
+ } catch {}
7000
6772
  let cache;
7001
- const el = false || (cache = context.caches?.media?.get(url.href)?.cloneNode(true)) || (0, dom_1.html)('img', {
6773
+ const el = false || uri && (cache = context.caches?.media?.get(uri.href)?.cloneNode(true)) || (0, dom_1.html)('img', {
7002
6774
  class: 'media',
7003
- 'data-src': url.source,
7004
- alt: text
6775
+ 'data-src': uri?.source
7005
6776
  });
7006
- cache?.hasAttribute('alt') && cache.setAttribute('alt', text);
7007
- if (!sanitize(el, url, text)) return [[el], rest];
6777
+ el.setAttribute('alt', text);
6778
+ if (!sanitize(el, uri, text)) return [[el], rest];
7008
6779
  (0, dom_1.define)(el, (0, html_1.attributes)('media', (0, array_1.push)([], el.classList), optspec, params));
7009
6780
  // Awaiting the generic support for attr().
7010
6781
  if (el.hasAttribute('aspect-ratio')) {
@@ -7024,33 +6795,33 @@ exports.linemedia = (0, combinator_1.surround)(source_1.linebreak, (0, combinato
7024
6795
  const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.recursion)(6 /* Recursion.terminal */, (0, combinator_1.union)([(0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ')'), (0, source_1.str)(')'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), ']'), (0, source_1.str)(']'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */]), (0, combinator_1.surround)((0, source_1.str)('{'), (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, bracket, source_1.txt]), '}'), (0, source_1.str)('}'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */]), (0, combinator_1.surround)((0, source_1.str)('"'), (0, combinator_1.precedence)(2, (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, source_1.txt]), '"')), (0, source_1.str)('"'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */])])));
7025
6796
  const option = (0, combinator_1.lazy)(() => (0, combinator_1.union)([(0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[1-9][0-9]*x[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` width="${opt.slice(1).split('x')[0]}"`, ` height="${opt.slice(1).split('x')[1]}"`]), (0, combinator_1.fmap)((0, source_1.str)(/^[^\S\n]+[1-9][0-9]*:[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` aspect-ratio="${opt.slice(1).split(':').join('/')}"`]), link_1.option]));
7026
6797
  function sanitize(target, uri, alt) {
7027
- switch (uri.protocol) {
6798
+ let type;
6799
+ let message;
6800
+ if (!alt.includes("\u0007" /* Command.Error */)) switch (uri?.protocol) {
6801
+ case undefined:
6802
+ type = 'argument';
6803
+ message = 'Invalid URI';
6804
+ break;
7028
6805
  case 'http:':
7029
6806
  case 'https:':
7030
- if (/\/\.\.?(?:\/|$)/.test('/' + uri.source.slice(0, uri.source.search(/[?#]|$/)))) {
7031
- (0, dom_1.define)(target, {
7032
- class: 'invalid',
7033
- ...(0, util_1.invalid)('media', 'argument', 'Dot-segments cannot be used in media paths; use subresource paths instead')
7034
- });
7035
- return false;
7036
- }
6807
+ if (!/\/\.\.?(?:\/|$)/.test('/' + uri.source.slice(0, uri.source.search(/[?#]|$/)))) return true;
6808
+ type = 'argument';
6809
+ message = 'Dot-segments cannot be used in media paths; use subresource paths instead';
7037
6810
  break;
7038
6811
  default:
7039
- (0, dom_1.define)(target, {
7040
- class: 'invalid',
7041
- ...(0, util_1.invalid)('media', 'argument', 'Invalid protocol')
7042
- });
7043
- return false;
7044
- }
7045
- if (alt.includes("\u0007" /* Command.Error */)) {
7046
- (0, dom_1.define)(target, {
7047
- class: 'invalid',
7048
- alt: target.getAttribute('alt')?.replace(context_1.CmdRegExp.Error, ''),
7049
- ...(0, util_1.invalid)('media', 'argument', `Cannot use invalid HTML entitiy "${alt.match(/&[0-9A-Za-z]+;/)[0]}"`)
7050
- });
7051
- return false;
6812
+ type = 'argument';
6813
+ message = 'Invalid protocol';
6814
+ } else {
6815
+ target.setAttribute('alt', alt.replace(context_1.CmdRegExp.Error, ''));
6816
+ type = 'argument';
6817
+ message = `Invalid HTML entitiy "${alt.match(/&[0-9A-Za-z]+;/)[0]}"`;
7052
6818
  }
7053
- return true;
6819
+ (0, dom_1.define)(target, {
6820
+ 'data-src': null,
6821
+ class: 'invalid',
6822
+ ...(0, util_1.invalid)('link', type, message)
6823
+ });
6824
+ return false;
7054
6825
  }
7055
6826
 
7056
6827
  /***/ },
@@ -7281,10 +7052,11 @@ Object.defineProperty(exports, "__esModule", ({
7281
7052
  exports.template = void 0;
7282
7053
  const combinator_1 = __webpack_require__(3484);
7283
7054
  const source_1 = __webpack_require__(8745);
7055
+ const array_1 = __webpack_require__(6876);
7284
7056
  const dom_1 = __webpack_require__(394);
7285
- exports.template = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('{{', (0, combinator_1.precedence)(1, (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), '}')), '}}', true, ([, ns = []], rest, context) => context.linebreak === undefined ? [[(0, dom_1.html)('span', {
7057
+ exports.template = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('{{'), (0, combinator_1.precedence)(1, (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), '}')), (0, source_1.str)('}}'), true, ([as, bs = [], cs], rest) => [[(0, dom_1.html)('span', {
7286
7058
  class: 'template'
7287
- }, `{{${ns.join('')}}}`)], rest] : undefined, undefined, [3 | 16 /* Backtrack.doublebracket */, 1 | 8 /* Backtrack.bracket */]));
7059
+ }, (0, dom_1.defrag)((0, array_1.push)((0, array_1.unshift)(as, bs), cs)))], rest], undefined, [3 | 16 /* Backtrack.doublebracket */, 1 | 8 /* Backtrack.bracket */]));
7288
7060
  const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.union)([(0, combinator_1.surround)((0, source_1.str)('('), (0, combinator_1.recursion)(6 /* Recursion.terminal */, (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), ')')), (0, source_1.str)(')'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */]), (0, combinator_1.surround)((0, source_1.str)('['), (0, combinator_1.recursion)(6 /* Recursion.terminal */, (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), ']')), (0, source_1.str)(']'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */]), (0, combinator_1.surround)((0, source_1.str)('{'), (0, combinator_1.recursion)(6 /* Recursion.terminal */, (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.escsource]), '}')), (0, source_1.str)('}'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */]), (0, combinator_1.surround)((0, source_1.str)('"'), (0, combinator_1.precedence)(2, (0, combinator_1.recursion)(6 /* Recursion.terminal */, (0, combinator_1.some)(source_1.escsource, '"'))), (0, source_1.str)('"'), true, undefined, () => [[], ''], [3 | 4 /* Backtrack.escbracket */])]));
7289
7061
 
7290
7062
  /***/ },
@@ -7724,6 +7496,7 @@ Object.defineProperty(exports, "__esModule", ({
7724
7496
  exports.escsource = void 0;
7725
7497
  const combinator_1 = __webpack_require__(3484);
7726
7498
  const text_1 = __webpack_require__(5655);
7499
+ const dom_1 = __webpack_require__(394);
7727
7500
  const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
7728
7501
  const escsource = ({
7729
7502
  source,
@@ -7756,7 +7529,7 @@ const escsource = ({
7756
7529
  }
7757
7530
  case '\n':
7758
7531
  context.linebreak ??= source.length;
7759
- return [[source[0]], source.slice(1)];
7532
+ return [[(0, dom_1.html)('br')], source.slice(1)];
7760
7533
  default:
7761
7534
  const b = source[0].trimStart() === '';
7762
7535
  const i = b ? source.search(text_1.nonWhitespace) : 1;
@@ -7911,6 +7684,7 @@ Object.defineProperty(exports, "__esModule", ({
7911
7684
  exports.unescsource = void 0;
7912
7685
  const combinator_1 = __webpack_require__(3484);
7913
7686
  const text_1 = __webpack_require__(5655);
7687
+ const dom_1 = __webpack_require__(394);
7914
7688
  const unescsource = ({
7915
7689
  source,
7916
7690
  context
@@ -7933,7 +7707,7 @@ const unescsource = ({
7933
7707
  return [[source.slice(1, 2)], source.slice(2)];
7934
7708
  case '\n':
7935
7709
  context.linebreak ??= source.length;
7936
- return [[source[0]], source.slice(1)];
7710
+ return [[(0, dom_1.html)('br')], source.slice(1)];
7937
7711
  default:
7938
7712
  const b = source[0].trimStart() === '';
7939
7713
  const i = b || (0, text_1.isAlphanumeric)(source[0]) ? source.search(b ? text_1.nonWhitespace : text_1.nonAlphanumeric) || 1 : 1;
package/markdown.d.ts CHANGED
@@ -686,16 +686,16 @@ export namespace MarkdownParser {
686
686
  export namespace TemplateParser {
687
687
  export interface BracketParser extends
688
688
  Inline<'template/bracket'>,
689
- Parser<string, Context, [
690
- Parser<string, Context, [
689
+ Parser<string | HTMLBRElement, Context, [
690
+ Parser<string | HTMLBRElement, Context, [
691
691
  BracketParser,
692
692
  SourceParser.EscapableSourceParser,
693
693
  ]>,
694
- Parser<string, Context, [
694
+ Parser<string | HTMLBRElement, Context, [
695
695
  BracketParser,
696
696
  SourceParser.EscapableSourceParser,
697
697
  ]>,
698
- Parser<string, Context, [
698
+ Parser<string | HTMLBRElement, Context, [
699
699
  BracketParser,
700
700
  SourceParser.EscapableSourceParser,
701
701
  ]>,
@@ -960,9 +960,8 @@ export namespace MarkdownParser {
960
960
  Inline<'html'>,
961
961
  Parser<HTMLElement | string, Context, [
962
962
  HTMLParser.VoidTagParser,
963
- HTMLParser.VoidTagParser,
964
- HTMLParser.TagParser,
965
963
  HTMLParser.TagParser,
964
+ HTMLParser.VoidTagParser,
966
965
  ]> {
967
966
  }
968
967
  export namespace HTMLParser {
@@ -1165,16 +1164,16 @@ export namespace MarkdownParser {
1165
1164
  }
1166
1165
  export interface BracketParser extends
1167
1166
  Inline<'url/bracket'>,
1168
- Parser<string, Context, [
1169
- Parser<string, Context, [
1167
+ Parser<string | HTMLBRElement, Context, [
1168
+ Parser<string | HTMLBRElement, Context, [
1170
1169
  BracketParser,
1171
1170
  SourceParser.UnescapableSourceParser,
1172
1171
  ]>,
1173
- Parser<string, Context, [
1172
+ Parser<string | HTMLBRElement, Context, [
1174
1173
  BracketParser,
1175
1174
  SourceParser.UnescapableSourceParser,
1176
1175
  ]>,
1177
- Parser<string, Context, [
1176
+ Parser<string | HTMLBRElement, Context, [
1178
1177
  BracketParser,
1179
1178
  SourceParser.UnescapableSourceParser,
1180
1179
  ]>,
@@ -1264,12 +1263,12 @@ export namespace MarkdownParser {
1264
1263
  export interface EscapableSourceParser extends
1265
1264
  // abc
1266
1265
  Source<'escsource'>,
1267
- Parser<string, Context, []> {
1266
+ Parser<string | HTMLBRElement, Context, []> {
1268
1267
  }
1269
1268
  export interface UnescapableSourceParser extends
1270
1269
  // abc
1271
1270
  Source<'unescsource'>,
1272
- Parser<string, Context, []> {
1271
+ Parser<string | HTMLBRElement, Context, []> {
1273
1272
  }
1274
1273
  export interface StrParser extends
1275
1274
  Source<'str'>,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.289.6",
3
+ "version": "0.290.0",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -132,9 +132,9 @@ describe('Unit: parser/api/parse', () => {
132
132
  '<p><a class="url" href="https://source/a" target="_blank">../a</a></p>',
133
133
  '<p><a class="url" href="https://source/a" target="_blank">../../a</a></p>',
134
134
  '<p><a class="url" href="//domain/a" target="_blank">//domain/a</a></p>',
135
- '<div><a href="https://source/x/a" target="_blank"><img class="media" data-src="https://source/x/a" alt=""></a></div>',
136
- '<div><a href="/z/a" target="_blank"><img class="media" data-src="/z/a" alt=""></a></div>',
137
- '<div><a href="https://source/a" target="_blank"><img class="media" data-src="https://source/a" alt=""></a></div>',
135
+ '<div><a href="https://source/x/a" target="_blank"><img class="media" data-src="https://source/x/a" alt="a"></a></div>',
136
+ '<div><a href="/z/a" target="_blank"><img class="media" data-src="/z/a" alt="^/a"></a></div>',
137
+ '<div><a href="https://source/a" target="_blank"><img class="media" data-src="https://source/a" alt="../../a"></a></div>',
138
138
  '<ol class="annotations"><li id="annotation::def:a:1" data-marker="*1"><span>a</span><sup><a href="#annotation::ref:a:1">^1</a></sup></li></ol>',
139
139
  ]);
140
140
  assert.deepStrictEqual(
@@ -19,8 +19,8 @@ describe('Unit: parser/block/extension/example', () => {
19
19
  assert.deepStrictEqual(inspect(parser('~~~example/markdown\n\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no"></pre><hr><section><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
20
20
  assert.deepStrictEqual(inspect(parser('~~~example/markdown\na\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">a</pre><hr><section><p>a</p><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
21
21
  assert.deepStrictEqual(inspect(parser('~~~example/markdown\n++a\nb++\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">++a\nb++</pre><hr><section><p><ins>a<br>b</ins></p><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
22
- assert.deepStrictEqual(inspect(parser('~~~example/markdown\n$fig-a\n!https://host\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">$fig-a\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
23
- assert.deepStrictEqual(inspect(parser('~~~example/markdown\n[$fig-a]\n!https://host\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">[$fig-a]\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
22
+ assert.deepStrictEqual(inspect(parser('~~~example/markdown\n$fig-a\n!https://host\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">$fig-a\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
23
+ assert.deepStrictEqual(inspect(parser('~~~example/markdown\n[$fig-a]\n!https://host\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">[$fig-a]\n!https://host</pre><hr><section><figure data-type="media" data-label="fig-a" data-group="fig" data-number="1"><figcaption><span class="figindex">Fig. 1. </span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
24
24
  assert.deepStrictEqual(inspect(parser('~~~example/markdown\n## a\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">## a</pre><hr><section><h2>a</h2><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
25
25
  assert.deepStrictEqual(inspect(parser('~~~example/markdown\n~ a\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">~ a</pre><hr><section><dl><dt>a</dt><dd></dd></dl><h2>References</h2><ol class="references"></ol></section></aside>'], '']);
26
26
  assert.deepStrictEqual(inspect(parser('~~~example/markdown\n((a))[[b]]\n~~~')), [['<aside class="example" data-type="markdown"><pre translate="no">((a))[[b]]</pre><hr><section><p><sup class="annotation disabled" title="a"><span></span><a>*1</a></sup><sup class="reference disabled" title="b"><span></span><a>[1]</a></sup></p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"><li><span>b</span><sup><a>^1</a></sup></li></ol></section></aside>'], '']);
@@ -15,14 +15,14 @@ describe('Unit: parser/block/extension/fig', () => {
15
15
  assert.deepStrictEqual(inspect(parser('[$group-name]a\nhttps://host')), undefined);
16
16
  assert.deepStrictEqual(inspect(parser('[$group-name]a\n!https://host')), undefined);
17
17
  assert.deepStrictEqual(inspect(parser('[$group-name] a\nhttps://host')), undefined);
18
- assert.deepStrictEqual(inspect(parser('[$group-name] a\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group" class="invalid"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
18
+ assert.deepStrictEqual(inspect(parser('[$group-name] a\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group" class="invalid"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
19
19
  assert.deepStrictEqual(inspect(parser('$-a\n$-b')), undefined);
20
20
  assert.deepStrictEqual(inspect(parser(' [$group-name]\n!https://host\n')), undefined);
21
21
  });
22
22
 
23
23
  it('valid', () => {
24
- assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
25
- assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
24
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
25
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
26
26
  assert.deepStrictEqual(inspect(parser('[$group-name]\n|\n|-\n|')), [['<figure data-type="table" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><table><thead><tr></tr></thead><tbody><tr></tr></tbody></table></div></figure>'], '']);
27
27
  assert.deepStrictEqual(inspect(parser('[$group-name]\n|\n|-\n|\n')), [['<figure data-type="table" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><table><thead><tr></tr></thead><tbody><tr></tr></tbody></table></div></figure>'], '']);
28
28
  assert.deepStrictEqual(inspect(parser('[$group-name]\n```\n\n```')), [['<figure data-type="text" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><pre class="text"></pre></div></figure>'], '']);
@@ -40,11 +40,11 @@ describe('Unit: parser/block/extension/fig', () => {
40
40
  assert.deepStrictEqual(inspect(parser('[$group-name]\n> \n')), [['<figure data-type="quote" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><blockquote></blockquote></div></figure>'], '']);
41
41
  assert.deepStrictEqual(inspect(parser('[$group-name]\n>\n~~~')), [['<figure data-type="quote" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><blockquote><pre><br>~~~</pre></blockquote></div></figure>'], '']);
42
42
  assert.deepStrictEqual(inspect(parser('[$group-name]\n!> *a*')), [['<figure data-type="quote" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><blockquote><section><p><em>a</em></p><h2>References</h2><ol class="references"></ol></section></blockquote></div></figure>'], '']);
43
- assert.deepStrictEqual(inspect(parser('[$group-name]\n![]{https://host}')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
44
- assert.deepStrictEqual(inspect(parser('[$group-name]\n![]{https://host}\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
45
- assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\ncaption')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
46
- assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\ncaption\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
47
- assert.deepStrictEqual(inspect(parser('$group-name\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt=""></a></div></figure>'], '']);
43
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n![]{https://host}')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
44
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n![]{https://host}\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
45
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\ncaption')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
46
+ assert.deepStrictEqual(inspect(parser('[$group-name]\n!https://host\ncaption\n')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext">caption</span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
47
+ assert.deepStrictEqual(inspect(parser('$group-name\n!https://host')), [['<figure data-type="media" data-label="group-name" data-group="group"><figcaption><span class="figindex"></span><span class="figtext"></span></figcaption><div><a href="https://host" target="_blank"><img class="media" data-src="https://host" alt="https://host"></a></div></figure>'], '']);
48
48
  });
49
49
 
50
50
  });