securemark 0.271.0 → 0.272.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.272.0
4
+
5
+ - Change footnote identifiers.
6
+
3
7
  ## 0.271.0
4
8
 
5
9
  - Extend table highlight syntax.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.271.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.272.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"));
@@ -1373,17 +1373,18 @@ exports.suppressAsyncException = suppressAsyncException;
1373
1373
  /***/ }),
1374
1374
 
1375
1375
  /***/ 4128:
1376
- /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
1376
+ /***/ ((__unused_webpack_module, exports, __webpack_require__) => {
1377
1377
 
1378
1378
  "use strict";
1379
1379
 
1380
1380
 
1381
+ Object.defineProperty(exports, "__esModule", ({
1382
+ value: true
1383
+ }));
1381
1384
  __webpack_require__(6921);
1382
- const global = false || typeof globalThis !== 'undefined' && globalThis
1383
- // @ts-ignore
1384
- || typeof self !== 'undefined' && self || Function('return this')();
1385
+ const global = globalThis;
1385
1386
  global.global = global;
1386
- module.exports = global;
1387
+ exports["default"] = global;
1387
1388
 
1388
1389
  /***/ }),
1389
1390
 
@@ -1394,9 +1395,7 @@ module.exports = global;
1394
1395
 
1395
1396
 
1396
1397
  // @ts-ignore
1397
- var globalThis;
1398
- // @ts-ignore
1399
- var global = (/* unused pure expression or super */ null && (globalThis));
1398
+ var global = globalThis;
1400
1399
 
1401
1400
  /***/ }),
1402
1401
 
@@ -1487,9 +1486,9 @@ class Heap {
1487
1486
  this.$length = 0;
1488
1487
  }
1489
1488
  }
1490
- exports.Heap = Heap;
1491
1489
  Heap.max = (a, b) => a > b ? -1 : a < b ? 1 : 0;
1492
1490
  Heap.min = (a, b) => a > b ? 1 : a < b ? -1 : 0;
1491
+ exports.Heap = Heap;
1493
1492
  function sort(cmp, array, index, length, stable) {
1494
1493
  if (length === 0) return false;
1495
1494
  switch (index) {
@@ -1631,9 +1630,9 @@ class MultiHeap {
1631
1630
  this.$length = 0;
1632
1631
  }
1633
1632
  }
1634
- exports.MultiHeap = MultiHeap;
1635
1633
  MultiHeap.max = Heap.max;
1636
1634
  MultiHeap.min = Heap.min;
1635
+ exports.MultiHeap = MultiHeap;
1637
1636
 
1638
1637
  /***/ }),
1639
1638
 
@@ -1993,10 +1992,10 @@ class PriorityQueue {
1993
1992
  return;
1994
1993
  }
1995
1994
  }
1996
- exports.PriorityQueue = PriorityQueue;
1997
1995
  PriorityQueue.priority = Symbol('priority');
1998
1996
  PriorityQueue.max = heap_1.Heap.max;
1999
1997
  PriorityQueue.min = heap_1.Heap.min;
1998
+ exports.PriorityQueue = PriorityQueue;
2000
1999
  class MultiQueue {
2001
2000
  constructor(entries) {
2002
2001
  this.dict = new Map();
@@ -2570,7 +2569,6 @@ class ReadonlyURL {
2570
2569
  return this.href;
2571
2570
  }
2572
2571
  }
2573
- exports.ReadonlyURL = ReadonlyURL;
2574
2572
  // Can't freeze URL object in the Firefox extension environment.
2575
2573
  // ref: https://github.com/falsandtru/pjax-api/issues/44#issuecomment-633915035
2576
2574
  // Bug: Error in dependents.
@@ -2578,6 +2576,7 @@ exports.ReadonlyURL = ReadonlyURL;
2578
2576
  ReadonlyURL.get = (0, memoize_1.memoize)((url, base) => ({
2579
2577
  url: new __webpack_require__.g.URL(url, base)
2580
2578
  }), (url, base = '') => `${base.indexOf('\n') > -1 ? base.replace(/\n+/g, '') : base}\n${url}`, new cache_1.Cache(10000));
2579
+ exports.ReadonlyURL = ReadonlyURL;
2581
2580
 
2582
2581
  /***/ }),
2583
2582
 
@@ -3540,7 +3539,6 @@ class Delimiters {
3540
3539
  return false;
3541
3540
  }
3542
3541
  }
3543
- exports.Delimiters = Delimiters;
3544
3542
  _a = Delimiters;
3545
3543
  Delimiters.matcher = (0, memoize_1.memoize)(pattern => {
3546
3544
  switch (typeof pattern) {
@@ -3552,6 +3550,7 @@ Delimiters.matcher = (0, memoize_1.memoize)(pattern => {
3552
3550
  return (0, memoize_1.reduce)(source => pattern.test(source) || undefined);
3553
3551
  }
3554
3552
  }, _a.signature);
3553
+ exports.Delimiters = Delimiters;
3555
3554
 
3556
3555
  /***/ }),
3557
3556
 
@@ -4539,7 +4538,7 @@ exports.aside = (0, combinator_1.block)((0, combinator_1.validate)('~~~', (0, co
4539
4538
  'data-invalid-message': 'Missing the title at the first line'
4540
4539
  }, `${opener}${body}${closer}`)];
4541
4540
  return [(0, dom_1.html)('aside', {
4542
- id: (0, indexee_1.identity)(context.id, (0, indexee_1.text)(heading)),
4541
+ id: (0, indexee_1.identity)(context.id, (0, indexee_1.index)(heading)),
4543
4542
  class: 'aside'
4544
4543
  }, [document, (0, dom_1.html)('h2', 'References'), references])];
4545
4544
  })));
@@ -5737,7 +5736,7 @@ const shortmedia_1 = __webpack_require__(4189);
5737
5736
  const autolink_1 = __webpack_require__(6051);
5738
5737
  const bracket_1 = __webpack_require__(5196);
5739
5738
  const source_1 = __webpack_require__(6743);
5740
- exports.inline = (0, combinator_1.union)([annotation_1.annotation, reference_1.reference, template_1.template, comment_1.comment, math_1.math, extension_1.extension, ruby_1.ruby, link_1.textlink, link_1.linemedialink, media_1.linemedia, html_1.html, insertion_1.insertion, deletion_1.deletion, mark_1.mark, strong_1.strong, emphasis_1.emphasis, code_1.code, htmlentity_1.htmlentity, shortmedia_1.lineshortmedia, autolink_1.autolink, bracket_1.bracket, source_1.text]);
5739
+ exports.inline = (0, combinator_1.lazy)(() => (0, combinator_1.union)([annotation_1.annotation, reference_1.reference, template_1.template, comment_1.comment, math_1.math, extension_1.extension, ruby_1.ruby, link_1.textlink, link_1.linemedialink, media_1.linemedia, html_1.html, insertion_1.insertion, deletion_1.deletion, mark_1.mark, strong_1.strong, emphasis_1.emphasis, code_1.code, htmlentity_1.htmlentity, shortmedia_1.lineshortmedia, autolink_1.autolink, bracket_1.bracket, source_1.text]));
5741
5740
  var indexee_1 = __webpack_require__(1269);
