securemark 0.274.2 → 0.274.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.eslintrc.json CHANGED
@@ -20,8 +20,6 @@
20
20
  "maxSimpleRepeatCount": 256,
21
21
  "attackTimeout": null,
22
22
  "incubationTimeout": null,
23
- "recallTimeout": null,
24
- "seedingTimeout": null,
25
23
  "timeout": 1e6
26
24
  }
27
25
  ]
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.274.4
4
+
5
+ - Fix list item parser.
6
+
7
+ ## 0.274.3
8
+
9
+ - Fix abbr parser.
10
+
3
11
  ## 0.274.2
4
12
 
5
13
  - Fix identifiers of notes.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.274.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.274.4 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"));
@@ -5259,6 +5259,7 @@ const combinator_1 = __webpack_require__(2087);
5259
5259
  const ulist_1 = __webpack_require__(5425);
5260
5260
  const ilist_1 = __webpack_require__(238);
5261
5261
  const inline_1 = __webpack_require__(1160);
5262
+ const index_1 = __webpack_require__(4479);
5262
5263
  const source_1 = __webpack_require__(6743);
5263
5264
  const visibility_1 = __webpack_require__(7618);
5264
5265
  const memoize_1 = __webpack_require__(1808);
@@ -5269,8 +5270,11 @@ const openers = {
5269
5270
  '(': /^\(([0-9]*|[a-z]*)(?![^)\n])\)?(?:-(?!-)[0-9]*)*(?:$|\s)/
5270
5271
  };
5271
5272
  exports.olist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(new RegExp([/^([0-9]+|[a-z]+|[A-Z]+)(?:-[0-9]+)*\.(?=[^\S\n]|\n[^\S\n]*\S)/.source, /^\(([0-9]+|[a-z]+)\)(?:-[0-9]+)*(?=[^\S\n]|\n[^\S\n]*\S)/.source].join('|')), (0, combinator_1.state)(8 /* State.media */, exports.olist_))));
5272
- exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => index(ms[1]), [])), (0, combinator_1.match)(openers['('], (0, memoize_1.memoize)(ms => list(type(ms[1]), '('), ms => index(ms[1]), []))])));
5273
- const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, visibility_1.trimBlank)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), exports.invalid), ns => [(0, dom_1.html)('li', {
5273
+ exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])), (0, combinator_1.match)(openers['('], (0, memoize_1.memoize)(ms => list(type(ms[1]), '('), ms => idx(ms[1]), []))])));
5274
+ const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, combinator_1.union)([(0, combinator_1.trim)((0, combinator_1.fmap)((0, combinator_1.close)((0, combinator_1.union)([index_1.index]), /^$/), ([el]) => [(0, dom_1.define)(el, {
5275
+ class: void el.classList.add('indexer'),
5276
+ 'data-index': ''
5277
+ })])), (0, visibility_1.trimBlank)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))])]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), exports.invalid), ns => [(0, dom_1.html)('li', {
5274
5278
  'data-marker': ns[0] || undefined
5275
5279
  }, (0, dom_1.defrag)((0, ulist_1.fillFirstLine)((0, array_1.shift)(ns)[1])))]), true)]))), es => [format((0, dom_1.html)('ol', es), type, form)]);
5276
5280
  const heads = {
@@ -5291,7 +5295,7 @@ exports.invalid = (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.co
5291
5295
  'data-invalid-type': 'syntax',
5292
5296
  'data-invalid-message': 'Fix the indent or the head of the list item'
5293
5297
  }, source.replace('\n', ''))], '']);
5294
- function index(value) {
5298
+ function idx(value) {
5295
5299
  switch (value) {
5296
5300
  case 'i':
5297
5301
  return 1;
@@ -5632,11 +5636,15 @@ const combinator_1 = __webpack_require__(2087);
5632
5636
  const olist_1 = __webpack_require__(7471);
5633
5637
  const ilist_1 = __webpack_require__(238);
5634
5638
  const inline_1 = __webpack_require__(1160);
5639
+ const index_1 = __webpack_require__(4479);
5635
5640
  const visibility_1 = __webpack_require__(7618);
5636
5641
  const array_1 = __webpack_require__(8112);
5637
5642
  const dom_1 = __webpack_require__(3252);
5638
5643
  exports.ulist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(/^-(?=[^\S\n]|\n[^\S\n]*\S)/, (0, combinator_1.state)(8 /* State.media */, exports.ulist_))));
5639
- exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^-(?=$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^-(?:$|\s)/, (0, combinator_1.subsequence)([exports.checkbox, (0, visibility_1.trimBlank)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([exports.ulist_, olist_1.olist_, ilist_1.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)(fillFirstLine(ns)))]), true)])))), es => [format((0, dom_1.html)('ul', es))])));
5644
+ exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^-(?=$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^-(?:$|\s)/, (0, combinator_1.subsequence)([exports.checkbox, (0, combinator_1.union)([(0, combinator_1.trim)((0, combinator_1.fmap)((0, combinator_1.close)((0, combinator_1.union)([index_1.index]), /^$/), ([el]) => [(0, dom_1.define)(el, {
5645
+ class: void el.classList.add('indexer'),
5646
+ 'data-index': ''
5647
+ })])), (0, visibility_1.trimBlank)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline]))))])]), true)), (0, combinator_1.indent)((0, combinator_1.union)([exports.ulist_, olist_1.olist_, ilist_1.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)(fillFirstLine(ns)))]), true)])))), es => [format((0, dom_1.html)('ul', es))])));
5640
5648
  exports.checkbox = (0, combinator_1.creation)(1, false, (0, combinator_1.focus)(/^\[[xX ]\](?=$|\s)/, ({
5641
5649
  source
5642
5650
  }) => [[(0, dom_1.html)('span', {
@@ -6143,7 +6151,7 @@ exports.index = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[#', (0
6143
6151
  id: el.id ? null : undefined,
6144
6152
  class: 'index',
6145
6153
  href: el.id ? `#${el.id}` : undefined
6146
- }, el.childNodes)])));
6154
+ })])));
6147
6155
  const signature = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.fmap)((0, combinator_1.open)('|', (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([bracket, source_1.txt]), ']'))), ns => [(0, dom_1.html)('span', {
6148
6156
  class: 'indexer',
6149
6157
  'data-index': (0, indexee_1.identity)(undefined, ns.join('')).slice(7)
@@ -6581,14 +6589,14 @@ const visibility_1 = __webpack_require__(7618);
6581
6589
  const array_1 = __webpack_require__(8112);
6582
6590
  const dom_1 = __webpack_require__(3252);
6583
6591
  exports.mark = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)('==', '='), (0, combinator_1.constraint)(4 /* State.mark */, false, (0, combinator_1.syntax)(0 /* Syntax.none */, 1, 1, 0 /* State.none */, (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('=='), [[/^\\?\n/, 9]]), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '=', [[/^\\?\n/, 9]]), exports.mark)]))))), (0, source_1.str)('=='), false, ([, bs], rest, {
6584
- id
6592
+ id,
6593
+ state
6585
6594
  }) => {
6586
6595
  const el = (0, dom_1.html)('mark', (0, dom_1.defrag)(bs));
6587
- (0, dom_1.define)(el, {
6588
- id: (0, indexee_1.identity)(id, (0, indexee_1.text)(el), 'mark')
6589
- });
6590
- return [[el, (0, dom_1.html)('a', {
6591
- href: el.id ? `#${el.id}` : undefined
6596
+ return [[(0, dom_1.define)(el, {
6597
+ id: state & (256 /* State.annotation */ | 128 /* State.reference */) ? undefined : (0, indexee_1.identity)(id, (0, indexee_1.text)(el), 'mark')
6598
+ }), el.id && (0, dom_1.html)('a', {
6599
+ href: `#${el.id}`
6592
6600
  })], rest];
6593
6601
  }, ([as, bs], rest) => [(0, array_1.unshift)(as, bs), rest]));
6594
6602
 
@@ -6727,22 +6735,31 @@ const combinator_1 = __webpack_require__(2087);
6727
6735
  const inline_1 = __webpack_require__(1160);
6728
6736
  const source_1 = __webpack_require__(6743);
6729
6737
  const visibility_1 = __webpack_require__(7618);
6730
- const util_1 = __webpack_require__(9437);
6731
6738
  const dom_1 = __webpack_require__(3252);
6732
6739
  exports.reference = (0, combinator_1.lazy)(() => (0, combinator_1.surround)('[[', (0, combinator_1.constraint)(128 /* State.reference */, false, (0, combinator_1.syntax)(256 /* Syntax.reference */, 6, 1, 256 /* State.annotation */ | 128 /* State.reference */ | 8 /* State.media */, (0, visibility_1.startLoose)((0, combinator_1.subsequence)([abbr, (0, combinator_1.fmap)((0, source_1.str)('^'), ns => ['', ...ns]), (0, combinator_1.some)(inline_1.inline, ']', [[/^\\?\n/, 9], [']', 2], [']]', 6]])]), ']'))), ']]', false, ([, ns], rest) => [[(0, dom_1.html)('sup', attributes(ns), [(0, dom_1.html)('span', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))])], rest]));
6733
- const abbr = (0, combinator_1.creation)((0, combinator_1.bind)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]), /^\|?(?=]])|^\|[^\S\n]*/), ([source], rest) => [[(0, dom_1.html)('abbr', source)], rest.replace(visibility_1.regBlankStart, '')]));
6740
+ // Chicago-Style
6741
+ const abbr = (0, combinator_1.creation)((0, combinator_1.bind)((0, combinator_1.surround)('^', (0, combinator_1.union)([(0, source_1.str)(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]), /^\|?(?=]])|^\|[^\S\n]*/), ([source], rest) => [['\n', source.trimEnd()], rest.replace(visibility_1.regBlankStart, '')]));
6734
6742
  function attributes(ns) {
6735
- return typeof ns[0] === 'object' && ns[0].tagName === 'ABBR' ? {
6736
- class: 'reference',
6737
- 'data-abbr': (0, util_1.stringify)([ns.shift()]).trimEnd()
6738
- } : ns[0] === '' ? {
6739
- class: 'invalid',
6740
- 'data-invalid-syntax': 'reference',
6741
- 'data-invalid-type': 'syntax',
6742
- 'data-invalid-message': 'Invalid abbr'
6743
- } : {
6744
- class: 'reference'
6745
- };
6743
+ switch (ns[0]) {
6744
+ case '':
6745
+ return {
6746
+ class: 'invalid',
6747
+ 'data-invalid-syntax': 'reference',
6748
+ 'data-invalid-type': 'syntax',
6749
+ 'data-invalid-message': 'Invalid abbreviation'
6750
+ };
6751
+ case '\n':
6752
+ const abbr = ns[1];
6753
+ ns[0] = ns[1] = '';
6754
+ return {
6755
+ class: 'reference',
6756
+ 'data-abbr': abbr
6757
+ };
6758
+ default:
6759
+ return {
6760
+ class: 'reference'
6761
+ };
6762
+ }
6746
6763
  }
