securemark 0.237.1 → 0.239.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/securemark.js +151 -106
  3. package/markdown.d.ts +3 -1
  4. package/package-lock.json +50 -50
  5. package/package.json +1 -1
  6. package/src/combinator/data/parser/subsequence.ts +5 -9
  7. package/src/combinator/data/parser/tails.ts +1 -1
  8. package/src/combinator/data/parser/union.ts +1 -1
  9. package/src/debug.test.ts +1 -1
  10. package/src/parser/block/codeblock.test.ts +5 -2
  11. package/src/parser/block/codeblock.ts +42 -24
  12. package/src/parser/block/extension/fig.test.ts +1 -1
  13. package/src/parser/block/extension/fig.ts +1 -1
  14. package/src/parser/block/extension/figure.test.ts +2 -0
  15. package/src/parser/block/extension/figure.ts +21 -24
  16. package/src/parser/block/olist.test.ts +2 -0
  17. package/src/parser/block/ulist.test.ts +2 -0
  18. package/src/parser/block.ts +2 -2
  19. package/src/parser/inline/comment.ts +1 -1
  20. package/src/parser/inline/extension/index.test.ts +19 -13
  21. package/src/parser/inline/extension/index.ts +4 -3
  22. package/src/parser/inline/extension/indexee.ts +7 -3
  23. package/src/parser/inline/extension/indexer.test.ts +2 -1
  24. package/src/parser/inline/extension/indexer.ts +6 -3
  25. package/src/parser/inline/htmlentity.ts +2 -2
  26. package/src/parser/inline/media.ts +2 -2
  27. package/src/parser/inline/ruby.ts +2 -2
  28. package/src/parser/processor/figure.test.ts +8 -6
  29. package/src/parser/processor/figure.ts +32 -19
  30. package/src/parser/segment.test.ts +2 -2
  31. package/src/parser/segment.ts +2 -2
  32. package/src/parser/source/str.ts +23 -4
  33. package/src/parser/source/text.ts +3 -0
  34. package/src/parser/source.ts +1 -1
  35. package/src/parser/util.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.239.0
4
+
5
+ - Extend indexer syntax to make its own index optional.
6
+
7
+ ## 0.238.0
8
+
9
+ - Revert signature syntax not to require leading whitespace.
10
+
11
+ ## 0.237.2
12
+
13
+ - Refactoring.
14
+
3
15
  ## 0.237.1
4
16
 
5
17
  - Refactoring.