5742
5741
  Object.defineProperty(exports, "indexee", ({
5743
5742
  enumerable: true,
@@ -5809,7 +5808,7 @@ const hashnum_1 = __webpack_require__(5631);
5809
5808
  const anchor_1 = __webpack_require__(6495);
5810
5809
  const source_1 = __webpack_require__(6743);
5811
5810
  const util_1 = __webpack_require__(9437);
5812
- exports.autolink = (0, combinator_1.validate)(/^(?:[@#>0-9a-z\r\n]|\S[#>])/i, (0, combinator_1.constraint)(2 /* State.autolink */, false, (0, combinator_1.syntax)(2 /* Syntax.autolink */, 1, 1, ~1 /* State.shortcut */, (0, combinator_1.union)([(0, combinator_1.some)((0, combinator_1.union)([url_1.lineurl])), (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.union)([url_1.url, email_1.email,
5811
+ exports.autolink = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(/^(?:[@#>0-9a-z\r\n]|\S[#>])/i, (0, combinator_1.constraint)(2 /* State.autolink */, false, (0, combinator_1.syntax)(2 /* Syntax.autolink */, 1, 1, ~1 /* State.shortcut */, (0, combinator_1.union)([(0, combinator_1.some)((0, combinator_1.union)([url_1.lineurl])), (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.union)([url_1.url, email_1.email,
5813
5812
  // Escape unmatched email-like strings.
5814
5813
  (0, combinator_1.focus)(/^[0-9a-z](?:[_.+-](?=[0-9a-z])|[0-9a-z])*(?:@(?:[0-9a-z]+(?:[.-][0-9a-z]+)*)?)*/i, ({
5815
5814
  source
@@ -5826,7 +5825,7 @@ exports.autolink = (0, combinator_1.validate)(/^(?:[@#>0-9a-z\r\n]|\S[#>])/i, (0
5826
5825
  // Escape unmatched hashtag-like strings.
5827
5826
  (0, source_1.str)(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|')*/u.source.replace('emoji', hashtag_1.emoji), 'u')),
5828
5827
  // Escape invalid leading characters.
5829
- (0, source_1.str)(/^[0-9\p{Sc}](?=>)/u), anchor_1.anchor])), ns => ns.length === 1 ? ns : [(0, util_1.stringify)(ns)])]))));
5828
+ (0, source_1.str)(/^[0-9\p{Sc}](?=>)/u), anchor_1.anchor])), ns => ns.length === 1 ? ns : [(0, util_1.stringify)(ns)])])))));
5830
5829
 
5831
5830
  /***/ }),
5832
5831
 
@@ -5988,7 +5987,7 @@ const link_1 = __webpack_require__(9628);
5988
5987
  const source_1 = __webpack_require__(6743);
5989
5988
  const closer = /^[-+*=~^_,.;:!?]*(?=[\\"`|\[\](){}<>]|$)/;
5990
5989
  exports.url = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['http://', 'https://'], (0, combinator_1.rewrite)((0, combinator_1.open)(/^https?:\/\/(?=[\x21-\x7E])/, (0, combinator_1.focus)(/^[\x21-\x7E]+/, (0, combinator_1.some)((0, combinator_1.union)([bracket, (0, combinator_1.some)(source_1.unescsource, closer)])))), (0, combinator_1.convert)(url => `{ ${url} }`, (0, combinator_1.union)([link_1.unsafelink])))));
5991
- exports.lineurl = (0, combinator_1.open)(source_1.linebreak, (0, combinator_1.tails)([(0, source_1.str)('!'), (0, combinator_1.focus)(/^https?:\/\/\S+(?=[^\S\n]*(?:$|\n))/, (0, combinator_1.convert)(url => `{ ${url} }`, link_1.unsafelink))]));
5990
+ exports.lineurl = (0, combinator_1.lazy)(() => (0, combinator_1.open)(source_1.linebreak, (0, combinator_1.tails)([(0, source_1.str)('!'), (0, combinator_1.focus)(/^https?:\/\/\S+(?=[^\S\n]*(?:$|\n))/, (0, combinator_1.convert)(url => `{ ${url} }`, link_1.unsafelink))])));
5992
5991
  const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.precedence)(2, (0, combinator_1.union)([(0, combinator_1.surround)('(', (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.unescsource]), ')'), ')', true), (0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.unescsource]), ']'), ']', true), (0, combinator_1.surround)('{', (0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.unescsource]), '}'), '}', true), (0, combinator_1.surround)('"', (0, combinator_1.precedence)(8, (0, combinator_1.some)(source_1.unescsource, '"')), '"', true)]))));
5993
5992
 
5994
5993
  /***/ }),
@@ -6162,14 +6161,15 @@ const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, comb
6162
6161
  Object.defineProperty(exports, "__esModule", ({
6163
6162
  value: true
6164
6163
  }));
6165
- exports.text = exports.identity = exports.indexee = void 0;
6164
+ exports.text = exports.index = exports.identity = exports.indexee = void 0;
6166
6165
  const combinator_1 = __webpack_require__(2087);
6166
+ const memoize_1 = __webpack_require__(1808);
6167
6167
  const dom_1 = __webpack_require__(3252);
6168
6168
  function indexee(parser, optional) {
6169
6169
  return (0, combinator_1.fmap)(parser, ([el], _, {
6170
6170
  id
6171
6171
  }) => [(0, dom_1.define)(el, {
6172
- id: identity(id, text(el, optional))
6172
+ id: identity(id, index(el, optional))
6173
6173
  })]);
6174
6174
  }
6175
6175
  exports.indexee = indexee;
@@ -6183,17 +6183,20 @@ function identity(id, text, name = 'index') {
6183
6183
  case 'index':
6184
6184
  return `${name}:${id ?? ''}:${cs.slice(0, 97).join('')}...`;
6185
6185
  case 'mark':
6186
- case 'note':
6187
6186
  return `${name}:${id ?? ''}:${cs.slice(0, 50).join('')}...${cs.slice(-47).join('')}`;
6188
6187
  }
6189
6188
  }
6190
6189
  exports.identity = identity;
6191
- function text(source, optional = false) {
6190
+ function index(source, optional = false) {
6192
6191
  if (!source.firstChild) return '';
6193
6192
  const indexer = source.querySelector(':scope > .indexer');
6194
6193
  const index = indexer?.getAttribute('data-index');
6195
6194
  if (index) return index;
6196
6195
  if (index === '' && optional) return '';
6196
+ return (0, exports.text)(source);
6197
+ }
6198
+ exports.index = index;
6199
+ exports.text = (0, memoize_1.reduce)(source => {
6197
6200
  const target = source.cloneNode(true);
6198
6201
  for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'), len = es.length, i = 0; i < len; ++i) {
6199
6202
  const el = es[i];
@@ -6224,8 +6227,7 @@ function text(source, optional = false) {
6224
6227
  // Better:
6225
6228
  //return target.innerText;
6226
6229
  return target.textContent;
6227
- }
6228
- exports.text = text;
6230
+ });
6229
6231
 
6230
6232
  /***/ }),
6231
6233
 
@@ -6684,7 +6686,7 @@ exports.media = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['![', '
6684
6686
  }))))));
6685
6687
  exports.linemedia = (0, combinator_1.surround)(source_1.linebreak, (0, combinator_1.union)([exports.media]), /^(?=[^\S\n]*(?:$|\n))/);
6686
6688
  const bracket = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((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, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (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, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (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, ([as, bs = []], rest) => [(0, array_1.unshift)(as, bs), rest]), (0, combinator_1.surround)((0, source_1.str)('"'), (0, combinator_1.precedence)(8, (0, combinator_1.some)((0, combinator_1.union)([htmlentity_1.unsafehtmlentity, source_1.txt]), '"')), (0, source_1.str)('"'), true)])));
6687
- const option = (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]);
6689
+ 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]));
6688
6690
  function sanitize(target, uri, alt) {
6689
6691
  switch (uri.protocol) {
6690
6692
  case 'http:':
@@ -7095,8 +7097,8 @@ function* footnote(target, footnotes, opts = {}, bottom = null) {
7095
7097
  const el = es[i];
7096
7098
  el.parentNode === target && el.remove();
7097
7099
  }
7098
- yield* (0, exports.reference)(target, footnotes?.references, opts, bottom);
7099
7100
  yield* (0, exports.annotation)(target, footnotes?.annotations, opts, bottom);
7101
+ yield* (0, exports.reference)(target, footnotes?.references, opts, bottom);
7100
7102
  return;
7101
7103
  }
7102
7104
  exports.footnote = footnote;
@@ -7115,25 +7117,16 @@ function build(syntax, marker, splitter = '_') {
7115
7117
  }
7116
7118
  const refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`);
7117
7119
  const titles = new Map();
7118
- const contents = new Map();
7119
- for (let len = refs.length, i = 0; i < len; ++i) {
7120
- if (i % 10 === 9) yield;
7121
- const ref = refs[i];
7122
- const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild.innerHTML}`;
7123
- if (titles.has(identifier)) continue;
7124
- const content = (0, dom_1.html)('span', {
7125
- id: (0, indexee_1.identity)(opts.id, (0, indexee_1.text)(ref.firstElementChild), 'note')
7126
- }, ref.firstElementChild.cloneNode(true).childNodes);
7127
- const title = (0, indexee_1.text)(content).trim();
7128
- if (!title) continue;
7129
- titles.set(identifier, title);
7130
- contents.set(identifier, content);
7131
- }
7120
+ const indexes = new Map();
7132
7121
  let count = 0;