6747
6764
 
6748
6765
  /***/ }),
@@ -7069,39 +7086,35 @@ function build(syntax, marker, splitter = '') {
7069
7086
  // 構文ごとに各1回の処理では不可能
7070
7087
  return function* (target, note, opts = {}, bottom = null) {
7071
7088
  const defs = new Map();
7072
- const splitters = [];
7073
- for (let es = target.querySelectorAll(splitter || '_'), len = es.length, i = 0; i < len; ++i) {
7074
- if (i % 100 === 0) yield;
7075
- const el = es[i];
7076
- el.parentNode === target && splitters.push(el);
7077
- }
7078
7089
  const refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`);
7079
7090
  const titles = new Map();
7080
7091
  const defIndexes = new Map();
7081
7092
  const refSubindexes = new Map();
7082
- const defSubindexes = splitter ? new Map() : undefined;
7093
+ const defSubindexes = splitter && refs.length > 0 ? new Map() : undefined;
7094
+ const splitters = splitter && refs.length > 0 ? target.querySelectorAll(splitter) : [];
7095
+ let iSplitters = 0;
7083
7096
  let total = 0;
7084
7097
  let format;
7085
7098
  let refIndex = 0;
7086
7099
  for (let len = refs.length, i = 0; i < len; ++i) {
7087
7100
  const ref = refs[i];
7088
- if (ref.closest('[hidden]')) {
7101
+ if (ref.closest('sup > [hidden]')) {
7089
7102
  yield;
7090
7103
  continue;
7091
7104
  }
7092
- while (splitters.length > 0 && splitters[0].compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING) {
7105
+ if (splitter) for (let el; (el = splitters[iSplitters])?.compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING; ++iSplitters) {
7106
+ if (el.parentNode !== target) continue;
7093
7107
  if (defs.size > 0) {
7094
7108
  total += defs.size;
7095
7109
  yield* proc(defs, target.insertBefore((0, dom_1.html)('ol', {
7096
7110
  class: `${syntax}s`
7097
- }), splitters[0]));
7098
- } else if (splitters.length % 100 === 0) {
7111
+ }), el));
7112
+ } else if (~iSplitters % 128 === 0) {
7099
7113
  yield;
7100
7114
  }
7101
- splitters.shift();
7102
7115
  }
7103
7116
  const abbr = ref.getAttribute('data-abbr') || undefined;
7104
- const identifier = abbr || (0, indexee_1.identity)(undefined, (0, indexee_1.text)(ref.firstElementChild), 'mark')?.slice(6) || '';
7117
+ const identifier = (0, indexee_1.identity)(undefined, abbr ? abbr.match(/^(?:\S+ )+?(?:(?:January|February|March|April|May|June|August|September|October|November|December) \d{1,2}(?:-\d{0,2})?, \d{1,4}(?:-\d{0,4})?[a-z]?|n\.d\.)(?=,|$)/)?.[0] ?? abbr.match(/^[^,\s]+(?:,? [^,\s]+)*?(?: \d{1,4}(?:-\d{0,4})?[a-z]?(?=,|$)|(?=,(?: [a-z]+\.?)? [0-9]))/)?.[0] ?? abbr : (0, indexee_1.text)(ref.firstElementChild), 'mark')?.slice(6) || '';
7105
7118
  const refSubindex = refSubindexes.get(identifier) + 1 || 1;
7106
7119
  refSubindexes.set(identifier, refSubindex);
7107
7120
  const refId = opts.id !== '' ? `${syntax}:${opts.id ?? ''}:ref:${identifier}:${refSubindex}` : undefined;
@@ -7120,28 +7133,26 @@ function build(syntax, marker, splitter = '') {
7120
7133
  initial && defIndexes.set(def, defIndex);
7121
7134
  const title = initial ? (0, indexee_1.text)(ref.firstElementChild) : titles.get(identifier);
7122
7135
  initial && titles.set(identifier, title);
7123
- format ??= abbr ? 'abbr' : 'number';
7124
- if (!ref.classList.contains('invalid')) {
7125
- if (format === 'number' ? abbr : !abbr) {
7126
- (0, util_1.markInvalid)(ref, syntax, 'format', 'Notation format must be consistent with numbers or abbreviations');
7127
- }
7128
- } else switch (ref.getAttribute('data-invalid-syntax')) {
7129
- case 'format':
7130
- case 'content':
7131
- (0, util_1.unmarkInvalid)(ref);
7132
- }
7133
7136
  ref.firstElementChild.hasAttribute('hidden') ? ref.lastElementChild.remove() : ref.firstElementChild.setAttribute('hidden', '');
7134
7137
  (0, dom_1.define)(ref, {
7135
7138
  id: refId,
7136
7139
  class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
7137
- title,
7138
- ...(!title && {
7139
- class: void ref.classList.add('invalid'),
7140
- 'data-invalid-syntax': syntax,
7141
- 'data-invalid-type': 'content',
7142
- 'data-invalid-message': 'Missing the content'
7143
- })
7140
+ title
7144
7141
  });
7142
+ switch (ref.getAttribute('data-invalid-syntax')) {
7143
+ case 'format':
7144
+ case 'content':
7145
+ (0, util_1.unmarkInvalid)(ref);
7146
+ }
7147
+ format ??= abbr ? 'abbr' : 'number';
7148
+ if (!ref.classList.contains('invalid')) switch (true) {
7149
+ case format === 'number' ? !!abbr : !abbr:
7150
+ (0, util_1.markInvalid)(ref, syntax, 'format', 'Notation format must be consistent with numbers or abbreviations');
7151
+ break;
7152
+ case !title:
7153
+ (0, util_1.markInvalid)(ref, syntax, 'content', 'Missing the content');
7154
+ break;
7155
+ }
7145
7156
  yield ref.appendChild((0, dom_1.html)('a', {
7146
7157
  href: refId && defId && `#${defId}`
7147
7158
  }, marker(defIndex, abbr)));
@@ -7153,7 +7164,7 @@ function build(syntax, marker, splitter = '') {
7153
7164
  if (note || defs.size > 0) {
7154
7165
  yield* proc(defs, note ?? target.insertBefore((0, dom_1.html)('ol', {
7155
7166
  class: `${syntax}s`
7156
- }), splitters[0] ?? bottom));
7167
+ }), splitters[iSplitters] ?? bottom));
7157
7168
  }
7158
7169
  return;
7159
7170
  };