@@ -1,4 +1,4 @@
1
- /*! securemark v0.237.1 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
1
+ /*! securemark v0.239.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
2
2
  require = function () {
3
3
  function r(e, n, t) {
4
4
  function o(i, f) {
@@ -4037,21 +4037,10 @@ require = function () {
4037
4037
  const union_1 = _dereq_('./union');
4038
4038
  const inits_1 = _dereq_('./inits');
4039
4039
  function subsequence(parsers) {
4040
- switch (parsers.length) {
4041
- case 0:
4042
- case 1:
4043
- return (0, union_1.union)(parsers);
4044
- case 2:
4045
- return (0, union_1.union)([
4046
- (0, inits_1.inits)(parsers),
4047
- parsers[1]
4048
- ]);
4049
- default:
4050
- return subsequence([
4051
- parsers[0],
4052
- subsequence(parsers.slice(1))
4053
- ]);
4054
- }
4040
+ return (0, union_1.union)(parsers.map((_, i) => i < parsers.length - 1 ? (0, inits_1.inits)([
4041
+ parsers[i],
4042
+ subsequence(parsers.slice(i + 1))
4043
+ ]) : parsers[i]));
4055
4044
  }
4056
4045
  exports.subsequence = subsequence;
4057
4046
  },
@@ -4095,7 +4084,7 @@ require = function () {
4095
4084
  'return (source, context) =>',
4096
4085
  '0',
4097
4086
  ...parsers.map((_, i) => `|| parsers[${ i }](source, context)`)
4098
- ].join(''))(parsers);
4087
+ ].join('\n'))(parsers);
4099
4088
  }
4100
4089
  }
4101
4090
  exports.union = union;
@@ -4648,7 +4637,7 @@ require = function () {
4648
4637
  paragraph_1.paragraph
4649
4638
  ]))));
4650
4639
  function error(parser) {
4651
- return (0, combinator_1.recover)((0, combinator_1.fallback)((0, combinator_1.open)('\0', source => {
4640
+ return (0, combinator_1.recover)((0, combinator_1.fallback)((0, combinator_1.open)('\x07', source => {
4652
4641
  throw new Error(source.split('\n', 1)[0]);
4653
4642
  }), parser), (source, {id}, reason) => [
4654
4643
  [
@@ -4659,7 +4648,7 @@ require = function () {
4659
4648
  (0, typed_dom_1.html)('pre', {
4660
4649
  class: 'error',
4661
4650
  translate: 'no'
4662
- }, source.replace(/^\0.*\n/, '').slice(0, 1001).replace(/^(.{997}).{4}$/s, '$1...') || global_1.undefined)
4651
+ }, source.replace(/^\x07.*\n/, '').slice(0, 1001).replace(/^(.{997}).{4}$/s, '$1...') || global_1.undefined)
4663
4652
  ],
4664
4653
  ''
4665
4654
  ]);
@@ -4753,41 +4742,49 @@ require = function () {
4753
4742
  const parser_1 = _dereq_('../../combinator/data/parser');
4754
4743
  const combinator_1 = _dereq_('../../combinator');
4755
4744
  const autolink_1 = _dereq_('../autolink');
4756
- const source_1 = _dereq_('../source');
4757
4745
  const typed_dom_1 = _dereq_('typed-dom');
4758
- const array_1 = _dereq_('spica/array');
4759
- const opener = /^(`{3,})(?!`)(\S*)([^\n]*)(?:$|\n)/;
4760
- const language = /^[0-9a-z]+(?:-[a-z][0-9a-z]*)*$/;
4746
+ const opener = /^(`{3,})(?!`)([^\n]*)(?:$|\n)/;
4747
+ const language = /^[0-9a-z]+(?:-[a-z][0-9a-z]*)*$/i;
4761
4748
  exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('```', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 300))));
4762
4749
  exports.segment_ = (0, combinator_1.block)((0, combinator_1.validate)('```', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 300, false))), false);
4763
- exports.codeblock = (0, combinator_1.block)((0, combinator_1.validate)('```', (0, combinator_1.fmap)((0, combinator_1.fence)(opener, 300), ([body, closer, opener, delim, lang, param], _, context) => {
4764
- var _a, _b, _c, _d;
4765
- [lang, param] = language.test(lang) ? [
4766
- lang,
4767
- param
4768
- ] : [
4769
- '',
4770
- lang + param
4771
- ];
4772
- param = param.trim();
4773
- const path = (0, array_1.join)((0, parser_1.eval)((0, combinator_1.some)(source_1.escsource, /^\s/)(param, context), []));
4774
- if (!closer || param !== path)
4750
+ exports.codeblock = (0, combinator_1.block)((0, combinator_1.validate)('```', (0, combinator_1.fmap)((0, combinator_1.fence)(opener, 300), ([body, closer, opener, delim, param], _, context) => {
4751
+ var _a, _b, _c, _d, _e, _f;
4752
+ const params = (_b = (_a = param.match(/(?:\\.?|\S)+/g)) === null || _a === void 0 ? void 0 : _a.reduce((params, value, i) => {
4753
+ var _a, _b, _c;
4754
+ let name;
4755
+ switch (true) {
4756
+ case i === 0 && value[0] === param[0] && language.test(value):
4757
+ name = 'lang';
4758
+ value = value.toLowerCase();
4759
+ break;
4760
+ case /^\d+(?:[,-]\d+)*$/.test(value):
4761
+ name = 'line';
4762
+ break;
4763
+ default:
4764
+ name = 'path';
4765
+ if (!params.lang) {
4766
+ const file = (_a = value.split('/').pop()) !== null && _a !== void 0 ? _a : '';
4767
+ params.lang = file && file.includes('.', 1) ? (_c = (_b = file.split('.').pop()) === null || _b === void 0 ? void 0 : _b.match(language)) === null || _c === void 0 ? void 0 : _c[0].toLowerCase() : params.lang;
4768
+ }
4769
+ }
4770
+ name in params ? params.invalid = `Duplicate ${ name } value` : params[name] = value;
4771
+ return params;
4772
+ }, {})) !== null && _b !== void 0 ? _b : {};
4773
+ if (!closer || params.invalid)
4775
4774
  return [(0, typed_dom_1.html)('pre', {
4776
4775
  class: 'invalid',
4777
4776
  translate: 'no',
4778
4777
  'data-invalid-syntax': 'codeblock',
4779
4778
  'data-invalid-type': !closer ? 'fence' : 'argument',
4780
- 'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
4779
+ 'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : params.invalid
4781
4780
  }, `${ opener }${ body }${ closer }`)];
4782
- const file = (_a = path.split('/').pop()) !== null && _a !== void 0 ? _a : '';
4783
- const ext = file && file.includes('.', 1) ? file.split('.').pop() : '';
4784
- lang = language.test(lang || ext) ? lang || ext : lang && 'invalid';
4785
4781
  const el = (0, typed_dom_1.html)('pre', {
4786
- class: lang ? `code language-${ lang }` : 'text',
4782
+ class: params.lang ? `code language-${ params.lang }` : 'text',
4787
4783
  translate: 'no',
4788
- 'data-lang': lang || global_1.undefined,
4789
- 'data-path': path || global_1.undefined
4790
- }, lang ? ((_d = (_c = (_b = context.caches) === null || _b === void 0 ? void 0 : _b.code) === null || _c === void 0 ? void 0 : _c.get(`${ lang }\n${ body.slice(0, -1) }`)) === null || _d === void 0 ? void 0 : _d.cloneNode(true).childNodes) || body.slice(0, -1) || global_1.undefined : (0, typed_dom_1.defrag)((0, parser_1.eval)((0, combinator_1.some)(autolink_1.autolink)(body.slice(0, -1), context), [])));
4784
+ 'data-lang': params.lang || global_1.undefined,
4785
+ 'data-line': params.line || global_1.undefined,
4786
+ 'data-path': params.path || global_1.undefined
4787
+ }, params.lang ? ((_f = (_d = (_c = context.caches) === null || _c === void 0 ? void 0 : _c.code) === null || _d === void 0 ? void 0 : _d.get(`${ (_e = params.lang) !== null && _e !== void 0 ? _e : '' }\n${ body.slice(0, -1) }`)) === null || _f === void 0 ? void 0 : _f.cloneNode(true).childNodes) || body.slice(0, -1) || global_1.undefined : (0, typed_dom_1.defrag)((0, parser_1.eval)((0, combinator_1.some)(autolink_1.autolink)(body.slice(0, -1), context), [])));
4791
4788
  return [el];
4792
4789
  })));
4793
4790
  },
@@ -4795,8 +4792,6 @@ require = function () {
4795
4792
  '../../combinator': 27,
4796
4793
  '../../combinator/data/parser': 47,
4797
4794
  '../autolink': 62,
4798
- '../source': 128,
4799
- 'spica/array': 6,
4800
4795
  'spica/global': 15,
4801
4796
  'typed-dom': 26
4802
4797
  }
@@ -5037,7 +5032,7 @@ require = function () {
5037
5032
  '[$',
5038
5033
  '$'
5039
5034
  ], (0, combinator_1.sequence)([
5040
- (0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /^.*\n/)),
5035
+ (0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /^(?=\s).*\n/)),
5041
5036
  (0, combinator_1.union)([
5042
5037
  codeblock_1.segment,
5043
5038
  mathblock_1.segment,
@@ -5113,7 +5108,7 @@ require = function () {
5113
5108
  const memoize_1 = _dereq_('spica/memoize');
5114
5109
  const array_1 = _dereq_('spica/array');
5115
5110
  exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/^(~{3,})(?:figure[^\S\n]+)?(?=\[?\$[A-Za-z-][^\n]*\n)/, (0, memoize_1.memoize)(([, fence], closer = new RegExp(String.raw`^${ fence }[^\S\n]*(?:$|\n)`)) => (0, combinator_1.close)((0, combinator_1.sequence)([
5116
- (0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /^.*\n/)),
5111
+ source_1.contentline,
5117
5112
  (0, combinator_1.inits)([
5118
5113
  (0, combinator_1.union)([
5119
5114
  codeblock_1.segment_,
@@ -5158,10 +5153,6 @@ require = function () {
5158
5153
  ])])));
5159
5154
  function attributes(label, param, content, caption) {
5160
5155
  const group = label.split('-', 1)[0];
5161
- const invalidLabel = /^[^-]+-(?:[0-9]+\.)*0$/.test(label);
5162
- const invalidParam = param.trimStart() !== '';
5163
- const invalidContent = group === '$' && (!content.classList.contains('math') || caption.length > 0);
5164
- const invalid = invalidLabel || invalidParam || invalidContent || global_1.undefined;
5165
5156
  let type = content.className.split(/\s/)[0];
5166
5157
  switch (type || content.tagName) {
5167
5158
  case 'UL':
@@ -5185,24 +5176,25 @@ require = function () {
5185
5176
  break;
5186
5177
  default:
5187
5178
  }
5179
+ const invalid = /^[^-]+-(?:[0-9]+\.)*0$/.test(label) && {
5180
+ 'data-invalid-type': 'label',
5181
+ 'data-invalid-message': 'The last part of the fixed label numbers must not be 0'
5182
+ } || param.trimStart() !== '' && {
5183
+ 'data-invalid-type': 'argument',
5184
+ 'data-invalid-message': 'Invalid argument'
5185
+ } || group === '$' && (!content.classList.contains('math') || caption.length > 0) && {
5186
+ 'data-invalid-type': 'content',
5187
+ 'data-invalid-message': 'A figure labeled to define a formula number can contain only a math formula and no caption'
5188
+ } || global_1.undefined;
5188
5189
  return {
5189
5190
  'data-type': type,
5190
5191
  'data-label': label,
5191
5192
  'data-group': group,
5192
- class: invalid && 'invalid',
5193
- ...invalidLabel && {
5194
- 'data-invalid-syntax': 'figure',
5195
- 'data-invalid-type': 'label',
5196
- 'data-invalid-message': 'The last part of the fixed label numbers must not be 0'
5197
- } || invalidParam && {
5198
- 'data-invalid-syntax': 'figure',
5199
- 'data-invalid-type': 'argument',
5200
- 'data-invalid-message': 'Invalid argument'
5201
- } || invalidContent && {
5193
+ ...invalid && {
5194
+ class: 'invalid',
5202
5195
  'data-invalid-syntax': 'figure',
5203
- 'data-invalid-type': 'content',
5204
- 'data-invalid-message': 'A figure labeled to define a formula number can contain only a math formula and no caption'
5205
- } || global_1.undefined
5196
+ ...invalid
5197
+ }
5206
5198
  };
5207
5199
  }
5208
5200
  },
@@ -6740,7 +6732,7 @@ require = function () {
6740
6732
  ], ([as, bs = []], rest) => [
6741
6733
  (0, array_1.unshift)(as, bs),
6742
6734
  rest
6743
- ]), ([, fence]) => fence)))));
6735
+ ]), ([, fence]) => fence.length)))));
6744
6736
  },
6745
6737
  {
6746
6738
  '../../combinator': 27,
@@ -6983,15 +6975,15 @@ require = function () {
6983
6975
  autolink: false
6984
6976
  }
6985
6977
  }
6986
- }, (0, combinator_1.some)((0, combinator_1.union)([
6978
+ }, (0, combinator_1.open)((0, source_1.stropt)('|'), (0, combinator_1.some)((0, combinator_1.union)([
6987
6979
  signature,
6988
6980
  inline_1.inline
6989
- ]), ']', /^\\?\n/)))), ']'), ns => [(0, typed_dom_1.html)('a', (0, util_1.trimNodeEnd)((0, typed_dom_1.defrag)(ns)))])), ([el]) => [(0, typed_dom_1.define)(el, {
6981
+ ]), ']', /^\\?\n/), true)))), ']'), ns => [(0, typed_dom_1.html)('a', (0, util_1.trimNodeEnd)((0, typed_dom_1.defrag)(ns)))])), ([el]) => [(0, typed_dom_1.define)(el, {
6990
6982
  id: el.id ? null : global_1.undefined,
6991
6983
  class: 'index',
6992
6984
  href: el.id ? `#${ el.id }` : global_1.undefined
6993
6985
  }, el.childNodes)]))));
6994
- const signature = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.open)(/^\s+\|#/, (0, util_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([
6986
+ const signature = (0, combinator_1.lazy)(() => (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.open)('|#', (0, util_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([
6995
6987
  bracket,
6996
6988
  source_1.txt
6997
6989
  ]), ']'))), ns => [(0, typed_dom_1.html)('span', {
@@ -7045,12 +7037,13 @@ require = function () {
7045
7037
  function text(source, optional = false) {
7046
7038
  var _a;
7047
7039
  const indexer = source.querySelector(':scope > .indexer');
7048
- if (indexer)
7049
- return indexer.getAttribute('data-index');
7050
- if (optional)
7040
+ if (!indexer && optional)
7051
7041
  return '';
7042
+ const index = indexer === null || indexer === void 0 ? void 0 : indexer.getAttribute('data-index');
7043
+ if (index)
7044
+ return index;
7052
7045
  const target = source.cloneNode(true);
7053
- for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference'), i = 0, len = es.length; i < len; ++i) {
7046
+ for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference, .checkbox, ul, ol'), i = 0, len = es.length; i < len; ++i) {
7054
7047
  const el = es[i];
7055
7048
  switch (el.tagName) {
7056
7049
  case 'CODE':
@@ -7058,6 +7051,8 @@ require = function () {
7058
7051
  continue;
7059
7052
  case 'RT':
7060
7053
  case 'RP':
7054
+ case 'UL':
7055
+ case 'OL':
7061
7056
  el.remove();
7062
7057
  continue;
7063
7058
  }
@@ -7066,6 +7061,7 @@ require = function () {
7066
7061
  (0, typed_dom_1.define)(el, el.getAttribute('data-src'));
7067
7062
  continue;
7068
7063
  case 'comment':
7064
+ case 'checkbox':
7069
7065
  el.remove();
7070
7066
  continue;
7071
7067
  case 'reference':
@@ -7091,7 +7087,13 @@ require = function () {
7091
7087
  const combinator_1 = _dereq_('../../../combinator');
7092
7088
  const index_1 = _dereq_('./index');
7093
7089
  const typed_dom_1 = _dereq_('typed-dom');
7094
- exports.indexer = (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.verify)((0, combinator_1.surround)(/^\s+(?=\[#[^\s\]])/, (0, combinator_1.context)({ syntax: { inline: { index: true } } }, (0, combinator_1.union)([index_1.index])), /^\s*$/), ([el]) => el.getElementsByClassName('invalid').length === 0), ([el]) => [(0, typed_dom_1.html)('span', {
7090
+ exports.indexer = (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.verify)((0, combinator_1.surround)(/^\s+(?=\[#\S)/, (0, combinator_1.context)({ syntax: { inline: { index: true } } }, (0, combinator_1.union)([
7091
+ (0, combinator_1.focus)('[#]', () => [
7092
+ [(0, typed_dom_1.html)('a', { href: '#' })],
7093
+ ''
7094
+ ]),
7095
+ index_1.index
7096
+ ])), /^\s*$/), ([el]) => el.getElementsByClassName('invalid').length === 0), ([el]) => [(0, typed_dom_1.html)('span', {
7095
7097
  class: 'indexer',
7096
7098
  'data-index': el.getAttribute('href').slice(7)
7097
7099
  })]));
@@ -7372,11 +7374,11 @@ require = function () {
7372
7374
  exports.unsafehtmlentity = (0, combinator_1.creator)((0, combinator_1.validate)('&', (0, combinator_1.focus)(/^&[0-9A-Za-z]+;/, entity => {
7373
7375
  var _a;
7374
7376
  return [
7375
- [(_a = parse(entity)) !== null && _a !== void 0 ? _a : `\0${ entity }`],
7377
+ [(_a = parse(entity)) !== null && _a !== void 0 ? _a : `\x1B${ entity }`],
7376
7378
  ''
7377
7379
  ];
7378
7380
  })));
7379
- exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([test]) => [test[0] === '\0' ? (0, typed_dom_1.html)('span', {
7381
+ exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([test]) => [test[0] === '\x1B' ? (0, typed_dom_1.html)('span', {
7380
7382
  class: 'invalid',
7381
7383
  'data-invalid-syntax': 'htmlentity',
7382
7384
  'data-invalid-type': 'syntax',
@@ -7774,13 +7776,13 @@ require = function () {
7774
7776
  });
7775
7777
  return false;
7776
7778
  }
7777
- if (alt.includes('\0')) {
7779
+ if (alt.includes('\x1B')) {
7778
7780
  (0, typed_dom_1.define)(target, {
7779
7781
  class: void target.classList.add('invalid'),
7780
7782
  'data-invalid-syntax': 'media',
7781
7783
  'data-invalid-type': 'content',
7782
7784
  'data-invalid-message': `Cannot use invalid HTML entitiy "${ alt.match(/&[0-9A-Za-z]+;/)[0] }"`,
7783
- alt: (_a = target.getAttribute('alt')) === null || _a === void 0 ? void 0 : _a.replace(/\0/g, '')
7785
+ alt: (_a = target.getAttribute('alt')) === null || _a === void 0 ? void 0 : _a.replace(/\x1B/g, '')
7784
7786
  });
7785
7787
  return false;
7786
7788
  }
@@ -7943,9 +7945,9 @@ require = function () {
7943
7945
  rubies
7944
7946
  ]) {
7945
7947
  for (let i = 0; i < ss.length; ++i) {
7946
- if (ss[i].indexOf('\0') === -1)
7948
+ if (ss[i].indexOf('\x1B') === -1)
7947
7949
  continue;
7948
- ss[i] = ss[i].replace(/\0/g, '');
7950
+ ss[i] = ss[i].replace(/\x1B/g, '');
7949
7951
  attrs !== null && attrs !== void 0 ? attrs : attrs = {
7950
7952
  class: 'invalid',
7951
7953
  'data-invalid-syntax': 'ruby',
@@ -8184,7 +8186,7 @@ require = function () {
8184
8186
  const def = defs[i];
8185
8187
  if (def.parentNode !== target)
8186
8188
  continue;
8187
- const {tagName, classList} = def;
8189
+ const {tagName} = def;
8188
8190
  if (bases.length === 1 && tagName[0] === 'H')
8189
8191
  continue;
8190
8192
  const label = tagName === 'FIGURE' ? def.getAttribute('data-label') : `$-${ increment(index, def) }`;
@@ -8192,7 +8194,7 @@ require = function () {
8192
8194
  continue;
8193
8195
  if (label.endsWith('-0')) {
8194
8196
  (0, typed_dom_1.define)(def, {
8195
- class: void classList.add('invalid'),
8197
+ class: void def.classList.add('invalid'),
8196
8198
  'data-invalid-syntax': 'figure',
8197
8199
  'data-invalid-type': 'argument',
8198
8200
  'data-invalid-message': 'Invalid base index',
@@ -8203,7 +8205,7 @@ require = function () {
8203
8205
  if (tagName === 'FIGURE' && label.endsWith('.0')) {
8204
8206
  if (label.lastIndexOf('.', label.length - 3) !== -1) {
8205
8207
  (0, typed_dom_1.define)(def, {
8206
- class: void classList.add('invalid'),
8208
+ class: void def.classList.add('invalid'),
8207
8209
  'data-invalid-syntax': 'figure',
8208
8210
  'data-invalid-type': 'argument',
8209
8211
  'data-invalid-message': 'Base index must be $-x.0 format',
@@ -8213,16 +8215,16 @@ require = function () {
8213
8215
  }
8214
8216
  if (!/^H[1-6]$/.test((_d = (_c = def.previousElementSibling) === null || _c === void 0 ? void 0 : _c.tagName) !== null && _d !== void 0 ? _d : '')) {
8215
8217
  (0, typed_dom_1.define)(def, {
8216
- class: void classList.add('invalid'),
8218
+ class: void def.classList.add('invalid'),
8217
8219
  'data-invalid-syntax': 'figure',
8218
8220
  'data-invalid-type': 'position',
8219
- 'data-invalid-message': 'Base index declarations must be after level 1 or 2 headings',
8221
+ 'data-invalid-message': messages.declaration,
8220
8222
  hidden: null
8221
8223
  });
8222
8224
  continue;
8223
- } else {
8224
- classList.contains('invalid') && (0, typed_dom_1.define)(def, {
8225
- class: void classList.remove('invalid'),
8225
+ } else if (def.getAttribute('data-invalid-message') === messages.declaration) {
8226
+ (0, typed_dom_1.define)(def, {
8227
+ class: void def.classList.remove('invalid'),
8226
8228
  'data-invalid-syntax': null,
8227
8229
  'data-invalid-type': null,
8228
8230
  'data-invalid-message': null,
@@ -8247,42 +8249,50 @@ require = function () {
8247
8249
  continue;
8248
8250
  }
8249
8251
  !(0, label_1.isFixed)(label) && numbers.set(group, number);
8250
- opts.id !== '' && def.setAttribute('id', `label:${ opts.id ? `${ opts.id }:` : '' }${ label }`);
8251
8252
  const figindex = group === '$' ? `(${ number })` : `${ capitalize(group) }${ group === 'fig' ? '.' : '' } ${ number }`;
8252
8253
  (0, typed_dom_1.define)(def.querySelector(':scope > figcaption > .figindex'), group === '$' ? figindex : `${ figindex }. `);
8253
8254
  if (labels.has(label)) {
8254
- if (classList.contains('invalid') && def.getAttribute('data-invalid-message') !== 'Duplicate label')
8255
+ if (def.classList.contains('invalid'))
8255
8256
  continue;
8256
8257
  (0, typed_dom_1.define)(def, {
8257
8258
  id: null,
8258
- class: void classList.add('invalid'),
8259
+ class: void def.classList.add('invalid'),
8259
8260
  'data-invalid-syntax': 'figure',
8260
8261
  'data-invalid-type': 'argument',
8261
- 'data-invalid-message': 'Duplicate label'
8262
+ 'data-invalid-message': messages.duplicate
8262
8263
  });
8263
8264
  continue;
8264
- } else {
8265
- labels.add(label);
8265
+ } else if (def.getAttribute('data-invalid-message') === messages.duplicate) {
8266
8266
  (0, typed_dom_1.define)(def, {
8267
- class: void classList.remove('invalid'),
8267
+ class: void def.classList.remove('invalid'),
8268
8268
  'data-invalid-syntax': null,
8269
8269
  'data-invalid-type': null,
8270
8270
  'data-invalid-message': null
8271
8271
  });
8272
8272
  }
8273
+ labels.add(label);
8274
+ opts.id !== '' && def.setAttribute('id', `label:${ opts.id ? `${ opts.id }:` : '' }${ label }`);
8273
8275
  for (const ref of refs.take(label, global_1.Infinity)) {
8276
+ if (ref.getAttribute('data-invalid-message') === messages.reference) {
8277
+ (0, typed_dom_1.define)(ref, {
8278
+ class: void ref.classList.remove('invalid'),
8279
+ 'data-invalid-syntax': null,
8280
+ 'data-invalid-type': null,
8281
+ 'data-invalid-message': null
8282
+ });
8283
+ }
8274
8284
  if (ref.hash.slice(1) === def.id && ref.innerText === figindex)
8275
8285
  continue;
8276
8286
  yield (0, typed_dom_1.define)(ref, opts.id !== '' ? { href: `#${ def.id }` } : { class: `${ ref.className } disabled` }, figindex);
8277
8287
  }
8278
8288
  }
8279
8289
  for (const [, ref] of refs) {
8280
- if (opts.id !== '') {
8290
+ if (opts.id !== '' && !ref.classList.contains('invalid')) {
8281
8291
  (0, typed_dom_1.define)(ref, {
8282
- class: `${ ref.className } disabled invalid`,
8292
+ class: void ref.classList.add('invalid'),
8283
8293
  'data-invalid-syntax': 'label',
8284
8294
  'data-invalid-type': 'reference',
8285
- 'data-invalid-message': 'Missing the target figure'
8295
+ 'data-invalid-message': messages.reference
8286
8296
  });
8287
8297
  }
8288
8298
  yield ref;
@@ -8290,6 +8300,11 @@ require = function () {
8290
8300
  return;
8291
8301
  }
8292
8302
  exports.figure = figure;
8303
+ const messages = {
8304
+ declaration: 'Base index declarations must be after level 1 to 6 headings',
8305
+ duplicate: 'Duplicate label',
8306
+ reference: 'Missing the target figure'
8307
+ };
8293
8308
  function increment(bases, el) {
8294
8309
  const index = (+el.tagName[1] - 1 || 1) - 1;
8295
8310
  return index + 1 < bases.length ? (0, array_1.join)(bases.slice(0, index + 2).map((v, i) => {
@@ -8471,14 +8486,14 @@ require = function () {
8471
8486
  ]);
8472
8487
  function* segment(source) {
8473
8488
  if (!validate(source, exports.MAX_INPUT_SIZE))
8474
- return yield `\0Too large input over ${ exports.MAX_INPUT_SIZE.toLocaleString('en') } bytes.\n${ source.slice(0, 1001) }`;
8489
+ return yield `\x07Too large input over ${ exports.MAX_INPUT_SIZE.toLocaleString('en') } bytes.\n${ source.slice(0, 1001) }`;
8475
8490
  while (source !== '') {
8476
8491
  const result = parser(source, {});
8477
8492
  const rest = (0, parser_1.exec)(result);
8478
8493
  const segs = (0, parser_1.eval)(result).length ? (0, parser_1.eval)(result) : [source.slice(0, source.length - rest.length)];
8479
8494
  for (let i = 0; i < segs.length; ++i) {
8480
8495
  const seg = segs[i];
8481
- validate(seg, exports.MAX_SEGMENT_SIZE) ? yield seg : yield `\0Too large segment over ${ exports.MAX_SEGMENT_SIZE.toLocaleString('en') } bytes.\n${ seg }`;
8496
+ validate(seg, exports.MAX_SEGMENT_SIZE) ? yield seg : yield `\x07Too large segment over ${ exports.MAX_SEGMENT_SIZE.toLocaleString('en') } bytes.\n${ seg }`;
8482
8497
  }
8483
8498
  source = rest;
8484
8499
  }
@@ -8504,7 +8519,7 @@ require = function () {
8504
8519
  function (_dereq_, module, exports) {
8505
8520
  'use strict';
8506
8521
  Object.defineProperty(exports, '__esModule', { value: true });
8507
- exports.anyline = exports.emptyline = exports.contentline = exports.str = exports.unescsource = exports.escsource = exports.linebreak = exports.txt = exports.text = void 0;
8522
+ exports.anyline = exports.emptyline = exports.contentline = exports.stropt = exports.str = exports.unescsource = exports.escsource = exports.linebreak = exports.txt = exports.text = void 0;
8508
8523
  var text_1 = _dereq_('./source/text');
8509
8524
  Object.defineProperty(exports, 'text', {
8510
8525
  enumerable: true,
@@ -8545,6 +8560,12 @@ require = function () {
8545
8560
  return str_1.str;
8546
8561
  }
8547
8562
  });
8563
+ Object.defineProperty(exports, 'stropt', {
8564
+ enumerable: true,
8565
+ get: function () {
8566
+ return str_1.stropt;
8567
+ }
8568
+ });
8548
8569
  var line_1 = _dereq_('./source/line');
8549
8570
  Object.defineProperty(exports, 'contentline', {
8550
8571
  enumerable: true,
@@ -8653,10 +8674,10 @@ require = function () {
8653
8674
  function (_dereq_, module, exports) {
8654
8675
  'use strict';
8655
8676
  Object.defineProperty(exports, '__esModule', { value: true });
8656
- exports.str = void 0;
8677
+ exports.stropt = exports.str = void 0;
8657
8678
  const global_1 = _dereq_('spica/global');
8658
8679
  const combinator_1 = _dereq_('../../combinator');
8659
- function str(pattern, mustConsume = true) {
8680
+ function str(pattern) {
8660
8681
  return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
8661
8682
  if (source === '')
8662
8683
  return;
@@ -8668,14 +8689,38 @@ require = function () {
8668
8689
  if (source === '')
8669
8690
  return;
8670
8691
  const m = source.match(pattern);
8671
- return m && (!mustConsume || m[0].length > 0) ? [
8692
+ return m && m[0].length > 0 ? [
8672
8693
  [m[0]],
8673
8694
  source.slice(m[0].length)
8674
8695
  ] : global_1.undefined;
8675
8696
  });
8676
8697
  }
8677
8698
  exports.str = str;
8678
- ;
8699
+ function stropt(pattern) {
8700
+ return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
8701
+ if (source === '')
8702
+ return;
8703
+ return source.slice(0, pattern.length) === pattern ? [
8704
+ [pattern],
8705
+ source.slice(pattern.length)
8706
+ ] : [
8707
+ [],
8708
+ source
8709
+ ];
8710
+ }) : (0, combinator_1.creator)(source => {
8711
+ if (source === '')
8712
+ return;
8713
+ const m = source.match(pattern);
8714
+ return m ? [
8715
+ [m[0]],
8716
+ source.slice(m[0].length)
8717
+ ] : [
8718
+ [],
8719
+ source
8720
+ ];
8721
+ });
8722
+ }
8723
+ exports.stropt = stropt;
8679
8724
  },
8680
8725
  {
8681
8726
  '../../combinator': 27,
@@ -8892,7 +8937,7 @@ require = function () {
8892
8937
  exports.startLoose = startLoose;
8893
8938
  exports.isStartLoose = (0, memoize_1.reduce)((source, context, except) => {
8894
8939
  return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
8895
- }, (source, _, except = '') => `${ source }\0${ except }`);
8940
+ }, (source, _, except = '') => `${ source }\x1E${ except }`);
8896
8941
  function startTight(parser, except) {
8897
8942
  return (source, context) => isStartTight(source, context, except) ? parser(source, context) : global_1.undefined;
8898
8943
  }
@@ -8926,7 +8971,7 @@ require = function () {
8926
8971
  default:
8927
8972
  return source[0].trimStart() !== '';
8928
8973
  }
8929
- }, (source, _, except = '') => `${ source }\0${ except }`);
8974
+ }, (source, _, except = '') => `${ source }\x1E${ except }`);
8930
8975
  function isStartTightNodes(nodes) {
8931
8976
  if (nodes.length === 0)
8932
8977
  return true;
package/markdown.d.ts CHANGED
@@ -388,7 +388,7 @@ export namespace MarkdownParser {
388
388
  export interface SegmentParser extends
389
389
  Block<'extension/figure/segment'>,
390
390
  Parser<never, Context, [
391
- InlineParser.ExtensionParser.LabelParser.SegmentParser,
391
+ SourceParser.ContentLineParser,
392
392
  Parser<never, Context, [
393
393
  Parser<never, Context, [
394
394
  CodeBlockParser.SegmentParser,
@@ -768,9 +768,11 @@ export namespace MarkdownParser {
768
768
  }
769
769
  }
770
770
  export interface IndexerParser extends
771
+ // [#]
771
772
  // [#index]
772
773
  Inline<'extension/indexer'>,
773
774
  Parser<HTMLElement, Context, [
775
+ Parser<HTMLAnchorElement, Context, []>,
774
776
  IndexParser,
775
777
  ]> {
776
778
  }