7133
7122
  let total = 0;
7134
7123
  let style;
7135
7124
  for (let len = refs.length, i = 0; i < len; ++i) {
7136
7125
  const ref = refs[i];
7126
+ if (ref.closest('[hidden]')) {
7127
+ yield;
7128
+ continue;
7129
+ }
7137
7130
  while (splitters.length > 0 && splitters[0].compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING) {
7138
7131
  if (defs.size > 0) {
7139
7132
  total += defs.size;
@@ -7145,8 +7138,9 @@ function build(syntax, marker, splitter = '_') {
7145
7138
  }
7146
7139
  splitters.shift();
7147
7140
  }
7148
- const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild.innerHTML}`;
7149
7141
  const abbr = ref.getAttribute('data-abbr') || undefined;
7142
+ const identifier = abbr || (0, indexee_1.identity)(undefined, (0, indexee_1.text)(ref.firstElementChild), 'mark')?.slice(6) || '';
7143
+ const title = false || titles.get(identifier) || titles.set(identifier, (0, indexee_1.text)(ref.firstElementChild)).get(identifier) || null;
7150
7144
  style ??= abbr ? 'abbr' : 'count';
7151
7145
  if (style === 'count' ? abbr : !abbr) {
7152
7146
  (0, dom_1.define)(ref, {
@@ -7168,21 +7162,21 @@ function build(syntax, marker, splitter = '_') {
7168
7162
  } else {
7169
7163
  ref.lastChild?.remove();
7170
7164
  }
7171
- const title = titles.get(identifier);
7172
7165
  const refIndex = ++count;
7173
7166
  const refId = opts.id !== '' ? `${syntax}:${opts.id ?? ''}:ref:${refIndex}` : undefined;
7174
7167
  const def = false || defs.get(identifier) || defs.set(identifier, (0, dom_1.html)('li', {
7175
- id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${total + defs.size + 1}` : undefined,
7168
+ id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${identifier}` : undefined,
7176
7169
  'data-marker': !footnote ? marker(total + defs.size + 1, abbr) : undefined
7177
- }, [contents.get(identifier) ?? (0, dom_1.frag)(), (0, dom_1.html)('sup')])).get(identifier);
7178
- const defIndex = +def.id.slice(def.id.lastIndexOf(':') + 1) || total + defs.size;
7170
+ }, [(0, dom_1.define)(ref.firstElementChild.cloneNode(true), {
7171
+ hidden: null
7172
+ }), (0, dom_1.html)('sup')])).get(identifier);
7173
+ const defIndex = false || indexes.get(def) || indexes.set(def, total + defs.size).get(def);
7179
7174
  const defId = def.id || undefined;
7180
7175
  (0, dom_1.define)(ref, {
7181
7176
  id: refId,
7182
- class: opts.id !== '' ? undefined : `${ref.className} disabled`,
7183
- ...(title ? {
7184
- title
7185
- } : {
7177
+ class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
7178
+ title,
7179
+ ...(!title && {
7186
7180
  class: void ref.classList.add('invalid'),
7187
7181
  'data-invalid-syntax': syntax,
7188
7182
  'data-invalid-type': 'content',
@@ -8434,7 +8428,7 @@ function unlink(h) {
8434
8428
  /***/ 3252:
8435
8429
  /***/ (function(module) {
8436
8430
 
8437
- /*! typed-dom v0.0.317 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8431
+ /*! typed-dom v0.0.330 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8438
8432
  (function webpackUniversalModuleDefinition(root, factory) {
8439
8433
  if(true)
8440
8434
  module.exports = factory();
@@ -8444,7 +8438,7 @@ return /******/ (() => { // webpackBootstrap
8444
8438
  /******/ "use strict";
8445
8439
  /******/ var __webpack_modules__ = ({
8446
8440
 
8447
- /***/ 406:
8441
+ /***/ 5406:
8448
8442
  /***/ ((__unused_webpack_module, exports) => {
8449
8443
 
8450
8444
 
@@ -8467,7 +8461,7 @@ exports.ObjectSetPrototypeOf = Object.setPrototypeOf;
8467
8461
 
8468
8462
  /***/ }),
8469
8463
 
8470
- /***/ 529:
8464
+ /***/ 5529:
8471
8465
  /***/ ((__unused_webpack_module, exports) => {
8472
8466
 
8473
8467
 
@@ -8483,8 +8477,8 @@ exports.equal = equal;
8483
8477
 
8484
8478
  /***/ }),
8485
8479
 
8486
- /***/ 808:
8487
- /***/ ((__unused_webpack_module, exports, __nested_webpack_require_3147__) => {
8480
+ /***/ 1808:
8481
+ /***/ ((__unused_webpack_module, exports, __nested_webpack_require_3150__) => {
8488
8482
 
8489
8483
 
8490
8484
 
@@ -8492,8 +8486,8 @@ Object.defineProperty(exports, "__esModule", ({
8492
8486
  value: true
8493
8487
  }));
8494
8488
  exports.reduce = exports.memoize = void 0;
8495
- const alias_1 = __nested_webpack_require_3147__(406);
8496
- const compare_1 = __nested_webpack_require_3147__(529);
8489
+ const alias_1 = __nested_webpack_require_3150__(5406);
8490
+ const compare_1 = __nested_webpack_require_3150__(5529);
8497
8491
  function memoize(f, identify = (...as) => as[0], memory) {
8498
8492
  if (typeof identify === 'object') return memoize(f, undefined, identify);
8499
8493
  return (0, alias_1.isArray)(memory) || memory?.constructor === Object ? memoizeRecord(f, identify, memory) : memoizeDict(f, identify, memory ?? new Map());
@@ -8539,8 +8533,8 @@ exports.reduce = reduce;
8539
8533
 
8540
8534
  /***/ }),
8541
8535
 
8542
- /***/ 521:
8543
- /***/ ((__unused_webpack_module, exports, __nested_webpack_require_4662__) => {
8536
+ /***/ 7521:
8537
+ /***/ ((__unused_webpack_module, exports, __nested_webpack_require_4668__) => {
8544
8538
 
8545
8539
 
8546
8540
 
@@ -8548,8 +8542,8 @@ Object.defineProperty(exports, "__esModule", ({
8548
8542
  value: true
8549
8543
  }));
8550
8544
  exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
8551
- const alias_1 = __nested_webpack_require_4662__(406);
8552
- const memoize_1 = __nested_webpack_require_4662__(808);
8545
+ const alias_1 = __nested_webpack_require_4668__(5406);
8546
+ const memoize_1 = __nested_webpack_require_4668__(1808);
8553
8547
  var caches;
8554
8548
  (function (caches) {
8555
8549
  caches.shadows = new WeakMap();
@@ -8578,20 +8572,22 @@ function text(source) {
8578
8572
  exports.text = text;
8579
8573
  function element(context, ns) {
8580
8574
  return (tag, attrs, children) => {
8581
- const el = elem(context, ns, tag);
8582
- return !attrs || isChildren(attrs) ? defineChildren(el, attrs ?? children) : defineChildren(defineAttrs(el, attrs), children);
8575
+ return !attrs || isChildren(attrs) ? defineChildren(elem(context, ns, tag, {}), attrs ?? children) : defineChildren(defineAttrs(elem(context, ns, tag, attrs), attrs), children);
8583
8576
  };
8584
8577
  }
8585
8578
  exports.element = element;
8586
- function elem(context, ns, tag) {
8579
+ function elem(context, ns, tag, attrs) {
8587
8580
  if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser.`);