@@ -8406,7 +8417,7 @@ function unlink(h) {
8406
8417
  /***/ 3252:
8407
8418
  /***/ (function(module) {
8408
8419
 
8409
- /*! typed-dom v0.0.330 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8420
+ /*! typed-dom v0.0.333 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8410
8421
  (function webpackUniversalModuleDefinition(root, factory) {
8411
8422
  if(true)
8412
8423
  module.exports = factory();
@@ -8519,7 +8530,7 @@ exports.reduce = reduce;
8519
8530
  Object.defineProperty(exports, "__esModule", ({
8520
8531
  value: true
8521
8532
  }));
8522
- exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
8533
+ exports.defrag = exports.prepend = exports.append = exports.isChildren = exports.define = exports.element = exports.text = exports.math = exports.svg = exports.html = exports.frag = exports.shadow = void 0;
8523
8534
  const alias_1 = __nested_webpack_require_4668__(5406);
8524
8535
  const memoize_1 = __nested_webpack_require_4668__(1808);
8525
8536
  var caches;
@@ -8544,6 +8555,7 @@ function frag(children) {
8544
8555
  exports.frag = frag;
8545
8556
  exports.html = element(document, "HTML" /* NS.HTML */);
8546
8557
  exports.svg = element(document, "SVG" /* NS.SVG */);
8558
+ exports.math = element(document, "MathML" /* NS.Math */);
8547
8559
  function text(source) {
8548
8560
  return document.createTextNode(source);
8549
8561
  }
@@ -8555,7 +8567,7 @@ function element(context, ns) {
8555
8567
  }
8556
8568
  exports.element = element;
8557
8569
  function elem(context, ns, tag, attrs) {
8558
- if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser.`);
8570
+ if (!('createElement' in context)) throw new Error(`TypedDOM: Scoped custom elements are not supported on this browser`);
8559
8571
  const opts = 'is' in attrs ? {
8560
8572
  is: attrs['is']
8561
8573
  } : undefined;
@@ -8564,7 +8576,7 @@ function elem(context, ns, tag, attrs) {
8564
8576
  return context.createElement(tag, opts);
8565
8577
  case "SVG" /* NS.SVG */:
8566
8578
  return context.createElementNS('http://www.w3.org/2000/svg', tag, opts);
8567
- case "MathML" /* NS.MathML */:
8579
+ case "MathML" /* NS.Math */:
8568
8580
  return context.createElementNS('http://www.w3.org/1998/Math/MathML', tag, opts);
8569
8581
  }
8570
8582
  }
@@ -8606,10 +8618,10 @@ function defineAttrs(el, attrs) {
8606
8618
  }
8607
8619
  continue;
8608
8620
  case 'function':
8609
- if (name.length < 3) throw new Error(`TypedDOM: Attribute names for event listeners must have an event name but got "${name}".`);
8621
+ if (name.length < 3) throw new Error(`TypedDOM: Attribute names for event listeners must have an event name but got "${name}"`);
8610
8622
  const names = name.split(/\s+/);
8611
8623
  for (const name of names) {
8612
- if (!name.startsWith('on')) throw new Error(`TypedDOM: Attribute names for event listeners must start with "on" but got "${name}".`);
8624
+ if (!name.startsWith('on')) throw new Error(`TypedDOM: Attribute names for event listeners must start with "on" but got "${name}"`);
8613
8625
  const type = name.slice(2).toLowerCase();
8614
8626
  el.addEventListener(type, value, {
8615
8627
  passive: ['wheel', 'mousewheel', 'touchstart', 'touchmove', 'touchend', 'touchcancel'].includes(type)
@@ -8705,7 +8717,7 @@ exports.defrag = defrag;
8705
8717
  /******/ var __webpack_module_cache__ = {};
8706
8718
  /******/
8707
8719
  /******/ // The require function
8708
- /******/ function __nested_webpack_require_11589__(moduleId) {
8720
+ /******/ function __nested_webpack_require_11657__(moduleId) {
8709
8721
  /******/ // Check if module is in cache
8710
8722
  /******/ var cachedModule = __webpack_module_cache__[moduleId];
8711
8723
  /******/ if (cachedModule !== undefined) {
@@ -8719,7 +8731,7 @@ exports.defrag = defrag;
8719
8731
  /******/ };
8720
8732
  /******/
8721
8733
  /******/ // Execute the module function
8722
- /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11589__);
8734
+ /******/ __webpack_modules__[moduleId](module, module.exports, __nested_webpack_require_11657__);
8723
8735
  /******/
8724
8736
  /******/ // Return the exports of the module
8725
8737
  /******/ return module.exports;
@@ -8730,7 +8742,7 @@ exports.defrag = defrag;
8730
8742
  /******/ // startup
8731
8743
  /******/ // Load entry module and return exports
8732
8744
  /******/ // This entry module is referenced by other modules so it can't be inlined
8733
- /******/ var __nested_webpack_exports__ = __nested_webpack_require_11589__(7521);
8745
+ /******/ var __nested_webpack_exports__ = __nested_webpack_require_11657__(7521);
8734
8746
  /******/
8735
8747
  /******/ return __nested_webpack_exports__;
8736
8748
  /******/ })()
@@ -8742,7 +8754,7 @@ exports.defrag = defrag;
8742
8754
  /***/ 6120:
8743
8755
  /***/ (function(module) {
8744
8756
 
8745
- /*! typed-dom v0.0.330 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8757
+ /*! typed-dom v0.0.333 https://github.com/falsandtru/typed-dom | (c) 2016, falsandtru | (Apache-2.0 AND MPL-2.0) License */
8746
8758
  (function webpackUniversalModuleDefinition(root, factory) {
8747
8759
  if(true)
8748
8760
  module.exports = factory();
package/markdown.d.ts CHANGED
@@ -118,8 +118,13 @@ export namespace MarkdownParser {
118
118
  Parser<HTMLElement | string, Context, [
119
119
  InlineParser,
120
120
  Parser<HTMLElement | string, Context, [
121
- InlineParser.ExtensionParser.IndexerParser,
122
- InlineParser,
121
+ Parser<HTMLElement, Context, [
122
+ InlineParser.ExtensionParser.IndexParser,
123
+ ]>,
124
+ Parser<HTMLElement | string, Context, [
125
+ InlineParser.ExtensionParser.IndexerParser,
126
+ InlineParser,
127
+ ]>,
123
128
  ]>,
124
129
  ]>,
125
130
  Parser<HTMLUListElement | HTMLOListElement, Context, [
@@ -153,8 +158,13 @@ export namespace MarkdownParser {
153
158
  Parser<HTMLElement | string, Context, [
154
159
  InlineParser,
155
160
  Parser<HTMLElement | string, Context, [
156
- InlineParser.ExtensionParser.IndexerParser,
157
- InlineParser,
161
+ Parser<HTMLElement, Context, [
162
+ InlineParser.ExtensionParser.IndexParser,
163
+ ]>,
164
+ Parser<HTMLElement | string, Context, [
165
+ InlineParser.ExtensionParser.IndexerParser,
166
+ InlineParser,
167
+ ]>,
158
168
  ]>,
159
169
  ]>,
160
170
  Parser<HTMLUListElement | HTMLOListElement, Context, [
@@ -658,8 +668,8 @@ export namespace MarkdownParser {
658
668
  }
659
669
  export interface ReferenceParser extends
660
670
  // [[abc]]
661
- // [[^abbr]]
662
- // [[^abbr| abc]]
671
+ // [[^Abbr]]
672
+ // [[^Abbr| abc]]
663
673
  Inline<'reference'>,
664
674
  Parser<HTMLElement, Context, [
665
675
  ReferenceParser.AbbrParser,
@@ -669,11 +679,10 @@ export namespace MarkdownParser {
669
679
  }
670
680
  export namespace ReferenceParser {
671
681
  export interface AbbrParser extends
672
- // ^Xyz2020
673
- // ^X, 2020, p1-2
674
- // ^X. Y., Z et al., 2020, p1-2
682
+ // ^X 2020, 1-2
683
+ // ^X. Y., and Z et al. 2020, 1-2
675
684
  Inline<'reference/abbr'>,
676
- Parser<HTMLElement, Context, [
685
+ Parser<string, Context, [
677
686
  SourceParser.StrParser,
678
687
  ]> {
679
688
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.274.2",
3
+ "version": "0.274.4",
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",
@@ -34,14 +34,14 @@
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.59.0",
37
+ "@typescript-eslint/parser": "^5.59.5",
38
38
  "babel-loader": "^9.1.2",
39
39
  "babel-plugin-unassert": "^3.2.0",
40
40
  "concurrently": "^8.0.1",
41
- "eslint": "^8.39.0",
41
+ "eslint": "^8.40.0",
42
42
  "eslint-plugin-redos": "^4.4.5",
43
43
  "eslint-webpack-plugin": "^4.0.1",
44
- "glob": "^10.2.1",
44
+ "glob": "^10.2.3",
45
45
  "karma": "^6.4.2",
46
46
  "karma-chrome-launcher": "^3.2.0",
47
47
  "karma-coverage": "^2.2.0",
@@ -49,14 +49,14 @@
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.10.9",
52
+ "npm-check-updates": "^16.10.12",
53
53
  "semver": "^7.5.0",
54
54
  "spica": "0.0.721",
55
55
  "ts-loader": "^9.4.2",
56
- "typed-dom": "^0.0.330",
56
+ "typed-dom": "^0.0.333",
57
57
  "typescript": "5.0.4",
58
- "webpack": "^5.80.0",
59
- "webpack-cli": "^5.0.2",
58
+ "webpack": "^5.82.0",
59
+ "webpack-cli": "^5.1.1",
60
60
  "webpack-merge": "^5.8.0"
61
61
  },
62
62
  "scripts": {
@@ -204,15 +204,80 @@ describe('Unit: parser/api/parse', () => {
204
204
  it('note', () => {
205
205
  const notes = { references: html('ol') };
206
206
  assert.deepStrictEqual(
207
- [...parse('$-a\n$$\n$$\n\n(($-a[[^b]]))[[^b|$-a]]', { notes }).children].map(el => el.outerHTML),
207
+ [...parse('$-a\n$$\n$$\n\n(($-a[[^B]]))[[^B|$-a]]', { notes }).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):1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="b"><span></span></sup></span><a href="#annotation::def:(1):1">*1</a></sup><sup class="reference" data-abbr="b" id="reference::ref:b:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><a href="#reference::def:b">[b]</a></sup></p>',
211
- '<ol class="annotations"><li id="annotation::def:(1):1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="b" id="reference::ref:b:2" title="(1)"><span hidden=""></span><a href="#reference::def:b">[b]</a></sup></span><sup><a href="#annotation::ref:(1):1">^1</a></sup></li></ol>',
210
+ '<p><sup class="annotation" id="annotation::ref:(1):1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B"><span></span></sup></span><a href="#annotation::def:(1):1">*1</a></sup><sup class="reference" data-abbr="B" id="reference::ref:B:1" title="(1)"><span hidden=""><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><a href="#reference::def:B">[B]</a></sup></p>',
211
+ '<ol class="annotations"><li id="annotation::def:(1):1" data-marker="*1"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a><sup class="reference" data-abbr="B" id="reference::ref:B:2" title="(1)"><span hidden=""></span><a href="#reference::def:B">[B]</a></sup></span><sup><a href="#annotation::ref:(1):1">^1</a></sup></li></ol>',
212
212
  ]);
213
213
  assert.deepStrictEqual(
214
214
  notes.references.outerHTML,
215
- '<ol><li id="reference::def:b"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><sup><a href="#reference::ref:b:1" title="(1)">^1</a><a href="#reference::ref:b:2">^2</a></sup></li></ol>');
215
+ '<ol><li id="reference::def:B"><span><a class="label" data-label="$-a" href="#label:$-a">(1)</a></span><sup><a href="#reference::ref:B:1" title="(1)">^1</a><a href="#reference::ref:B:2">^2</a></sup></li></ol>');
216
+ assert.deepStrictEqual(
217
+ [...parse([
218
+ '[[^A 1|b]]',
219
+ '[[^A 1,|b]]',
220
+ '[[^A 1, |b]]',
221
+ '[[^Xyz 2020|b]]',
222
+ '[[^Xyz 2020, 1|b]]',
223
+ '[[^Xyz 2020, 1, 2|b]]',
224
+ '[[^Xyz 2020, 1, fig. 1.1|b]]',
225
+ '[[^Xyz 2020, 1, fig. 1.1-2.1b|b]]',
226
+ '[[^Xyz 2020, 1, fig. 1.1a-b|b]]',
227
+ '[[^Xyz 2020, 1-2|b]]',
228
+ '[[^Xyz 2020, 1:1-2|b]]',
229
+ '[[^Xyz 2020, 1n|b]]',
230
+ '[[^Xyz 2020, 1n1|b]]',
231
+ '[[^Xyz 2020, 1nn1-2|b]]',
232
+ '[[^Xyz 2020, i|b]]',
233
+ '[[^Xyz 2020, capter 1|b]]',
234
+ '[[^Xyz 2020, cap. 1|b]]',
235
+ '[[^Xyz 2020a|b]]',
236
+ '[[^Xyz 2020a, 1|b]]',
237
+ '[[^Xyz 2020-2021a|b]]',
238
+ '[[^Xyz 2020-2021a, 1|b]]',
239
+ '[[^Xyz, April 1, 2020|b]]',
240
+ '[[^Xyz, April 1, 2020, 1|b]]',
241
+ '[[^Xyz n.d.|b]]',
242
+ '[[^Xyz n.d., 1|b]]',
243
+ '[[^X. Y., and Z et al. 2020, 1-2|b]]',
244
+ '[[^A title 2020|b]]',
245
+ '[[^A title 2020, 1|b]]',
246
+ '[[^Constitution, art. 2|b]]',
247
+ '[[^Constitution, art. 2, sec. 1|b]]',
248
+ ].join('\n\n'), { notes }).children].map(el => el.outerHTML),
249
+ [
250
+ '<p><sup class="reference" data-abbr="A 1" id="reference::ref:A_1:1" title="b"><span hidden="">b</span><a href="#reference::def:A_1">[A 1]</a></sup></p>',
251
+ '<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:2" title="b"><span hidden="">b</span><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
252
+ '<p><sup class="reference" data-abbr="A 1," id="reference::ref:A_1:3" title="b"><span hidden="">b</span><a href="#reference::def:A_1">[A 1,]</a></sup></p>',
253
+ '<p><sup class="reference" data-abbr="Xyz 2020" id="reference::ref:Xyz_2020:1" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020]</a></sup></p>',
254
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1" id="reference::ref:Xyz_2020:2" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1]</a></sup></p>',
255
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, 2" id="reference::ref:Xyz_2020:3" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, 2]</a></sup></p>',
256
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1" id="reference::ref:Xyz_2020:4" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1]</a></sup></p>',
257
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b" id="reference::ref:Xyz_2020:5" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1-2.1b]</a></sup></p>',
258
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b" id="reference::ref:Xyz_2020:6" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1, fig. 1.1a-b]</a></sup></p>',
259
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1-2" id="reference::ref:Xyz_2020:7" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1-2]</a></sup></p>',
260
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1:1-2" id="reference::ref:Xyz_2020:8" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1:1-2]</a></sup></p>',
261
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1n" id="reference::ref:Xyz_2020:9" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n]</a></sup></p>',
262
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1n1" id="reference::ref:Xyz_2020:10" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1n1]</a></sup></p>',
263
+ '<p><sup class="reference" data-abbr="Xyz 2020, 1nn1-2" id="reference::ref:Xyz_2020:11" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, 1nn1-2]</a></sup></p>',
264
+ '<p><sup class="reference" data-abbr="Xyz 2020, i" id="reference::ref:Xyz_2020:12" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, i]</a></sup></p>',
265
+ '<p><sup class="reference" data-abbr="Xyz 2020, capter 1" id="reference::ref:Xyz_2020:13" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, capter 1]</a></sup></p>',
266
+ '<p><sup class="reference" data-abbr="Xyz 2020, cap. 1" id="reference::ref:Xyz_2020:14" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020">[Xyz 2020, cap. 1]</a></sup></p>',
267
+ '<p><sup class="reference" data-abbr="Xyz 2020a" id="reference::ref:Xyz_2020a:1" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020a">[Xyz 2020a]</a></sup></p>',
268
+ '<p><sup class="reference" data-abbr="Xyz 2020a, 1" id="reference::ref:Xyz_2020a:2" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020a">[Xyz 2020a, 1]</a></sup></p>',
269
+ '<p><sup class="reference" data-abbr="Xyz 2020-2021a" id="reference::ref:Xyz_2020-2021a:1" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a]</a></sup></p>',
270
+ '<p><sup class="reference" data-abbr="Xyz 2020-2021a, 1" id="reference::ref:Xyz_2020-2021a:2" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_2020-2021a">[Xyz 2020-2021a, 1]</a></sup></p>',
271
+ '<p><sup class="reference" data-abbr="Xyz, April 1, 2020" id="reference::ref:Xyz,_April_1,_2020:1" title="b"><span hidden="">b</span><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020]</a></sup></p>',
272
+ '<p><sup class="reference" data-abbr="Xyz, April 1, 2020, 1" id="reference::ref:Xyz,_April_1,_2020:2" title="b"><span hidden="">b</span><a href="#reference::def:Xyz,_April_1,_2020">[Xyz, April 1, 2020, 1]</a></sup></p>',
273
+ '<p><sup class="reference" data-abbr="Xyz n.d." id="reference::ref:Xyz_n.d.:1" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_n.d.">[Xyz n.d.]</a></sup></p>',
274
+ '<p><sup class="reference" data-abbr="Xyz n.d., 1" id="reference::ref:Xyz_n.d.:2" title="b"><span hidden="">b</span><a href="#reference::def:Xyz_n.d.">[Xyz n.d., 1]</a></sup></p>',
275
+ '<p><sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2" id="reference::ref:X._Y.,_and_Z_et_al._2020:1" title="b"><span hidden="">b</span><a href="#reference::def:X._Y.,_and_Z_et_al._2020">[X. Y., and Z et al. 2020, 1-2]</a></sup></p>',
276
+ '<p><sup class="reference" data-abbr="A title 2020" id="reference::ref:A_title_2020:1" title="b"><span hidden="">b</span><a href="#reference::def:A_title_2020">[A title 2020]</a></sup></p>',
277
+ '<p><sup class="reference" data-abbr="A title 2020, 1" id="reference::ref:A_title_2020:2" title="b"><span hidden="">b</span><a href="#reference::def:A_title_2020">[A title 2020, 1]</a></sup></p>',
278
+ '<p><sup class="reference" data-abbr="Constitution, art. 2" id="reference::ref:Constitution:1" title="b"><span hidden="">b</span><a href="#reference::def:Constitution">[Constitution, art. 2]</a></sup></p>',
279
+ '<p><sup class="reference" data-abbr="Constitution, art. 2, sec. 1" id="reference::ref:Constitution:2" title="b"><span hidden="">b</span><a href="#reference::def:Constitution">[Constitution, art. 2, sec. 1]</a></sup></p>',
280
+ ]);
216
281
  });
217
282
 
218
283
  it('normalize', () => {
@@ -127,10 +127,10 @@ describe('Unit: parser/block/olist', () => {
127
127
  });
128
128
 
129
129
  it('indexer', () => {
130
- assert.deepStrictEqual(inspect(parser('1. [#a]')), [['<ol><li id="index::a"><a class="index" href="#index::a">a</a></li></ol>'], '']);
130
+ assert.deepStrictEqual(inspect(parser('1. [#a]')), [['<ol><li><a class="index indexer" href="#index::a" data-index="">a</a></li></ol>'], '']);
131
131
  assert.deepStrictEqual(inspect(parser('1. a [#]')), [['<ol><li>a<span class="indexer" data-index=""></span></li></ol>'], '']);
132
132
  assert.deepStrictEqual(inspect(parser('1. a [#b]')), [['<ol><li id="index::b">a<span class="indexer" data-index="b"></span></li></ol>'], '']);
133
- assert.deepStrictEqual(inspect(parser('1. [ ] [#a]')), [['<ol class="checklist"><li id="index::a"><span class="checkbox">☐</span><a class="index" href="#index::a">a</a></li></ol>'], '']);
133
+ assert.deepStrictEqual(inspect(parser('1. [ ] [#a]')), [['<ol class="checklist"><li><span class="checkbox">☐</span><a class="index indexer" href="#index::a" data-index="">a</a></li></ol>'], '']);
134
134
  assert.deepStrictEqual(inspect(parser('1. [ ] a [#b]')), [['<ol class="checklist"><li id="index::b"><span class="checkbox">☐</span>a<span class="indexer" data-index="b"></span></li></ol>'], '']);
135
135
  assert.deepStrictEqual(inspect(parser('1. a [#]\n 1. c [#d]')), [['<ol><li>a<span class="indexer" data-index=""></span><ol><li id="index::d">c<span class="indexer" data-index="d"></span></li></ol></li></ol>'], '']);
136
136
  assert.deepStrictEqual(inspect(parser('1. a [#b]\n 1. c [#d]')), [['<ol><li id="index::b">a<span class="indexer" data-index="b"></span><ol><li id="index::d">c<span class="indexer" data-index="d"></span></li></ol></li></ol>'], '']);
@@ -1,9 +1,10 @@
1
1
  import { OListParser } from '../block';
2
2
  import { Parser } from '../../combinator/data/parser';
3
- import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, match, fallback, lazy, fmap } from '../../combinator';
3
+ import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, rewrite, open, close, match, trim, fallback, lazy, fmap } from '../../combinator';
4
4
  import { checkbox, ulist_, fillFirstLine } from './ulist';
5
5
  import { ilist_ } from './ilist';
6
6
  import { inline, indexee, indexer } from '../inline';
7
+ import { index } from '../inline/extension/index';
7
8
  import { contentline } from '../source';
8
9
  import { State } from '../context';
9
10
  import { visualize, trimBlank } from '../visibility';
@@ -27,17 +28,22 @@ export const olist: OListParser = lazy(() => block(validate(
27
28
  export const olist_: OListParser = lazy(() => block(union([
28
29
  match(
29
30
  openers['.'],
30
- memoize(ms => list(type(ms[1]), '.'), ms => index(ms[1]), [])),
31
+ memoize(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])),
31
32
  match(
32
33
  openers['('],
33
- memoize(ms => list(type(ms[1]), '('), ms => index(ms[1]), [])),
34
+ memoize(ms => list(type(ms[1]), '('), ms => idx(ms[1]), [])),
34
35
  ])));
35
36
 
36
37
  const list = (type: string, form: string): OListParser.ListParser => fmap(
37
38
  some(creation(1, false, union([
38
39
  indexee(fmap(fallback(
39
40
  inits([
40
- line(open(heads[form], subsequence([checkbox, trimBlank(visualize(some(union([indexer, inline]))))]), true)),
41
+ line(open(heads[form], subsequence([checkbox, union([
42
+ trim(fmap(close(union([index]), /^$/), ([el]) => [
43
+ define(el, { class: void el.classList.add('indexer'), 'data-index': '' })
44
+ ])),
45
+ trimBlank(visualize(some(union([indexer, inline])))),
46
+ ])]), true)),
41
47
  indent(union([ulist_, olist_, ilist_])),
42
48
  ]),
43
49
  invalid),
@@ -67,7 +73,7 @@ export const invalid = rewrite(
67
73
  }, source.replace('\n', ''))
68
74
  ], '']);
69
75
 
70
- function index(value: string): number {
76
+ function idx(value: string): number {
71
77
  switch (value) {
72
78
  case 'i':
73
79
  return 1;
@@ -67,10 +67,10 @@ describe('Unit: parser/block/ulist', () => {
67
67
  });
68
68
 
69
69
  it('indexer', () => {
70
- assert.deepStrictEqual(inspect(parser('- [#a]')), [['<ul><li id="index::a"><a class="index" href="#index::a">a</a></li></ul>'], '']);
70
+ assert.deepStrictEqual(inspect(parser('- [#a]')), [['<ul><li><a class="index indexer" href="#index::a" data-index="">a</a></li></ul>'], '']);
71
71
  assert.deepStrictEqual(inspect(parser('- a [#]')), [['<ul><li>a<span class="indexer" data-index=""></span></li></ul>'], '']);
72
72
  assert.deepStrictEqual(inspect(parser('- a [#b]')), [['<ul><li id="index::b">a<span class="indexer" data-index="b"></span></li></ul>'], '']);
73
- assert.deepStrictEqual(inspect(parser('- [ ] [#a]')), [['<ul class="checklist"><li id="index::a"><span class="checkbox">☐</span><a class="index" href="#index::a">a</a></li></ul>'], '']);
73
+ assert.deepStrictEqual(inspect(parser('- [ ] [#a]')), [['<ul class="checklist"><li><span class="checkbox">☐</span><a class="index indexer" href="#index::a" data-index="">a</a></li></ul>'], '']);
74
74
  assert.deepStrictEqual(inspect(parser('- [ ] a [#b]')), [['<ul class="checklist"><li id="index::b"><span class="checkbox">☐</span>a<span class="indexer" data-index="b"></span></li></ul>'], '']);
75
75
  assert.deepStrictEqual(inspect(parser('- a [#]\n - c [#d]')), [['<ul><li>a<span class="indexer" data-index=""></span><ul><li id="index::d">c<span class="indexer" data-index="d"></span></li></ul></li></ul>'], '']);
76
76
  assert.deepStrictEqual(inspect(parser('- a [#b]\n - c [#d]')), [['<ul><li id="index::b">a<span class="indexer" data-index="b"></span><ul><li id="index::d">c<span class="indexer" data-index="d"></span></li></ul></li></ul>'], '']);
@@ -1,12 +1,13 @@
1
1
  import { UListParser } from '../block';
2
- import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, open, fallback, lazy, fmap } from '../../combinator';
2
+ import { union, inits, subsequence, some, creation, state, block, line, validate, indent, focus, open, close, trim, fallback, lazy, fmap } from '../../combinator';
3
3
  import { olist_, invalid } from './olist';
4
4
  import { ilist_ } from './ilist';
5
5
  import { inline, indexer, indexee } from '../inline';
6
+ import { index } from '../inline/extension/index';
6
7
  import { State } from '../context';
7
8
  import { visualize, trimBlank } from '../visibility';
8
9
  import { unshift } from 'spica/array';
9
- import { html, defrag } from 'typed-dom/dom';
10
+ import { html, define, defrag } from 'typed-dom/dom';
10
11
 
11
12
  export const ulist: UListParser = lazy(() => block(validate(
12
13
  /^-(?=[^\S\n]|\n[^\S\n]*\S)/,
@@ -18,7 +19,12 @@ export const ulist_: UListParser = lazy(() => block(fmap(validate(
18
19
  some(creation(1, false, union([
19
20
  indexee(fmap(fallback(
20
21
  inits([
21
- line(open(/^-(?:$|\s)/, subsequence([checkbox, trimBlank(visualize(some(union([indexer, inline]))))]), true)),
22
+ line(open(/^-(?:$|\s)/, subsequence([checkbox, union([
23
+ trim(fmap(close(union([index]), /^$/), ([el]) => [
24
+ define(el, { class: void el.classList.add('indexer'), 'data-index': '' })
25
+ ])),
26
+ trimBlank(visualize(some(union([indexer, inline])))),
27
+ ])]), true)),
22
28
  indent(union([ulist_, olist_, ilist_])),
23
29
  ]),
24
30
  invalid),
@@ -27,8 +27,7 @@ export const index: IndexParser = lazy(() => validate('[#', fmap(indexee(surroun
27
27
  id: el.id ? null : undefined,
28
28
  class: 'index',
29
29
  href: el.id ? `#${el.id}` : undefined,
30
- },
31
- el.childNodes),
30
+ }),
32
31
  ])));
33
32
 
34
33
  const signature: IndexParser.SignatureParser = lazy(() => creation(fmap(open(
@@ -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 index(source: Element | DocumentFragment, optional = false): string {
35
+ export function index(source: Element, 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 '';
@@ -17,9 +17,15 @@ export const mark: MarkParser = lazy(() => surround(
17
17
  open(some(inline, '=', [[/^\\?\n/, 9]]), mark),
18
18
  ]))))),
19
19
  str('=='), false,
20
- ([, bs], rest, { id }) => {
20
+ ([, bs], rest, { id, state }) => {
21
21
  const el = html('mark', defrag(bs));
22
- define(el, { id: identity(id, text(el), 'mark') });
23
- return [[el, html('a', { href: el.id ? `#${el.id}` : undefined })], rest];
22
+ return [[
23
+ define(el, {
24
+ id: state! & (State.annotation | State.reference)
25
+ ? undefined
26
+ : identity(id, text(el), 'mark'),
27
+ }),
28
+ el.id && html('a', { href: `#${el.id}` }),
29
+ ], rest];
24
30
  },
25
31
  ([as, bs], rest) => [unshift(as, bs), rest]));
@@ -54,41 +54,68 @@ describe('Unit: parser/inline/reference', () => {
54
54
 
55
55
  it('abbr', () => {
56
56
  assert.deepStrictEqual(inspect(parser('[[^]]')), [['<sup class="invalid"><span>^</span></sup>'], '']);
57
- assert.deepStrictEqual(inspect(parser('[[^a]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
58
- assert.deepStrictEqual(inspect(parser('[[^a,]]')), [['<sup class="reference" data-abbr="a,"><span></span></sup>'], '']);
59
- assert.deepStrictEqual(inspect(parser('[[^a, ]]')), [['<sup class="reference" data-abbr="a,"><span></span></sup>'], '']);
60
- assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
61
- assert.deepStrictEqual(inspect(parser('[[^a ]]')), [['<sup class="invalid"><span>^a</span></sup>'], '']);
62
- assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="reference" data-abbr="a b"><span></span></sup>'], '']);
63
- assert.deepStrictEqual(inspect(parser('[[^a b]]')), [['<sup class="invalid"><span>^a b</span></sup>'], '']);
64
- assert.deepStrictEqual(inspect(parser('[[^a|]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
65
- assert.deepStrictEqual(inspect(parser('[[^a,|]]')), [['<sup class="reference" data-abbr="a,"><span></span></sup>'], '']);
66
- assert.deepStrictEqual(inspect(parser('[[^a |]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
67
- assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="reference" data-abbr="a"><span>b</span></sup>'], '']);
68
- assert.deepStrictEqual(inspect(parser('[[^a|b]]')), [['<sup class="reference" data-abbr="a"><span>b</span></sup>'], '']);
69
- assert.deepStrictEqual(inspect(parser('[[^a|b ]]')), [['<sup class="reference" data-abbr="a"><span>b</span></sup>'], '']);
70
- assert.deepStrictEqual(inspect(parser('[[^a|b ]]')), [['<sup class="reference" data-abbr="a"><span>b</span></sup>'], '']);
71
- assert.deepStrictEqual(inspect(parser('[[^a|<wbr>]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
72
- assert.deepStrictEqual(inspect(parser('[[^a|<wbr>b]]')), [['<sup class="reference" data-abbr="a"><span>b</span></sup>'], '']);
73
- assert.deepStrictEqual(inspect(parser('[[^a|^b]]')), [['<sup class="reference" data-abbr="a"><span>^b</span></sup>'], '']);
74
- assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
75
- assert.deepStrictEqual(inspect(parser('[[^a| b]]')), [['<sup class="reference" data-abbr="a"><span>b</span></sup>'], '']);
76
- assert.deepStrictEqual(inspect(parser('[[^a| ]]')), [['<sup class="reference" data-abbr="a"><span></span></sup>'], '']);
57
+ assert.deepStrictEqual(inspect(parser('[[^A]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
58
+ assert.deepStrictEqual(inspect(parser('[[^A,]]')), [['<sup class="reference" data-abbr="A,"><span></span></sup>'], '']);
59
+ assert.deepStrictEqual(inspect(parser('[[^A, ]]')), [['<sup class="reference" data-abbr="A,"><span></span></sup>'], '']);
60
+ assert.deepStrictEqual(inspect(parser('[[^A.]]')), [['<sup class="reference" data-abbr="A."><span></span></sup>'], '']);
61
+ assert.deepStrictEqual(inspect(parser('[[^A.,]]')), [['<sup class="reference" data-abbr="A.,"><span></span></sup>'], '']);
62
+ assert.deepStrictEqual(inspect(parser('[[^A?]]')), [['<sup class="reference" data-abbr="A?"><span></span></sup>'], '']);
63
+ assert.deepStrictEqual(inspect(parser('[[^A?,]]')), [['<sup class="reference" data-abbr="A?,"><span></span></sup>'], '']);
64
+ assert.deepStrictEqual(inspect(parser('[[^A ]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
65
+ assert.deepStrictEqual(inspect(parser('[[^A ]]')), [['<sup class="invalid"><span>^A</span></sup>'], '']);
66
+ assert.deepStrictEqual(inspect(parser('[[^A B]]')), [['<sup class="reference" data-abbr="A B"><span></span></sup>'], '']);
67
+ assert.deepStrictEqual(inspect(parser('[[^A B]]')), [['<sup class="invalid"><span>^A B</span></sup>'], '']);
68
+ assert.deepStrictEqual(inspect(parser('[[^A|]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
69
+ assert.deepStrictEqual(inspect(parser('[[^A,|]]')), [['<sup class="reference" data-abbr="A,"><span></span></sup>'], '']);
70
+ assert.deepStrictEqual(inspect(parser('[[^A |]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
71
+ assert.deepStrictEqual(inspect(parser('[[^A|b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
72
+ assert.deepStrictEqual(inspect(parser('[[^A|b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
73
+ assert.deepStrictEqual(inspect(parser('[[^A|b ]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
74
+ assert.deepStrictEqual(inspect(parser('[[^A|b ]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
75
+ assert.deepStrictEqual(inspect(parser('[[^A|<wbr>]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
76
+ assert.deepStrictEqual(inspect(parser('[[^A|<wbr>b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
77
+ assert.deepStrictEqual(inspect(parser('[[^A| ]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
78
+ assert.deepStrictEqual(inspect(parser('[[^A| b]]')), [['<sup class="reference" data-abbr="A"><span>b</span></sup>'], '']);
79
+ assert.deepStrictEqual(inspect(parser('[[^A| ]]')), [['<sup class="reference" data-abbr="A"><span></span></sup>'], '']);
80
+ assert.deepStrictEqual(inspect(parser('[[^A|^]]')), [['<sup class="reference" data-abbr="A"><span>^</span></sup>'], '']);
81
+ assert.deepStrictEqual(inspect(parser('[[^A|^B]]')), [['<sup class="reference" data-abbr="A"><span>^B</span></sup>'], '']);
77
82
  assert.deepStrictEqual(inspect(parser('[[^1]]')), [['<sup class="invalid"><span>^1</span></sup>'], '']);
78
- assert.deepStrictEqual(inspect(parser('[[^1a]]')), [['<sup class="reference" data-abbr="1a"><span></span></sup>'], '']);
83
+ assert.deepStrictEqual(inspect(parser('[[^1A]]')), [['<sup class="invalid"><span>^1A</span></sup>'], '']);
79
84
  assert.deepStrictEqual(inspect(parser('[[^1 ]]')), [['<sup class="invalid"><span>^1</span></sup>'], '']);
80
- assert.deepStrictEqual(inspect(parser('[[^1 a]]')), [['<sup class="reference" data-abbr="1 a"><span></span></sup>'], '']);
85
+ assert.deepStrictEqual(inspect(parser('[[^1 A]]')), [['<sup class="invalid"><span>^1 A</span></sup>'], '']);
81
86
  assert.deepStrictEqual(inspect(parser('[[^1|]]')), [['<sup class="invalid"><span>^1|</span></sup>'], '']);
82
87
  assert.deepStrictEqual(inspect(parser('[[^1 |]]')), [['<sup class="invalid"><span>^1 |</span></sup>'], '']);
83
- assert.deepStrictEqual(inspect(parser('[[^Xyz2020]]')), [['<sup class="reference" data-abbr="Xyz2020"><span></span></sup>'], '']);
84
- assert.deepStrictEqual(inspect(parser('[[^Xyz 2020]]')), [['<sup class="reference" data-abbr="Xyz 2020"><span></span></sup>'], '']);
85
- assert.deepStrictEqual(inspect(parser('[[^Xyz, 2020, p1-2]]')), [['<sup class="reference" data-abbr="Xyz, 2020, p1-2"><span></span></sup>'], '']);
86
- assert.deepStrictEqual(inspect(parser('[[^X. Y., Z et al., 2020, p1-2]]')), [['<sup class="reference" data-abbr="X. Y., Z et al., 2020, p1-2"><span></span></sup>'], '']);
88
+ assert.deepStrictEqual(inspect(parser('[[^Abc]]')), [['<sup class="reference" data-abbr="Abc"><span></span></sup>'], '']);
89
+ assert.deepStrictEqual(inspect(parser('[[^A, B]]')), [['<sup class="reference" data-abbr="A, B"><span></span></sup>'], '']);
87
90
  assert.deepStrictEqual(inspect(parser(`[[^A's, Aces']]`)), [[`<sup class="reference" data-abbr="A's, Aces'"><span></span></sup>`], '']);
91
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020]]')), [['<sup class="reference" data-abbr="Xyz 2020"><span></span></sup>'], '']);
92
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1"><span></span></sup>'], '']);
93
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, 2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, 2"><span></span></sup>'], '']);
94
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1"><span></span></sup>'], '']);
95
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1.1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1"><span></span></sup>'], '']);
96
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1.1-2.1b]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1-2.1b"><span></span></sup>'], '']);
97
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1, fig. 1.1a-b]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1, fig. 1.1a-b"><span></span></sup>'], '']);
98
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1-2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1-2"><span></span></sup>'], '']);
99
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1:1-2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1:1-2"><span></span></sup>'], '']);
100
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1n]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1n"><span></span></sup>'], '']);
101
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1n1]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1n1"><span></span></sup>'], '']);
102
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, 1nn1-2]]')), [['<sup class="reference" data-abbr="Xyz 2020, 1nn1-2"><span></span></sup>'], '']);
103
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, i]]')), [['<sup class="reference" data-abbr="Xyz 2020, i"><span></span></sup>'], '']);
104
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, capter 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, capter 1"><span></span></sup>'], '']);
105
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020, cap. 1]]')), [['<sup class="reference" data-abbr="Xyz 2020, cap. 1"><span></span></sup>'], '']);
106
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020a]]')), [['<sup class="reference" data-abbr="Xyz 2020a"><span></span></sup>'], '']);
107
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020a, 1]]')), [['<sup class="reference" data-abbr="Xyz 2020a, 1"><span></span></sup>'], '']);
108
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020-2021a]]')), [['<sup class="reference" data-abbr="Xyz 2020-2021a"><span></span></sup>'], '']);
109
+ assert.deepStrictEqual(inspect(parser('[[^Xyz 2020-2021a, 1]]')), [['<sup class="reference" data-abbr="Xyz 2020-2021a, 1"><span></span></sup>'], '']);
110
+ assert.deepStrictEqual(inspect(parser('[[^Xyz, April 1, 2020]]')), [['<sup class="reference" data-abbr="Xyz, April 1, 2020"><span></span></sup>'], '']);
111
+ assert.deepStrictEqual(inspect(parser('[[^Xyz, April 1, 2020, 1]]')), [['<sup class="reference" data-abbr="Xyz, April 1, 2020, 1"><span></span></sup>'], '']);
112
+ assert.deepStrictEqual(inspect(parser('[[^Xyz n.d.]]')), [['<sup class="reference" data-abbr="Xyz n.d."><span></span></sup>'], '']);
113
+ assert.deepStrictEqual(inspect(parser('[[^Xyz n.d., 1]]')), [['<sup class="reference" data-abbr="Xyz n.d., 1"><span></span></sup>'], '']);
114
+ assert.deepStrictEqual(inspect(parser('[[^X. Y., and Z et al. 2020, 1-2]]')), [['<sup class="reference" data-abbr="X. Y., and Z et al. 2020, 1-2"><span></span></sup>'], '']);
88
115
  assert.deepStrictEqual(inspect(parser('[[^^]]')), [['<sup class="invalid"><span>^^</span></sup>'], '']);
89
116
  assert.deepStrictEqual(inspect(parser('[[\\^]]')), [['<sup class="reference"><span>^</span></sup>'], '']);
90
117
  assert.deepStrictEqual(inspect(parser('[[^ ]]')), [['<sup class="invalid"><span>^</span></sup>'], '']);
91
- assert.deepStrictEqual(inspect(parser('[[^ a]]')), [['<sup class="invalid"><span>^ a</span></sup>'], '']);
118
+ assert.deepStrictEqual(inspect(parser('[[^ A]]')), [['<sup class="invalid"><span>^ A</span></sup>'], '']);
92
119
  assert.deepStrictEqual(inspect(parser('[[^ |]]')), [['<sup class="invalid"><span>^ |</span></sup>'], '']);
93
120
  assert.deepStrictEqual(inspect(parser('[[^ |b]]')), [['<sup class="invalid"><span>^ |b</span></sup>'], '']);
94
121
  assert.deepStrictEqual(inspect(parser('[[^ | ]]')), [['<sup class="invalid"><span>^ |</span></sup>'], '']);
@@ -4,7 +4,6 @@ import { inline } from '../inline';
4
4
  import { str } from '../source';
5
5
  import { Syntax, State } from '../context';
6
6
  import { regBlankStart, startLoose, trimNode } from '../visibility';
7
- import { stringify } from '../util';
8
7
  import { html, defrag } from 'typed-dom/dom';
9
8
 
10
9
  export const reference: ReferenceParser = lazy(() => surround(
@@ -21,24 +20,27 @@ export const reference: ReferenceParser = lazy(() => surround(
21
20
  false,
22
21
  ([, ns], rest) => [[html('sup', attributes(ns), [html('span', trimNode(defrag(ns)))])], rest]));
23
22
 
23
+ // Chicago-Style
24
24
  const abbr: ReferenceParser.AbbrParser = creation(bind(surround(
25
25
  '^',
26
- union([str(/^(?![0-9]+\s?[|\]])[0-9A-Za-z]+(?:(?:-|(?=\W)(?!'\d)'?(?!\.\d)\.?(?!,\S),? ?)[0-9A-Za-z]+)*(?:-|'?\.?,? ?)?/)]),
26
+ union([str(/^(?=[A-Z])(?:[0-9A-Za-z]'?|(?:[-.:]|\.?\??,? ?)(?!['\-.:?, ]))+/)]),
27
27
  /^\|?(?=]])|^\|[^\S\n]*/),
28
- ([source], rest) => [[html('abbr', source)], rest.replace(regBlankStart, '')]));
28
+ ([source], rest) => [['\n', source.trimEnd()], rest.replace(regBlankStart, '')]));
29
29
 
30
30
  function attributes(ns: (string | HTMLElement)[]): Record<string, string | undefined> {
31
- return typeof ns[0] === 'object' && ns[0].tagName === 'ABBR'
32
- ? {
33
- class: 'reference',
34
- 'data-abbr': stringify([ns.shift()!]).trimEnd(),
35
- }
36
- : ns[0] === ''
37
- ? {
38
- class: 'invalid',
39
- 'data-invalid-syntax': 'reference',
40
- 'data-invalid-type': 'syntax',
41
- 'data-invalid-message': 'Invalid abbr',
42
- }
43
- : { class: 'reference' };
31
+ switch (ns[0]) {
32
+ case '':
33
+ return {
34
+ class: 'invalid',
35
+ 'data-invalid-syntax': 'reference',
36
+ 'data-invalid-type': 'syntax',
37
+ 'data-invalid-message': 'Invalid abbreviation',
38
+ };
39
+ case '\n':
40
+ const abbr = ns[1] as string;
41
+ ns[0] = ns[1] = '';
42
+ return { class: 'reference', 'data-abbr': abbr };
43
+ default:
44
+ return { class: 'reference' };
45
+ }
44
46
  }
@@ -289,7 +289,7 @@ describe('Unit: parser/processor/note', () => {
289
289
  });
290
290
 
291
291
  it('abbr', () => {
292
- const target = parse('[[^a|b]][[^a]][[^a]]');
292
+ const target = parse('[[^A 1|b]][[^A 1]][[^A 1]]');
293
293
  const note = html('ol');
294
294
  for (let i = 0; i < 3; ++i) {
295
295
  [...reference(target, note)];
@@ -297,29 +297,29 @@ describe('Unit: parser/processor/note', () => {
297
297
  [...target.children].map(el => el.outerHTML),
298
298
  [
299
299
  html('p', [
300
- html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:a:1', title: 'b' }, [
300
+ html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:1', title: 'b' }, [
301
301
  html('span', { hidden: '' }, 'b'),
302
- html('a', { href: '#reference::def:a' }, '[a]')
302
+ html('a', { href: '#reference::def:A_1' }, '[A 1]')
303
303
  ]),
304
- html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:a:2', title: 'b' }, [
304
+ html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:2', title: 'b' }, [
305
305
  html('span', { hidden: '' }),
306
- html('a', { href: '#reference::def:a' }, '[a]')
306
+ html('a', { href: '#reference::def:A_1' }, '[A 1]')
307
307
  ]),
308
- html('sup', { class: 'reference', 'data-abbr': 'a', id: 'reference::ref:a:3', title: 'b' }, [
308
+ html('sup', { class: 'reference', 'data-abbr': 'A 1', id: 'reference::ref:A_1:3', title: 'b' }, [
309
309
  html('span', { hidden: '' }),
310
- html('a', { href: '#reference::def:a' }, '[a]')
310
+ html('a', { href: '#reference::def:A_1' }, '[A 1]')
311
311
  ]),
312
312
  ]).outerHTML,
313
313
  ]);
314
314
  assert.deepStrictEqual(
315
315
  note.outerHTML,
316
316
  html('ol', [
317
- html('li', { id: 'reference::def:a' }, [
317
+ html('li', { id: 'reference::def:A_1' }, [
318
318
  html('span', 'b'),
319
319
  html('sup', [
320
- html('a', { href: '#reference::ref:a:1', title: 'b' }, '^1'),
321
- html('a', { href: '#reference::ref:a:2' }, '^2'),
322
- html('a', { href: '#reference::ref:a:3' }, '^3'),
320
+ html('a', { href: '#reference::ref:A_1:1', title: 'b' }, '^1'),
321
+ html('a', { href: '#reference::ref:A_1:2' }, '^2'),
322
+ html('a', { href: '#reference::ref:A_1:3' }, '^3'),
323
323
  ])
324
324
  ]),
325
325
  ]).outerHTML);
@@ -327,7 +327,7 @@ describe('Unit: parser/processor/note', () => {
327
327
  });
328
328
 
329
329
  it('nest', () => {
330
- const target = parse('((a[[^b]]))[[^b|c]]');
330
+ const target = parse('((a[[^B]]))[[^B|c]]');
331
331
  const note = html('ol');
332
332
  for (let i = 0; i < 3; ++i) {
333
333
  [...annotation(target)];
@@ -339,24 +339,24 @@ describe('Unit: parser/processor/note', () => {
339
339
  html('sup', { class: 'annotation', id: 'annotation::ref:a:1', title: 'a' }, [
340
340
  html('span', { hidden: '' }, [
341
341
  'a',
342
- html('sup', { class: 'reference', 'data-abbr': 'b' }, [
342
+ html('sup', { class: 'reference', 'data-abbr': 'B' }, [
343
343
  html('span'),
344
344
  ]),
345
345
  ]),
346
346
  html('a', { href: '#annotation::def:a:1' }, '*1')
347
347
  ]),
348
- html('sup', { class: 'reference', 'data-abbr': 'b', id: 'reference::ref:b:1', title: 'c' }, [
348
+ html('sup', { class: 'reference', 'data-abbr': 'B', id: 'reference::ref:B:1', title: 'c' }, [
349
349
  html('span', { hidden: '' }, 'c'),
350
- html('a', { href: '#reference::def:b' }, '[b]')
350
+ html('a', { href: '#reference::def:B' }, '[B]')
351
351
  ]),
352
352
  ]).outerHTML,
353
353
  html('ol', { class: 'annotations' }, [
354
354
  html('li', { id: 'annotation::def:a:1', 'data-marker': '*1' }, [
355
355
  html('span', [
356
356
  'a',
357
- html('sup', { class: 'reference', 'data-abbr': 'b', id: 'reference::ref:b:2', title: 'c' }, [
357
+ html('sup', { class: 'reference', 'data-abbr': 'B', id: 'reference::ref:B:2', title: 'c' }, [
358
358
  html('span', { hidden: '' }),
359
- html('a', { href: '#reference::def:b' }, '[b]')
359
+ html('a', { href: '#reference::def:B' }, '[B]')
360
360
  ]),
361
361
  ]),
362
362
  html('sup', [html('a', { href: '#annotation::ref:a:1' }, '^1')])
@@ -366,11 +366,11 @@ describe('Unit: parser/processor/note', () => {
366
366
  assert.deepStrictEqual(
367
367
  note.outerHTML,
368
368
  html('ol', [
369
- html('li', { id: 'reference::def:b' }, [
369
+ html('li', { id: 'reference::def:B' }, [
370
370
  html('span', 'c'),
371
371
  html('sup', [
372
- html('a', { href: '#reference::ref:b:1', title: 'c' }, '^1'),
373
- html('a', { href: '#reference::ref:b:2' }, '^2'),
372
+ html('a', { href: '#reference::ref:B:1', title: 'c' }, '^1'),
373
+ html('a', { href: '#reference::ref:B:2' }, '^2'),
374
374
  ]),
375
375
  ]),
376
376
  ]).outerHTML);
@@ -39,41 +39,46 @@ function build(
39
39
  bottom: Node | null = null,
40
40
  ): Generator<HTMLAnchorElement | HTMLLIElement | undefined, undefined, undefined> {
41
41
  const defs = new Map<string, HTMLLIElement>();
42
- const splitters: Element[] = [];
43
- for (let es = target.querySelectorAll(splitter || '_'),
44
- len = es.length, i = 0; i < len; ++i) {
45
- if (i % 100 === 0) yield;
46
- const el = es[i];
47
- el.parentNode === target && splitters.push(el);
48
- }
49
42
  const refs = target.querySelectorAll(`sup.${syntax}:not(.disabled)`);
50
43
  const titles = new Map<string, string>();
51
44
  const defIndexes = new Map<HTMLLIElement, number>();
52
45
  const refSubindexes = new Map<string, number>();
53
- const defSubindexes = splitter ? new Map<string, number>() : undefined;
46
+ const defSubindexes = splitter && refs.length > 0 ? new Map<string, number>() : undefined;
47
+ const splitters = splitter && refs.length > 0 ? target.querySelectorAll(splitter) : [];
48
+ let iSplitters = 0;
54
49
  let total = 0;
55
50
  let format: 'number' | 'abbr';
56
51
  let refIndex = 0;
57
52
  for (let len = refs.length, i = 0; i < len; ++i) {
58
53
  const ref = refs[i];
59
- if (ref.closest('[hidden]')) {
54
+ if (ref.closest('sup > [hidden]')) {
60
55
  yield;
61
56
  continue;
62
57
  }
63
- while (splitters.length > 0
64
- && splitters[0].compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING) {
58
+ if (splitter) for (
59
+ let el: Element;
60
+ (el = splitters[iSplitters])?.compareDocumentPosition(ref) & Node.DOCUMENT_POSITION_FOLLOWING;
61
+ ++iSplitters) {
62
+ if (el.parentNode !== target) continue;
65
63
  if (defs.size > 0) {
66
64
  total += defs.size;
67
- yield* proc(defs, target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0]));
65
+ yield* proc(defs, target.insertBefore(html('ol', { class: `${syntax}s` }), el));
68
66
  assert(defs.size === 0);
69
67
  }
70
- else if (splitters.length % 100 === 0) {
68
+ else if (~iSplitters % 128 === 0) {
71
69
  yield;
72
70
  }
73
- splitters.shift();
74
71
  }
75
72
  const abbr = ref.getAttribute('data-abbr') || undefined;
76
- const identifier = abbr || identity(undefined, text(ref.firstElementChild!), 'mark')?.slice(6) || '';
73
+ const identifier = identity(
74
+ undefined,
75
+ abbr
76
+ ? abbr.match(/^(?:\S+ )+?(?:(?:January|February|March|April|May|June|August|September|October|November|December) \d{1,2}(?:-\d{0,2})?, \d{1,4}(?:-\d{0,4})?[a-z]?|n\.d\.)(?=,|$)/)?.[0] ??
77
+ abbr.match(/^[^,\s]+(?:,? [^,\s]+)*?(?: \d{1,4}(?:-\d{0,4})?[a-z]?(?=,|$)|(?=,(?: [a-z]+\.?)? [0-9]))/)?.[0] ??
78
+ abbr
79
+ : text(ref.firstElementChild!),
80
+ 'mark')
81
+ ?.slice(6) || '';
77
82
  const refSubindex = refSubindexes.get(identifier)! + 1 || 1;
78
83
  refSubindexes.set(identifier, refSubindex);
79
84
  const refId = opts.id !== ''
@@ -106,17 +111,6 @@ function build(
106
111
  : titles.get(identifier)!;
107
112
  initial && titles.set(identifier, title);
108
113
  assert(syntax !== 'annotation' || title);
109
- format ??= abbr ? 'abbr' : 'number';
110
- if (!ref.classList.contains('invalid')) {
111
- if (format === 'number' ? abbr : !abbr) {
112
- markInvalid(ref, syntax, 'format', 'Notation format must be consistent with numbers or abbreviations');
113
- }
114
- }
115
- else switch (ref.getAttribute('data-invalid-syntax')) {
116
- case 'format':
117
- case 'content':
118
- unmarkInvalid(ref);
119
- }
120
114
  ref.firstElementChild!.hasAttribute('hidden')
121
115
  ? ref.lastElementChild!.remove()
122
116
  : ref.firstElementChild!.setAttribute('hidden', '');
@@ -124,13 +118,21 @@ function build(
124
118
  id: refId,
125
119
  class: opts.id !== '' ? undefined : void ref.classList.add('disabled'),
126
120
  title,
127
- ...!title && {
128
- class: void ref.classList.add('invalid'),
129
- 'data-invalid-syntax': syntax,
130
- 'data-invalid-type': 'content',
131
- 'data-invalid-message': 'Missing the content',
132
- },
133
121
  });
122
+ switch (ref.getAttribute('data-invalid-syntax')) {
123
+ case 'format':
124
+ case 'content':
125
+ unmarkInvalid(ref);
126
+ }
127
+ format ??= abbr ? 'abbr' : 'number';
128
+ if (!ref.classList.contains('invalid')) switch (true) {
129
+ case format === 'number' ? !!abbr : !abbr:
130
+ markInvalid(ref, syntax, 'format', 'Notation format must be consistent with numbers or abbreviations');
131
+ break;
132
+ case !title:
133
+ markInvalid(ref, syntax, 'content', 'Missing the content');
134
+ break;
135
+ }
134
136
  yield ref.appendChild(html('a', { href: refId && defId && `#${defId}` }, marker(defIndex, abbr)));
135
137
  assert(ref.title || ref.matches('.invalid'));
136
138
  def.lastElementChild!.appendChild(
@@ -142,7 +144,7 @@ function build(
142
144
  `^${++refIndex}`));
143
145
  }
144
146
  if (note || defs.size > 0) {
145
- yield* proc(defs, note ?? target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[0] ?? bottom));
147
+ yield* proc(defs, note ?? target.insertBefore(html('ol', { class: `${syntax}s` }), splitters[iSplitters] ?? bottom));
146
148
  }
147
149
  return;
148
150
  }