8581
+ const opts = 'is' in attrs ? {
8582
+ is: attrs['is']
8583
+ } : undefined;
8588
8584
  switch (ns) {
8589
8585
  case "HTML" /* NS.HTML */:
8590
- return context.createElement(tag);
8586
+ return context.createElement(tag, opts);
8591
8587
  case "SVG" /* NS.SVG */:
8592
- return context.createElementNS('http://www.w3.org/2000/svg', tag);
8588
+ return context.createElementNS('http://www.w3.org/2000/svg', tag, opts);
8593
8589
  case "MathML" /* NS.MathML */:
8594
- return context.createElementNS('http://www.w3.org/1998/Math/MathML', tag);
8590
+ return context.createElementNS('http://www.w3.org/1998/Math/MathML', tag, opts);
8595
8591
  }
8596
8592
  }
8597
8593
  function define(node, attrs, children) {
@@ -8606,8 +8602,11 @@ function define(node, attrs, children) {
8606
8602
  }
8607
8603
  exports.define = define;
8608
8604
  function defineAttrs(el, attrs) {
8609
- for (const name in attrs) {
8610
- if (!(0, alias_1.hasOwnProperty)(attrs, name)) continue;
8605
+ for (const name of Object.keys(attrs)) {
8606
+ switch (name) {
8607
+ case 'is':
8608
+ continue;
8609
+ }
8611
8610
  const value = attrs[name];
8612
8611
  switch (typeof value) {
8613
8612
  case 'string':
@@ -8675,7 +8674,7 @@ function defineChildren(node, children) {
8675
8674
  return node;
8676
8675
  }
8677
8676
  function isChildren(value) {
8678
- return !!value?.[Symbol.iterator];
8677
+ return value?.[Symbol.iterator] !== undefined;
8679
8678
  }
8680
8679
  exports.isChildren = isChildren;
8681
8680
  function append(node, children) {
@@ -8728,7 +8727,7 @@ exports.defrag = defrag;
8728
8727
  /******/ var __webpack_module_cache__ = {};
8729
8728
  /******/
8730
8729
  /******/ // The require function
8731
- /******/ function __nested_webpack_require_11449__(moduleId) {
8730
+ /******/ function __nested_webpack_require_11589__(moduleId) {
8732
8731
  /******/ // Check if module is in cache
8733
8732
  /******/ var cachedModule = __webpack_module_cache__[moduleId];
8734
8733
  /******/ if (cachedModule !== undefined) {
@@ -8742,7 +8741,7 @@ exports.defrag = defrag;
8742
8741
  /******/ };
8743
8742
  /******/
8744
8743
  /******/ // Execute the module function
8745
- /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11449__);
8744
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11589__);
8746
8745
  /******/
8747
8746
  /******/ // Return the exports of the module
8748
8747
  /******/ return module.exports;
@@ -8753,7 +8752,7 @@ exports.defrag = defrag;
8753
8752
  /******/ // startup
8754
8753
  /******/ // Load entry module and return exports
8755
8754
  /******/ // This entry module is referenced by other modules so it can't be inlined
8756
- /******/ var __nested_webpack_exports__ = __nested_webpack_require_11449__(521);
8755
+ /******/ var __nested_webpack_exports__ = __nested_webpack_require_11589__(7521);
8757
8756
  /******/
8758
8757
  /******/ return __nested_webpack_exports__;
8759
8758
  /******/ })()
@@ -8765,7 +8764,7 @@ exports.defrag = defrag;
8765
8764
  /***/ 6120:
8766
8765
  /***/ (function(module) {
8767
8766
 
8768
- /*! typed-dom v0.0.317 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8767
+ /*! typed-dom v0.0.330 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8769
8768
  (function webpackUniversalModuleDefinition(root, factory) {
8770
8769
  if(true)
8771
8770
  module.exports = factory();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.271.0",
3
+ "version": "0.272.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",
@@ -28,35 +28,35 @@
28
28
  "LICENSE"
29
29
  ],
30
30
  "devDependencies": {
31
- "@types/dompurify": "3.0.0",
31
+ "@types/dompurify": "3.0.2",
32
32
  "@types/jquery": "3.5.16",
33
33
  "@types/mathjax": "0.0.37",
34
34
  "@types/mocha": "10.0.1",
35
35
  "@types/power-assert": "1.5.8",
36
36
  "@types/prismjs": "1.26.0",
37
- "@typescript-eslint/parser": "^5.55.0",
37
+ "@typescript-eslint/parser": "^5.59.0",
38
38
  "babel-loader": "^9.1.2",
39
39
  "babel-plugin-unassert": "^3.2.0",
40
- "concurrently": "^7.6.0",
41
- "eslint": "^8.36.0",
40
+ "concurrently": "^8.0.1",
41
+ "eslint": "^8.39.0",
42
42
  "eslint-plugin-redos": "^4.4.5",
43
- "eslint-webpack-plugin": "^4.0.0",
44
- "glob": "^8.1.0",
45
- "karma": "^6.4.1",
46
- "karma-chrome-launcher": "^3.1.1",
43
+ "eslint-webpack-plugin": "^4.0.1",
44
+ "glob": "^10.2.1",
45
+ "karma": "^6.4.2",
46
+ "karma-chrome-launcher": "^3.2.0",
47
47
  "karma-coverage": "^2.2.0",
48
48
  "karma-firefox-launcher": "^2.1.2",
49
49
  "karma-mocha": "^2.0.1",
50
50
  "karma-power-assert": "^1.0.0",
51
51
  "mocha": "^10.2.0",
52
- "npm-check-updates": "^16.7.12",
53
- "semver": "^7.3.8",
54
- "spica": "0.0.719",
52
+ "npm-check-updates": "^16.10.9",
53
+ "semver": "^7.5.0",
54
+ "spica": "0.0.721",
55
55
  "ts-loader": "^9.4.2",
56
- "typed-dom": "^0.0.317",
57
- "typescript": "4.9.5",
58
- "webpack": "^5.76.1",
59
- "webpack-cli": "^5.0.1",
56
+ "typed-dom": "^0.0.330",
57
+ "typescript": "5.0.4",
58
+ "webpack": "^5.80.0",
59
+ "webpack-cli": "^5.0.2",
60
60
  "webpack-merge": "^5.8.0"
61
61
  },
62
62
  "scripts": {
@@ -214,15 +214,15 @@ describe('Unit: parser/api/bind', () => {
214
214
  cfgs.footnotes.references?.outerHTML,
215
215
  html('ol', [
216
216
  html('li', { id: 'reference::def:1' }, [
217
- html('span', { id: 'note::1' }, '1'),
217
+ html('span', '1'),
218
218
  html('sup', [html('a', { href: '#reference::ref:1' }, '^1')]),
219
219
  ]),
220
220
  html('li', { id: 'reference::def:2' }, [
221
- html('span', { id: 'note::2' }, '2'),
221
+ html('span', '2'),
222
222
  html('sup', [html('a', { href: '#reference::ref:2' }, '^2')]),
223
223
  ]),
224
224
  html('li', { id: 'reference::def:3' }, [
225
- html('span', { id: 'note::3' }, '3'),
225
+ html('span', '3'),
226
226
  html('sup', [html('a', { href: '#reference::ref:3' }, '^3')]),
227
227
  ]),
228
228
  ]).outerHTML);
@@ -124,7 +124,7 @@ describe('Unit: parser/api/parse', () => {
124
124
  '<p><a class="index" href="#index::a">a</a></p>',
125
125
  '<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span><span class="figtext"></span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
126
126
  '<p><a class="label" data-label="$-a" href="#label:$-a">(1)</a></p>',
127
- '<p><sup class="annotation" id="annotation::ref:1" title="a"><span hidden="">a</span><a href="#annotation::def:1">*1</a></sup></p>',
127
+ '<p><sup class="annotation" id="annotation::ref:1" title="a"><span hidden="">a</span><a href="#annotation::def:a">*1</a></sup></p>',
128
128
  '<p><a class="url" href="https://source/x/a" target="_blank">a</a></p>',
129
129
  '<p><a class="url" href="https://source/a" target="_blank">/a</a></p>',
130
130
  '<p><a class="url" href="/z/a">^/a</a></p>',
@@ -135,7 +135,7 @@ describe('Unit: parser/api/parse', () => {
135
135
  '<p><a href="https://source/x/a" target="_blank"><img class="media" data-src="https://source/x/a" alt=""></a></p>',
136
136
  '<p><a href="/z/a" target="_blank"><img class="media" data-src="/z/a" alt=""></a></p>',
137
137
  '<p><a href="https://source/a" target="_blank"><img class="media" data-src="https://source/a" alt=""></a></p>',
138
- '<ol class="annotations"><li id="annotation::def:1" data-marker="*1"><span id="note::a">a</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>',
138
+ '<ol class="annotations"><li id="annotation::def:a" data-marker="*1"><span>a</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>',
139
139
  ]);
140
140
  assert.deepStrictEqual(
141
141
  [...parse([
@@ -207,12 +207,12 @@ describe('Unit: parser/api/parse', () => {
207
207
  [...parse('$-a\n$$\n$$\n\n(($-a[[b]][[c_d_]]))', { footnotes }).children].map(el => el.outerHTML),
208
208
  [
209
209
  '<figure data-type="math" data-label="$-a" data-group="$" data-number="1" id="label:$-a"><figcaption><span class="figindex">(1)</span><span class="figtext"></span></figcaption><div><div class="math" translate="no">$$\n$$</div></div></figure>',
210
- '<p><sup class="annotation" id="annotation::ref:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" id="reference::ref:1" title="b"><span hidden="">b</span><a href="#reference::def:1">[1]</a></sup><sup class="reference" id="reference::ref:2" title="cd"><span hidden="">c<em>d</em></span><a href="#reference::def:2">[2]</a></sup></span><a href="#annotation::def:1">*1</a></sup></p>',
211
- '<ol class="annotations"><li id="annotation::def:1" data-marker="*1"><span id="note::(1)"><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" id="reference::ref:1" title="b"><span hidden="">b</span><a href="#reference::def:1">[1]</a></sup><sup class="reference" id="reference::ref:2" title="cd"><span hidden="">c<em>d</em></span><a href="#reference::def:2">[2]</a></sup></span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>',
210
+ '<p><sup class="annotation" id="annotation::ref:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference"><span>b</span></sup><sup class="reference"><span>c<em>d</em></span></sup></span><a href="#annotation::def:(1)">*1</a></sup></p>',
211
+ '<ol class="annotations"><li id="annotation::def:(1)" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" id="reference::ref:1" title="b"><span hidden="">b</span><a href="#reference::def:b">[1]</a></sup><sup class="reference" id="reference::ref:2" title="cd"><span hidden="">c<em>d</em></span><a href="#reference::def:cd">[2]</a></sup></span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>',
212
212
  ]);
213
213
  assert.deepStrictEqual(
214
214
  footnotes.references.outerHTML,
215
- '<ol><li id="reference::def:1"><span id="note::b">b</span><sup><a href="#reference::ref:1">^1</a></sup></li><li id="reference::def:2"><span id="note::cd">c<em>d</em></span><sup><a href="#reference::ref:2">^2</a></sup></li></ol>');
215
+ '<ol><li id="reference::def:b"><span>b</span><sup><a href="#reference::ref:1">^1</a></sup></li><li id="reference::def:cd"><span>c<em>d</em></span><sup><a href="#reference::ref:2">^2</a></sup></li></ol>');
216
216
  });
217
217
 
218
218
  it('normalize', () => {
@@ -1,6 +1,6 @@
1
1
  import { ExtensionParser } from '../../block';
2
2
  import { block, validate, fence, fmap } from '../../../combinator';
3
- import { identity, text } from '../../inline/extension/indexee';
3
+ import { identity, index } from '../../inline/extension/indexee';
4
4
  import { parse } from '../../api/parse';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
@@ -34,9 +34,9 @@ export const aside: ExtensionParser.AsideParser = block(validate('~~~', fmap(
34
34
  'data-invalid-type': 'content',
35
35
  'data-invalid-message': 'Missing the title at the first line',
36
36
  }, `${opener}${body}${closer}`)];
37
- assert(identity(context.id, text(heading)));
37
+ assert(identity(context.id, index(heading)));
38
38
  return [
39
- html('aside', { id: identity(context.id, text(heading)), class: 'aside' }, [
39
+ html('aside', { id: identity(context.id, index(heading)), class: 'aside' }, [
40
40
  document,
41
41
  html('h2', 'References'),
42
42
  references,
@@ -13,7 +13,7 @@ export const url: AutolinkParser.UrlParser = lazy(() => validate(['http://', 'ht
13
13
  url => `{ ${url} }`,
14
14
  union([unsafelink])))));
15
15
 
16
- export const lineurl: AutolinkParser.UrlParser.LineUrlParser = open(
16
+ export const lineurl: AutolinkParser.UrlParser.LineUrlParser = lazy(() => open(
17
17
  linebreak,
18
18
  tails([
19
19
  str('!'),
@@ -22,7 +22,7 @@ export const lineurl: AutolinkParser.UrlParser.LineUrlParser = open(
22
22
  convert(
23
23
  url => `{ ${url} }`,
24
24
  unsafelink)),
25
- ]));
25
+ ])));
26
26
 
27
27
  const bracket: AutolinkParser.UrlParser.BracketParser = lazy(() => creation(precedence(2, union([
28
28
  surround('(', some(union([bracket, unescsource]), ')'), ')', true),
@@ -1,5 +1,5 @@
1
1
  import { AutolinkParser } from '../inline';
2
- import { union, some, syntax, constraint, validate, focus, fmap } from '../../combinator';
2
+ import { union, some, syntax, constraint, validate, focus, lazy, fmap } from '../../combinator';
3
3
  import { url, lineurl } from './autolink/url';
4
4
  import { email } from './autolink/email';
5
5
  import { channel } from './autolink/channel';
@@ -11,7 +11,7 @@ import { str } from '../source';
11
11
  import { Syntax, State } from '../context';
12
12
  import { stringify } from '../util';
13
13
 
14
- export const autolink: AutolinkParser =
14
+ export const autolink: AutolinkParser = lazy(() =>
15
15
  validate(/^(?:[@#>0-9a-z\r\n]|\S[#>])/i,
16
16
  constraint(State.autolink, false,
17
17
  syntax(Syntax.autolink, 1, 1, ~State.shortcut,
@@ -44,4 +44,4 @@ export const autolink: AutolinkParser =
44
44
  anchor,
45
45
  ])),
46
46
  ns => ns.length === 1 ? ns : [stringify(ns)]),
47
- ]))));
47
+ ])))));
@@ -1,14 +1,15 @@
1
1
  import { MarkdownParser } from '../../../../markdown';
2
2
  import { Parser } from '../../../combinator/data/parser';
3
3
  import { fmap } from '../../../combinator';
4
+ import { reduce } from 'spica/memoize';
4
5
  import { define } from 'typed-dom/dom';
5
6
 
6
7
  export function indexee<P extends Parser<unknown, MarkdownParser.Context>>(parser: P, optional?: boolean): P;
7
8
  export function indexee(parser: Parser<HTMLElement, MarkdownParser.Context>, optional?: boolean): Parser<HTMLElement> {
8
- return fmap(parser, ([el], _, { id }) => [define(el, { id: identity(id, text(el, optional)) })]);
9
+ return fmap(parser, ([el], _, { id }) => [define(el, { id: identity(id, index(el, optional)) })]);
9
10
  }
10
11
 
11
- export function identity(id: string | undefined, text: string, name: 'index' | 'mark' | 'note' = 'index'): string | undefined {
12
+ export function identity(id: string | undefined, text: string, name: 'index' | 'mark' = 'index'): string | undefined {
12
13
  assert(!id?.match(/[^0-9a-z/-]/i));
13
14
  assert(!text.includes('\n'));
14
15
  if (id === '') return undefined;
@@ -20,7 +21,6 @@ export function identity(id: string | undefined, text: string, name: 'index' | '
20
21
  case 'index':
21
22
  return `${name}:${id ?? ''}:${cs.slice(0, 97).join('')}...`;
22
23
  case 'mark':
23
- case 'note':
24
24
  return `${name}:${id ?? ''}:${cs.slice(0, 50).join('')}...${cs.slice(-47).join('')}`;
25
25
  }
26
26
  assert(false);
@@ -32,7 +32,7 @@ assert(identity(undefined, '0'.repeat(100 - 1) + 1, 'mark')!.slice(6) === '0'.re
32
32
  assert(identity(undefined, '0'.repeat(100) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
33
33
  assert(identity(undefined, '0'.repeat(200) + 1, 'mark')!.slice(6) === '0'.repeat(50) + '...' + '0'.repeat(47 - 1) + 1);
34
34
 
35
- export function text(source: Element | DocumentFragment, optional = false): string {
35
+ export function index(source: Element | DocumentFragment, optional = false): string {
36
36
  assert(source instanceof DocumentFragment || !source.matches('.indexer'));
37
37
  assert(source.querySelectorAll(':scope > .indexer').length <= 1);
38
38
  if (!source.firstChild) return '';
@@ -40,6 +40,10 @@ export function text(source: Element | DocumentFragment, optional = false): stri
40
40
  const index = indexer?.getAttribute('data-index');
41
41
  if (index) return index;
42
42
  if (index === '' && optional) return '';
43
+ return text(source);
44
+ }
45
+
46
+ export const text = reduce((source: Element | DocumentFragment): string => {
43
47
  assert(!navigator.userAgent.includes('Chrome') || !source.querySelector('br:not(:has(+ :is(ul, ol)))'));
44
48
  const target = source.cloneNode(true) as typeof source;
45
49
  for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, br, .annotation, .reference, .checkbox, ul, ol'),
@@ -72,4 +76,4 @@ export function text(source: Element | DocumentFragment, optional = false): stri
72
76
  // Better:
73
77
  //return target.innerText;
74
78
  return target.textContent!;
75
- }
79
+ });
@@ -73,11 +73,11 @@ const bracket: MediaParser.TextParser.BracketParser = lazy(() => creation(union(
73
73
  surround(str('"'), precedence(8, some(union([unsafehtmlentity, txt]), '"')), str('"'), true),
74
74
  ])));
75
75
 
76
- const option: MediaParser.ParameterParser.OptionParser = union([
76
+ const option: MediaParser.ParameterParser.OptionParser = lazy(() => union([
77
77
  fmap(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]}"`]),
78
78
  fmap(str(/^[^\S\n]+[1-9][0-9]*:[1-9][0-9]*(?=[^\S\n]|})/), ([opt]) => [` aspect-ratio="${opt.slice(1).split(':').join('/')}"`]),
79
79
  linkoption,
80
- ]);
80
+ ]));
81
81
 
82
82
  function sanitize(target: HTMLElement, uri: ReadonlyURL, alt: string): boolean {
83
83
  assert(target.tagName === 'IMG');
@@ -1,5 +1,5 @@
1
1
  import { MarkdownParser } from '../../markdown';
2
- import { union } from '../combinator';
2
+ import { union, lazy } from '../combinator';
3
3
  import { annotation } from './inline/annotation';
4
4
  import { reference } from './inline/reference';
5
5
  import { template } from './inline/template';
@@ -45,7 +45,7 @@ export import ShortMediaParser = InlineParser.ShortMediaParser;
45
45
  export import AutolinkParser = InlineParser.AutolinkParser;
46
46
  export import BracketParser = InlineParser.BracketParser;
47
47
 
48
- export const inline: InlineParser = union([
48
+ export const inline: InlineParser = lazy(() => union([
49
49
  annotation,
50
50
  reference,
51
51
  template,
@@ -68,7 +68,7 @@ export const inline: InlineParser = union([
68
68
  autolink,
69
69
  bracket,
70
70
  text
71
- ]);
71
+ ]));
72
72
 
73
73
  export { indexee } from './inline/extension/indexee';
74
74
  export { indexer } from './inline/extension/indexer';
@@ -29,15 +29,15 @@ describe('Unit: parser/processor/footnote', () => {
29
29
  html('p', [
30
30
  html('sup', { class: "annotation", id: "annotation::ref:1", title: "a b" }, [
31
31
  html('span', { hidden: '' }, 'a b'),
32
- html('a', { href: "#annotation::def:1" }, '*1')
32
+ html('a', { href: "#annotation::def:a_b" }, '*1')
33
33
  ]),
34
34
  ]).outerHTML,
35
35
  ]);
36
36
  assert.deepStrictEqual(
37
37
  footnote.outerHTML,
38
38
  html('ol', [
39
- html('li', { id: 'annotation::def:1' }, [
40
- html('span', { id: 'note::a_b' }, 'a b'),
39
+ html('li', { id: 'annotation::def:a_b' }, [
40
+ html('span', 'a b'),
41
41
  html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
42
42
  ]),
43
43
  ]).outerHTML);
@@ -59,7 +59,7 @@ describe('Unit: parser/processor/footnote', () => {
59
59
  ]),
60
60
  html('sup', { class: "annotation", id: "annotation::ref:2", title: "12345678901234567890" }, [
61
61
  html('span', { hidden: '' }, '12345678901234567890'),
62
- html('a', { href: "#annotation::def:2" }, '*2')
62
+ html('a', { href: "#annotation::def:12345678901234567890" }, '*2')
63
63
  ]),
64
64
  ]).outerHTML,
65
65
  ]);
@@ -67,11 +67,11 @@ describe('Unit: parser/processor/footnote', () => {
67
67
  footnote.outerHTML,
68
68
  html('ol', [
69
69
  html('li', { id: 'annotation::def:1' }, [
70
- html('span', { id: 'note::1' }, '1'),
70
+ html('span', '1'),
71
71
  html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
72
72
  ]),
73
- html('li', { id: 'annotation::def:2' }, [
74
- html('span', { id: 'note::12345678901234567890' }, '12345678901234567890'),
73
+ html('li', { id: 'annotation::def:12345678901234567890' }, [
74
+ html('span', '12345678901234567890'),
75
75
  html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
76
76
  ]),
77
77
  ]).outerHTML);
@@ -113,22 +113,22 @@ describe('Unit: parser/processor/footnote', () => {
113
113
  footnote.outerHTML,
114
114
  html('ol', [
115
115
  html('li', { id: 'annotation::def:1' }, [
116
- html('span', { id: 'note::1' }, '1'),
116
+ html('span', '1'),
117
117
  html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
118
118
  ]),
119
119
  html('li', { id: 'annotation::def:2' }, [
120
- html('span', { id: 'note::2' }, '2'),
120
+ html('span', '2'),
121
121
  html('sup', [
122
122
  html('a', { href: '#annotation::ref:2' }, '^2'),
123
123
  html('a', { href: '#annotation::ref:4' }, '^4'),
124
124
  ]),
125
125
  ]),
126
126
  html('li', { id: 'annotation::def:3' }, [
127
- html('span', { id: 'note::3' }, '3'),
127
+ html('span', '3'),
128
128
  html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
129
129
  ]),
130
130
  html('li', { id: 'annotation::def:4' }, [
131
- html('span', { id: 'note::4' }, '4'),
131
+ html('span', '4'),
132
132
  html('sup', [html('a', { href: '#annotation::ref:5' }, '^5')])
133
133
  ]),
134
134
  ]).outerHTML);
@@ -141,9 +141,9 @@ describe('Unit: parser/processor/footnote', () => {
141
141
 
142
142
  it('separation', () => {
143
143
  const target = html('blockquote', parse([
144
- '!>> ((a))\n> ((a))\n~~~',
145
- '~~~~example/markdown\n((a))\n~~~~',
146
- '((a))',
144
+ '!>> ((1))\n> ((2))\n~~~',
145
+ '~~~~example/markdown\n((3))\n~~~~',
146
+ '((4))',
147
147
  ].join('\n\n')).children);
148
148
  const footnote = html('ol');
149
149
  for (let i = 0; i < 3; ++i) {
@@ -151,13 +151,13 @@ describe('Unit: parser/processor/footnote', () => {
151
151
  assert.deepStrictEqual(
152
152
  [...target.children].map(el => el.outerHTML),
153
153
  [
154
- '<blockquote><blockquote><section><p><sup class="annotation disabled" title="a"><span hidden="">a</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"></ol></section></blockquote><section><p><sup class="annotation disabled" title="a"><span hidden="">a</span><a>*1</a></sup><br>~~~</p><ol class="annotations"><li data-marker="*1"><span>a</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>',
155
- '<aside class="example" data-type="markdown"><pre translate="no">((a))</pre><hr><section><p><sup class="annotation disabled" title="a"><span hidden="">a</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"></ol></section></aside>',
156
- '<p><sup class="annotation" id="annotation::ref:1" title="a"><span hidden="">a</span><a href="#annotation::def:1">*1</a></sup></p>',
154
+ '<blockquote><blockquote><section><p><sup class="annotation disabled" title="1"><span hidden="">1</span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>1</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote><section><p><sup class="annotation disabled" title="2"><span hidden="">2</span><a>*1</a></sup><br>~~~</p><ol class="annotations"><li data-marker="*1"><span>2</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></blockquote>',
155
+ '<aside class="example" data-type="markdown"><pre translate="no">((3))</pre><hr><section><p><sup class="annotation disabled" title="3"><span hidden="">3</span><a>*1</a></sup></p><ol class="annotations"><li data-marker="*1"><span>3</span><sup><a>^1</a></sup></li></ol><h2>References</h2><ol class="references"></ol></section></aside>',
156
+ '<p><sup class="annotation" id="annotation::ref:1" title="4"><span hidden="">4</span><a href="#annotation::def:4">*1</a></sup></p>',
157
157
  ]);
158
158
  assert.deepStrictEqual(
159
159
  footnote.outerHTML,
160
- '<ol><li id="annotation::def:1"><span id="note::a">a</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>');
160
+ '<ol><li id="annotation::def:4"><span>4</span><sup><a href="#annotation::ref:1">^1</a></sup></li></ol>');
161
161
  }
162
162
  });
163
163
 
@@ -172,15 +172,15 @@ describe('Unit: parser/processor/footnote', () => {
172
172
  html('p', [
173
173
  html('sup', { class: "annotation", id: "annotation:0:ref:1", title: "a b" }, [
174
174
  html('span', { hidden: '' }, 'a b'),
175
- html('a', { href: "#annotation:0:def:1" }, '*1')
175
+ html('a', { href: "#annotation:0:def:a_b" }, '*1')
176
176
  ]),
177
177
  ]).outerHTML,
178
178
  ]);
179
179
  assert.deepStrictEqual(
180
180
  footnote.outerHTML,
181
181
  html('ol', [
182
- html('li', { id: 'annotation:0:def:1' }, [
183
- html('span', { id: 'note:0:a_b' }, 'a b'),
182
+ html('li', { id: 'annotation:0:def:a_b' }, [
183
+ html('span', 'a b'),
184
184
  html('sup', [html('a', { href: '#annotation:0:ref:1' }, '^1')])
185
185
  ]),
186
186
  ]).outerHTML);
@@ -202,7 +202,7 @@ describe('Unit: parser/processor/footnote', () => {
202
202
  ]).outerHTML,
203
203
  html('ol', { class: 'annotations' }, [
204
204
  html('li', { id: 'annotation::def:1', 'data-marker': '*1' }, [
205
- html('span', { id: 'note::1' }, '1'),
205
+ html('span', '1'),
206
206
  html('sup', [html('a', { href: '#annotation::ref:1' }, '^1')])
207
207
  ]),
208
208
  ]).outerHTML,
@@ -220,11 +220,11 @@ describe('Unit: parser/processor/footnote', () => {
220
220
  ]).outerHTML,
221
221
  html('ol', { class: 'annotations' }, [
222
222
  html('li', { id: 'annotation::def:2', 'data-marker': '*2' }, [
223
- html('span', { id: 'note::2' }, '2'),
223
+ html('span', '2'),
224
224
  html('sup', [html('a', { href: '#annotation::ref:2' }, '^2')])
225
225
  ]),
226
226
  html('li', { id: 'annotation::def:3', 'data-marker': '*3' }, [
227
- html('span', { id: 'note::3' }, '3'),
227
+ html('span', '3'),
228
228
  html('sup', [html('a', { href: '#annotation::ref:3' }, '^3')])
229
229
  ]),
230
230
  ]).outerHTML,
@@ -237,7 +237,7 @@ describe('Unit: parser/processor/footnote', () => {
237
237
  ]).outerHTML,
238
238
  html('ol', { class: 'annotations' }, [
239
239
  html('li', { id: 'annotation::def:4', 'data-marker': '*4' }, [
240
- html('span', { id: 'note::4' }, '4'),
240
+ html('span', '4'),
241
241
  html('sup', [html('a', { href: '#annotation::ref:4' }, '^4')])
242
242
  ]),
243
243
  ]).outerHTML,
@@ -259,15 +259,15 @@ describe('Unit: parser/processor/footnote', () => {
259
259
  html('p', [
260
260
  html('sup', { class: "reference", id: "reference::ref:1", title: "a b" }, [
261
261
  html('span', { hidden: '' }, 'a b'),
262
- html('a', { href: "#reference::def:1" }, '[1]')
262
+ html('a', { href: "#reference::def:a_b" }, '[1]')
263
263
  ]),
264
264
  ]).outerHTML,
265
265
  ]);
266
266
  assert.deepStrictEqual(
267
267
  footnote.outerHTML,
268
268
  html('ol', [
269
- html('li', { id: 'reference::def:1' }, [
270
- html('span', { id: 'note::a_b' }, 'a b'),
269
+ html('li', { id: 'reference::def:a_b' }, [
270
+ html('span', 'a b'),
271
271
  html('sup', [html('a', { href: '#reference::ref:1' }, '^1')])
272
272
  ]),
273
273
  ]).outerHTML);
@@ -275,7 +275,7 @@ describe('Unit: parser/processor/footnote', () => {
275
275
  });
276
276
 
277
277
  it('abbr', () => {
278
- const target = parse('[[^a]][[^a| b]][[^a]]');
278
+ const target = parse('[[^a| b]][[^a]][[^a]]');
279
279
  const footnote = html('ol');
280
280
  for (let i = 0; i < 3; ++i) {
281
281
  [...reference(target, footnote)];
@@ -284,27 +284,27 @@ describe('Unit: parser/processor/footnote', () => {
284
284
  [
285
285
  html('p', [
286
286
  html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:1", title: "b" }, [
287
- html('span', { hidden: '' }),
288
- html('a', { href: "#reference::def:1" }, '[a]')
287
+ html('span', { hidden: '' }, 'b'),
288
+ html('a', { href: "#reference::def:a" }, '[a]')
289
289
  ]),
290
290
  html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:2", title: "b" }, [
291
- html('span', { hidden: '' }, 'b'),
292
- html('a', { href: "#reference::def:1" }, '[a]')
291
+ html('span', { hidden: '' }),
292
+ html('a', { href: "#reference::def:a" }, '[a]')
293
293
  ]),
294
294
  html('sup', { class: "reference", 'data-abbr': "a", id: "reference::ref:3", title: "b" }, [
295
295
  html('span', { hidden: '' }),
296
- html('a', { href: "#reference::def:1" }, '[a]')
296
+ html('a', { href: "#reference::def:a" }, '[a]')
297
297
  ]),
298
298
  ]).outerHTML,
299
299
  ]);
300
300
  assert.deepStrictEqual(
301
301
  footnote.outerHTML,
302
302
  html('ol', [
303
- html('li', { id: 'reference::def:1' }, [
304
- html('span', { id: 'note::b' }, 'b'),
303
+ html('li', { id: 'reference::def:a' }, [
304
+ html('span', 'b'),
305
305
  html('sup', [
306
- html('a', { href: '#reference::ref:1' }, '^1'),
307
- html('a', { href: '#reference::ref:2', title: 'b' }, '^2'),
306
+ html('a', { href: '#reference::ref:1', title: 'b' }, '^1'),
307
+ html('a', { href: '#reference::ref:2' }, '^2'),
308
308
  html('a', { href: '#reference::ref:3' }, '^3'),
309
309
  ])
310
310
  ]),
@@ -12,8 +12,8 @@ export function* footnote(
12
12
  const el = es[i];
13
13
  el.parentNode === target && el.remove();
14
14
  }
15
- yield* reference(target, footnotes?.references, opts, bottom);
16
15
  yield* annotation(target, footnotes?.annotations, opts, bottom);
16
+ yield* reference(target, footnotes?.references, opts, bottom);
17
17
  return;
18
18
  }
19
19
 
@@ -44,25 +44,16 @@ function build(
44
44
  }
45
45
  const refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`);
46
46
  const titles = new Map<string, string>();
47
- const contents = new Map<string, HTMLSpanElement>();
48
- for (let len = refs.length, i = 0; i < len; ++i) {
49
- if (i % 10 === 9) yield;
50
- const ref = refs[i];
51
- const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild!.innerHTML}`;
52
- if (titles.has(identifier)) continue;
53
- const content = html('span',
54
- { id: identity(opts.id, text(ref.firstElementChild!), 'note') },
55
- ref.firstElementChild!.cloneNode(true).childNodes);
56
- const title = text(content).trim();
57
- if (!title) continue;
58
- titles.set(identifier, title);
59
- contents.set(identifier, content);
60
- }
47
+ const indexes = new Map<HTMLLIElement, number>();
61
48
  let count = 0;
62
49
  let total = 0;
63
50
  let style: 'count' | 'abbr';
64
51
  for (let len = refs.length, i = 0; i < len; ++i) {
65
52
  const ref = refs[i];
53
+ if (ref.closest('[hidden]')) {
54
+ yield;
55
+ continue;
56
+ }
66
57
  while (splitters.length > 0
67
58
  && splitters[0].compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING) {
68
59
  if (defs.size > 0) {
@@ -74,8 +65,13 @@ function build(
74
65
  }
75
66
  splitters.shift();
76
67
  }
77
- const identifier = ref.getAttribute('data-abbr') || ` ${ref.firstElementChild!.innerHTML}`;
78
68
  const abbr = ref.getAttribute('data-abbr') || undefined;
69
+ const identifier = abbr || identity(undefined, text(ref.firstElementChild!), 'mark')?.slice(6) || '';
70
+ const title = undefined
71
+ || titles.get(identifier)
72
+ || titles.set(identifier, text(ref.firstElementChild!)).get(identifier)!
73
+ || null;
74
+ assert(syntax !== 'annotation' || title);
79
75
  style ??= abbr ? 'abbr' : 'count';
80
76
  if (style === 'count' ? abbr : !abbr) {
81
77
  define(ref, {
@@ -99,9 +95,6 @@ function build(
99
95
  else {
100
96
  ref.lastChild?.remove();
101
97
  }
102
- const title = titles.get(identifier);
103
- assert(title !== '');
104
- assert(syntax !== 'annotation' || title);
105
98
  const refIndex = ++count;
106
99
  const refId = opts.id !== ''
107
100
  ? `${syntax}:${opts.id ?? ''}:ref:${refIndex}`
@@ -110,24 +103,26 @@ function build(
110
103
  || defs.get(identifier)
111
104
  || defs.set(identifier, html('li',
112
105
  {
113
- id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${total + defs.size + 1}` : undefined,
106
+ id: opts.id !== '' ? `${syntax}:${opts.id ?? ''}:def:${identifier}` : undefined,
114
107
  'data-marker': !footnote ? marker(total + defs.size + 1, abbr) : undefined,
115
108
  },
116
- [contents.get(identifier) ?? frag(), html('sup')]))
109
+ [define(ref.firstElementChild!.cloneNode(true), { hidden: null }), html('sup')]))
117
110
  .get(identifier)!;
118
111
  assert(def.lastChild);
119
- const defIndex = +def.id.slice(def.id.lastIndexOf(':') + 1) || total + defs.size;
112
+ const defIndex = undefined
113
+ || indexes.get(def)
114
+ || indexes.set(def, total + defs.size).get(def)!;
120
115
  const defId = def.id || undefined;
121
116
  define(ref, {
122
117
  id: refId,
123
- class: opts.id !== '' ? undefined : `${ref.className} disabled`,
124
- ...title
125
- ? { title }
126
- : { class: void ref.classList.add('invalid'),
127
- 'data-invalid-syntax': syntax,
128
- 'data-invalid-type': 'content',
129
- 'data-invalid-message': 'Missing the content',
130
- },
118
+ class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
119
+ title,
120
+ ...!title && {
121
+ class: void ref.classList.add('invalid'),
122
+ 'data-invalid-syntax': syntax,
123
+ 'data-invalid-type': 'content',
124
+ 'data-invalid-message': 'Missing the content',
125
+ },
131
126
  });
132
127
  yield ref.appendChild(html('a', { href: refId && defId && `#${defId}` }, marker(defIndex, abbr)));
133
128
  assert(ref.title || ref.matches('.invalid'));
package/tsconfig.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "compilerOptions": {
3
3
  "target": "ES2021",
4
4
  "lib": [
5
- "ES2021",
5
+ "ES2022",
6
6
  "DOM",
7
7
  "DOM.Iterable"
8
8
  ],
@@ -18,6 +18,7 @@
18
18
  "noImplicitOverride": true,
19
19
  "noPropertyAccessFromIndexSignature": true,
20
20
  "suppressImplicitAnyIndexErrors": true,
21
+ "ignoreDeprecations": "5.0",
21
22
  "noFallthroughCasesInSwitch": true,
22
23
  "noErrorTruncation": true,
23
24
  "forceConsistentCasingInFileNames": true
package/webpack.config.js CHANGED
@@ -33,7 +33,7 @@ module.exports = env => {
33
33
  resolve: {
34
34
  extensions: ['.ts', '.js'],
35
35
  },
36
- entry: glob.sync('./{src,test}/**/*.ts'),
36
+ entry: glob.sync('./{src,test}/**/*.ts', { absolute: true }).sort(),
37
37
  output: {
38
38
  filename: 'index.js',
39
39
  path: path.resolve(__dirname, 'dist'),
@@ -81,7 +81,7 @@ module.exports = env => {
81
81
  return merge(config);
82
82
  case 'lint':
83
83
  return merge(config, {
84
- entry: glob.sync('./!(node_modules)/**/*.ts'),
84
+ entry: glob.sync('./!(node_modules)/**/*.ts', { absolute: true }),
85
85
  plugins: [
86
86
  new ESLintPlugin({
87
87
  extensions: ['ts'],
@@ -90,7 +90,7 @@ module.exports = env => {
90
90
  });
91
91
  case 'bench':
92
92
  return merge(config, {
93
- entry: glob.sync('./benchmark/**/*.ts'),
93
+ entry: glob.sync('./benchmark/**/*.ts', { absolute: true }).sort(),
94
94
  module: {
95
95
  rules: [
96
96
  {
@@ -109,7 +109,7 @@ module.exports = env => {
109
109
  });
110
110
  case 'dist':
111
111
  return merge(config, {
112
- entry: glob.sync('./index.ts'),
112
+ entry: glob.sync('./index.ts', { absolute: true }),
113
113
  module: {
114
114
  rules: [
115
115
  {