securemark 0.237.0 → 0.238.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 (37) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/securemark.js +179 -102
  3. package/markdown.d.ts +1 -1
  4. package/package-lock.json +16 -16
  5. package/package.json +1 -1
  6. package/src/debug.test.ts +1 -1
  7. package/src/parser/block/codeblock.test.ts +5 -2
  8. package/src/parser/block/codeblock.ts +43 -25
  9. package/src/parser/block/extension/aside.ts +1 -1
  10. package/src/parser/block/extension/example.ts +1 -1
  11. package/src/parser/block/extension/fig.test.ts +1 -1
  12. package/src/parser/block/extension/fig.ts +1 -1
  13. package/src/parser/block/extension/figure.test.ts +2 -0
  14. package/src/parser/block/extension/figure.ts +22 -25
  15. package/src/parser/block/extension/message.ts +1 -1
  16. package/src/parser/block/extension/placeholder.ts +1 -1
  17. package/src/parser/block/extension/table.ts +1 -1
  18. package/src/parser/block/heading.test.ts +1 -1
  19. package/src/parser/block/heading.ts +10 -4
  20. package/src/parser/block/mathblock.ts +1 -1
  21. package/src/parser/block.ts +2 -2
  22. package/src/parser/inline/comment.ts +1 -1
  23. package/src/parser/inline/extension/index.test.ts +19 -13
  24. package/src/parser/inline/extension/index.ts +4 -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 +44 -18
  29. package/src/parser/processor/figure.ts +68 -24
  30. package/src/parser/processor/footnote.ts +1 -1
  31. package/src/parser/segment.test.ts +2 -2
  32. package/src/parser/segment.ts +2 -2
  33. package/src/parser/source/str.ts +23 -4
  34. package/src/parser/source/text.ts +3 -0
  35. package/src/parser/source.ts +1 -1
  36. package/src/parser/util.ts +2 -2
  37. package/src/util/quote.ts +1 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.238.0
4
+
5
+ - Revert signature syntax not to require leading whitespace.
6
+
7
+ ## 0.237.2
8
+
9
+ - Refactoring.
10
+
11
+ ## 0.237.1
12
+
13
+ - Refactoring.
14
+
3
15
  ## 0.237.0
4
16
 
5
17
  - Extend ulist syntax and olist syntax to make their items indexable.
@@ -1,4 +1,4 @@
1
- /*! securemark v0.237.0 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
1
+ /*! securemark v0.238.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) {
@@ -4648,7 +4648,7 @@ require = function () {
4648
4648
  paragraph_1.paragraph
4649
4649
  ]))));
4650
4650
  function error(parser) {
4651
- return (0, combinator_1.recover)((0, combinator_1.fallback)((0, combinator_1.open)('\0', source => {
4651
+ return (0, combinator_1.recover)((0, combinator_1.fallback)((0, combinator_1.open)('\x07', source => {
4652
4652
  throw new Error(source.split('\n', 1)[0]);
4653
4653
  }), parser), (source, {id}, reason) => [
4654
4654
  [
@@ -4659,7 +4659,7 @@ require = function () {
4659
4659
  (0, typed_dom_1.html)('pre', {
4660
4660
  class: 'error',
4661
4661
  translate: 'no'
4662
- }, source.replace(/^\0.*\n/, '').slice(0, 1001).replace(/^(.{997}).{4}$/s, '$1...') || global_1.undefined)
4662
+ }, source.replace(/^\x07.*\n/, '').slice(0, 1001).replace(/^(.{997}).{4}$/s, '$1...') || global_1.undefined)
4663
4663
  ],
4664
4664
  ''
4665
4665
  ]);
@@ -4753,41 +4753,49 @@ require = function () {
4753
4753
  const parser_1 = _dereq_('../../combinator/data/parser');
4754
4754
  const combinator_1 = _dereq_('../../combinator');
4755
4755
  const autolink_1 = _dereq_('../autolink');
4756
- const source_1 = _dereq_('../source');
4757
4756
  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]*)*$/;
4757
+ const opener = /^(`{3,})(?!`)([^\n]*)(?:$|\n)/;
4758
+ const language = /^[0-9a-z]+(?:-[a-z][0-9a-z]*)*$/i;
4761
4759
  exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('```', (0, combinator_1.clear)((0, combinator_1.fence)(opener, 300))));
4762
4760
  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)
4761
+ 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) => {
4762
+ var _a, _b, _c, _d, _e, _f;
4763
+ const params = (_b = (_a = param.match(/(?:\\.?|\S)+/g)) === null || _a === void 0 ? void 0 : _a.reduce((params, value, i) => {
4764
+ var _a, _b, _c;
4765
+ let name;
4766
+ switch (true) {
4767
+ case i === 0 && value[0] === param[0] && language.test(value):
4768
+ name = 'lang';
4769
+ value = value.toLowerCase();
4770
+ break;
4771
+ case /^\d+(?:[,-]\d+)*$/.test(value):
4772
+ name = 'line';
4773
+ break;
4774
+ default:
4775
+ name = 'path';
4776
+ if (!params.lang) {
4777
+ const file = (_a = value.split('/').pop()) !== null && _a !== void 0 ? _a : '';
4778
+ 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;
4779
+ }
4780
+ }
4781
+ name in params ? params.invalid = `Duplicate ${ name } value` : params[name] = value;
4782
+ return params;
4783
+ }, {})) !== null && _b !== void 0 ? _b : {};
4784
+ if (!closer || params.invalid)
4775
4785
  return [(0, typed_dom_1.html)('pre', {
4776
4786
  class: 'invalid',
4777
4787
  translate: 'no',
4778
4788
  'data-invalid-syntax': 'codeblock',
4779
- 'data-invalid-type': !closer ? 'closer' : 'argument',
4780
- 'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
4789
+ 'data-invalid-type': !closer ? 'fence' : 'argument',
4790
+ 'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : params.invalid
4781
4791
  }, `${ 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
4792
  const el = (0, typed_dom_1.html)('pre', {
4786
- class: lang ? `code language-${ lang }` : 'text',
4793
+ class: params.lang ? `code language-${ params.lang }` : 'text',
4787
4794
  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), [])));
4795
+ 'data-lang': params.lang || global_1.undefined,
4796
+ 'data-line': params.line || global_1.undefined,
4797
+ 'data-path': params.path || global_1.undefined
4798
+ }, 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
4799
  return [el];
4792
4800
  })));
4793
4801
  },
@@ -4795,8 +4803,6 @@ require = function () {
4795
4803
  '../../combinator': 27,
4796
4804
  '../../combinator/data/parser': 47,
4797
4805
  '../autolink': 62,
4798
- '../source': 128,
4799
- 'spica/array': 6,
4800
4806
  'spica/global': 15,
4801
4807
  'typed-dom': 26
4802
4808
  }
@@ -4910,7 +4916,7 @@ require = function () {
4910
4916
  class: 'invalid',
4911
4917
  translate: 'no',
4912
4918
  'data-invalid-syntax': 'aside',
4913
- 'data-invalid-type': !closer ? 'closer' : 'argument',
4919
+ 'data-invalid-type': !closer ? 'fence' : 'argument',
4914
4920
  'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
4915
4921
  }, `${ opener }${ body }${ closer }`)];
4916
4922
  const annotations = (0, typed_dom_1.html)('ol', { class: 'annotations' });
@@ -4965,7 +4971,7 @@ require = function () {
4965
4971
  class: 'invalid',
4966
4972
  translate: 'no',
4967
4973
  'data-invalid-syntax': 'example',
4968
- 'data-invalid-type': !closer ? 'closer' : 'argument',
4974
+ 'data-invalid-type': !closer ? 'fence' : 'argument',
4969
4975
  'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
4970
4976
  }, `${ opener }${ body }${ closer }`)];
4971
4977
  switch (type) {
@@ -5037,7 +5043,7 @@ require = function () {
5037
5043
  '[$',
5038
5044
  '$'
5039
5045
  ], (0, combinator_1.sequence)([
5040
- (0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /^.*\n/)),
5046
+ (0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /^(?=\s).*\n/)),
5041
5047
  (0, combinator_1.union)([
5042
5048
  codeblock_1.segment,
5043
5049
  mathblock_1.segment,
@@ -5112,8 +5118,8 @@ require = function () {
5112
5118
  const typed_dom_1 = _dereq_('typed-dom');
5113
5119
  const memoize_1 = _dereq_('spica/memoize');
5114
5120
  const array_1 = _dereq_('spica/array');
5115
- exports.segment = (0, combinator_1.block)((0, combinator_1.match)(/^(~{3,})(?:figure[^\S\n]+)?(?=\[?\$[A-Za-z-][^\n]*\n(?:[^\n]*\n)*?\1[^\S\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/)),
5121
+ 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)([
5122
+ source_1.contentline,
5117
5123
  (0, combinator_1.inits)([
5118
5124
  (0, combinator_1.union)([
5119
5125
  codeblock_1.segment_,
@@ -5158,10 +5164,6 @@ require = function () {
5158
5164
  ])])));
5159
5165
  function attributes(label, param, content, caption) {
5160
5166
  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
5167
  let type = content.className.split(/\s/)[0];
5166
5168
  switch (type || content.tagName) {
5167
5169
  case 'UL':
@@ -5185,24 +5187,25 @@ require = function () {
5185
5187
  break;
5186
5188
  default:
5187
5189
  }
5190
+ const invalid = /^[^-]+-(?:[0-9]+\.)*0$/.test(label) && {
5191
+ 'data-invalid-type': 'label',
5192
+ 'data-invalid-message': 'The last part of the fixed label numbers must not be 0'
5193
+ } || param.trimStart() !== '' && {
5194
+ 'data-invalid-type': 'argument',
5195
+ 'data-invalid-message': 'Invalid argument'
5196
+ } || group === '$' && (!content.classList.contains('math') || caption.length > 0) && {
5197
+ 'data-invalid-type': 'content',
5198
+ 'data-invalid-message': 'A figure labeled to define a formula number can contain only a math formula and no caption'
5199
+ } || global_1.undefined;
5188
5200
  return {
5189
5201
  'data-type': type,
5190
5202
  'data-label': label,
5191
5203
  '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 && {
5204
+ ...invalid && {
5205
+ class: 'invalid',
5202
5206
  '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
5207
+ ...invalid
5208
+ }
5206
5209
  };
5207
5210
  }
5208
5211
  },
@@ -5253,7 +5256,7 @@ require = function () {
5253
5256
  class: 'invalid',
5254
5257
  translate: 'no',
5255
5258
  'data-invalid-syntax': 'message',
5256
- 'data-invalid-type': !closer ? 'closer' : 'argument',
5259
+ 'data-invalid-type': !closer ? 'fence' : 'argument',
5257
5260
  'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
5258
5261
  }, `${ opener }${ body }${ closer }`)];
5259
5262
  switch (type) {
@@ -5324,7 +5327,7 @@ require = function () {
5324
5327
  class: 'invalid',
5325
5328
  translate: 'no',
5326
5329
  'data-invalid-syntax': 'extension',
5327
- 'data-invalid-type': !closer ? 'closer' : 'syntax',
5330
+ 'data-invalid-type': !closer ? 'fence' : 'syntax',
5328
5331
  'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid syntax'
5329
5332
  }, `${ opener }${ body }${ closer }`)])));
5330
5333
  },
@@ -5358,7 +5361,7 @@ require = function () {
5358
5361
  class: 'invalid',
5359
5362
  translate: 'no',
5360
5363
  'data-invalid-syntax': 'table',
5361
- 'data-invalid-type': !closer ? 'closer' : 'argument',
5364
+ 'data-invalid-type': !closer ? 'fence' : 'argument',
5362
5365
  'data-invalid-message': !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
5363
5366
  }, `${ opener }${ body }${ closer }`)];
5364
5367
  return (_a = (0, parser_1.eval)(parser(body, context))) !== null && _a !== void 0 ? _a : [(0, typed_dom_1.html)('table')];
@@ -5611,8 +5614,7 @@ require = function () {
5611
5614
  const source_1 = _dereq_('../source');
5612
5615
  const util_1 = _dereq_('../util');
5613
5616
  const typed_dom_1 = _dereq_('typed-dom');
5614
- const array_1 = _dereq_('spica/array');
5615
- exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('#', (0, combinator_1.focus)(/^#{1,6}[^\S\n]+\S[^\n]*(?:\n#{1,6}(?!\S)[^\n]*)*(?:$|\n)/, (0, combinator_1.some)((0, combinator_1.line)(source => [
5617
+ exports.segment = (0, combinator_1.block)((0, combinator_1.validate)('#', (0, combinator_1.focus)(/^#+[^\S\n]+\S[^\n]*(?:\n#+(?!\S)[^\n]*)*(?:$|\n)/, (0, combinator_1.some)((0, combinator_1.line)(source => [
5616
5618
  [source],
5617
5619
  ''
5618
5620
  ])))));
@@ -5636,14 +5638,18 @@ require = function () {
5636
5638
  inline_1.indexer,
5637
5639
  inline_1.inline
5638
5640
  ]))))), true)
5639
- ]), ns => [(0, typed_dom_1.html)(`h${ (0, array_1.shift)(ns)[0].length }`, (0, typed_dom_1.defrag)(ns))]))))));
5641
+ ]), ([h, ...ns]) => [h.length <= 6 ? (0, typed_dom_1.html)(`h${ h.length }`, (0, typed_dom_1.defrag)(ns)) : (0, typed_dom_1.html)(`h6`, {
5642
+ class: 'invalid',
5643
+ 'data-invalid-syntax': 'heading',
5644
+ 'data-invalid-type': 'syntax',
5645
+ 'data-invalid-message': 'Heading level must be up to 6'
5646
+ }, (0, typed_dom_1.defrag)(ns))]))))));
5640
5647
  },
5641
5648
  {
5642
5649
  '../../combinator': 27,
5643
5650
  '../inline': 88,
5644
5651
  '../source': 128,
5645
5652
  '../util': 134,
5646
- 'spica/array': 6,
5647
5653
  'typed-dom': 26
5648
5654
  }
5649
5655
  ],
@@ -5726,7 +5732,7 @@ require = function () {
5726
5732
  class: 'invalid',
5727
5733
  translate: 'no',
5728
5734
  'data-invalid-syntax': 'mathblock',
5729
- 'data-invalid-type': delim.length > 2 ? 'syntax' : !closer ? 'closer' : 'argument',
5735
+ 'data-invalid-type': delim.length > 2 ? 'syntax' : !closer ? 'fence' : 'argument',
5730
5736
  'data-invalid-message': delim.length > 2 ? 'Invalid syntax' : !closer ? `Missing the closing delimiter "${ delim }"` : 'Invalid argument'
5731
5737
  }, `${ opener }${ body }${ closer }`)];
5732
5738
  })));
@@ -6737,7 +6743,7 @@ require = function () {
6737
6743
  ], ([as, bs = []], rest) => [
6738
6744
  (0, array_1.unshift)(as, bs),
6739
6745
  rest
6740
- ]), ([, fence]) => fence)))));
6746
+ ]), ([, fence]) => fence.length)))));
6741
6747
  },
6742
6748
  {
6743
6749
  '../../combinator': 27,
@@ -6980,15 +6986,15 @@ require = function () {
6980
6986
  autolink: false
6981
6987
  }
6982
6988
  }
6983
- }, (0, combinator_1.some)((0, combinator_1.union)([
6989
+ }, (0, combinator_1.open)((0, source_1.stropt)('|'), (0, combinator_1.some)((0, combinator_1.union)([
6984
6990
  signature,
6985
6991
  inline_1.inline
6986
- ]), ']', /^\\?\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, {
6992
+ ]), ']', /^\\?\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, {
6987
6993
  id: el.id ? null : global_1.undefined,
6988
6994
  class: 'index',
6989
6995
  href: el.id ? `#${ el.id }` : global_1.undefined
6990
6996
  }, el.childNodes)]))));
6991
- 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)([
6997
+ 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)([
6992
6998
  bracket,
6993
6999
  source_1.txt
6994
7000
  ]), ']'))), ns => [(0, typed_dom_1.html)('span', {
@@ -7369,11 +7375,11 @@ require = function () {
7369
7375
  exports.unsafehtmlentity = (0, combinator_1.creator)((0, combinator_1.validate)('&', (0, combinator_1.focus)(/^&[0-9A-Za-z]+;/, entity => {
7370
7376
  var _a;
7371
7377
  return [
7372
- [(_a = parse(entity)) !== null && _a !== void 0 ? _a : `\0${ entity }`],
7378
+ [(_a = parse(entity)) !== null && _a !== void 0 ? _a : `\x1B${ entity }`],
7373
7379
  ''
7374
7380
  ];
7375
7381
  })));
7376
- exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([test]) => [test[0] === '\0' ? (0, typed_dom_1.html)('span', {
7382
+ exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([test]) => [test[0] === '\x1B' ? (0, typed_dom_1.html)('span', {
7377
7383
  class: 'invalid',
7378
7384
  'data-invalid-syntax': 'htmlentity',
7379
7385
  'data-invalid-type': 'syntax',
@@ -7771,13 +7777,13 @@ require = function () {
7771
7777
  });
7772
7778
  return false;
7773
7779
  }
7774
- if (alt.includes('\0')) {
7780
+ if (alt.includes('\x1B')) {
7775
7781
  (0, typed_dom_1.define)(target, {
7776
7782
  class: void target.classList.add('invalid'),
7777
7783
  'data-invalid-syntax': 'media',
7778
7784
  'data-invalid-type': 'content',
7779
7785
  'data-invalid-message': `Cannot use invalid HTML entitiy "${ alt.match(/&[0-9A-Za-z]+;/)[0] }"`,
7780
- alt: (_a = target.getAttribute('alt')) === null || _a === void 0 ? void 0 : _a.replace(/\0/g, '')
7786
+ alt: (_a = target.getAttribute('alt')) === null || _a === void 0 ? void 0 : _a.replace(/\x1B/g, '')
7781
7787
  });
7782
7788
  return false;
7783
7789
  }
@@ -7940,9 +7946,9 @@ require = function () {
7940
7946
  rubies
7941
7947
  ]) {
7942
7948
  for (let i = 0; i < ss.length; ++i) {
7943
- if (ss[i].indexOf('\0') === -1)
7949
+ if (ss[i].indexOf('\x1B') === -1)
7944
7950
  continue;
7945
- ss[i] = ss[i].replace(/\0/g, '');
7951
+ ss[i] = ss[i].replace(/\x1B/g, '');
7946
7952
  attrs !== null && attrs !== void 0 ? attrs : attrs = {
7947
7953
  class: 'invalid',
7948
7954
  'data-invalid-syntax': 'ruby',
@@ -8166,7 +8172,7 @@ require = function () {
8166
8172
  const multimap_1 = _dereq_('spica/multimap');
8167
8173
  const array_1 = _dereq_('spica/array');
8168
8174
  function* figure(target, footnotes, opts = {}) {
8169
- var _a, _b, _c;
8175
+ var _a, _b, _c, _d;
8170
8176
  const refs = new multimap_1.MultiMap((0, array_1.push)((0, array_1.push)((0, array_1.push)([], target.querySelectorAll('a.label:not(.disabled)[data-label]')), (_a = footnotes === null || footnotes === void 0 ? void 0 : footnotes.annotations.querySelectorAll('a.label:not(.disabled)')) !== null && _a !== void 0 ? _a : []), (_b = footnotes === null || footnotes === void 0 ? void 0 : footnotes.references.querySelectorAll('a.label:not(.disabled)')) !== null && _b !== void 0 ? _b : []).map(el => [
8171
8177
  el.getAttribute('data-label'),
8172
8178
  el
@@ -8176,48 +8182,78 @@ require = function () {
8176
8182
  let base = '0';
8177
8183
  let bases = base.split('.');
8178
8184
  let index = bases;
8179
- for (let defs = target.querySelectorAll('figure[data-label], h1, h2, h3'), i = 0, len = defs.length; i < len; ++i) {
8185
+ for (let defs = target.querySelectorAll('figure[data-label], h1, h2'), i = 0, len = defs.length; i < len; ++i) {
8180
8186
  yield;
8181
8187
  const def = defs[i];
8182
8188
  if (def.parentNode !== target)
8183
8189
  continue;
8184
- if (bases.length === 1 && def.tagName[0] === 'H')
8190
+ const {tagName} = def;
8191
+ if (bases.length === 1 && tagName[0] === 'H')
8185
8192
  continue;
8186
- const label = def.tagName === 'FIGURE' ? def.getAttribute('data-label') : `$-${ increment(index, def) }`;
8193
+ const label = tagName === 'FIGURE' ? def.getAttribute('data-label') : `$-${ increment(index, def) }`;
8187
8194
  if (label.endsWith('-'))
8188
8195
  continue;
8189
- if (label.endsWith('-0'))
8196
+ if (label.endsWith('-0')) {
8197
+ (0, typed_dom_1.define)(def, {
8198
+ class: void def.classList.add('invalid'),
8199
+ 'data-invalid-syntax': 'figure',
8200
+ 'data-invalid-type': 'argument',
8201
+ 'data-invalid-message': 'Invalid base index',
8202
+ hidden: null
8203
+ });
8190
8204
  continue;
8191
- if (def.tagName === 'FIGURE' && label.endsWith('.0')) {
8192
- if (label.lastIndexOf('.', label.length - 3) < 0 && !(+((_c = def.previousElementSibling) === null || _c === void 0 ? void 0 : _c.tagName[1]) <= 2))
8205
+ }
8206
+ if (tagName === 'FIGURE' && label.endsWith('.0')) {
8207
+ if (label.lastIndexOf('.', label.length - 3) !== -1) {
8208
+ (0, typed_dom_1.define)(def, {
8209
+ class: void def.classList.add('invalid'),
8210
+ 'data-invalid-syntax': 'figure',
8211
+ 'data-invalid-type': 'argument',
8212
+ 'data-invalid-message': 'Base index must be $-x.0 format',
8213
+ hidden: null
8214
+ });
8193
8215
  continue;
8194
- if (label.lastIndexOf('.', label.length - 3) > 0)
8216
+ }
8217
+ if (!/^H[1-6]$/.test((_d = (_c = def.previousElementSibling) === null || _c === void 0 ? void 0 : _c.tagName) !== null && _d !== void 0 ? _d : '')) {
8218
+ (0, typed_dom_1.define)(def, {
8219
+ class: void def.classList.add('invalid'),
8220
+ 'data-invalid-syntax': 'figure',
8221
+ 'data-invalid-type': 'position',
8222
+ 'data-invalid-message': 'Base index declarations must be after level 1 to 6 headings',
8223
+ hidden: null
8224
+ });
8195
8225
  continue;
8226
+ } else if (def.getAttribute('data-invalid-message') === 'Base index declarations must be after level 1 to 6 headings') {
8227
+ (0, typed_dom_1.define)(def, {
8228
+ class: void def.classList.remove('invalid'),
8229
+ 'data-invalid-syntax': null,
8230
+ 'data-invalid-type': null,
8231
+ 'data-invalid-message': null,
8232
+ hidden: ''
8233
+ });
8234
+ }
8196
8235
  }
8197
8236
  const group = label.split('-', 1)[0];
8198
8237
  let number = (0, label_1.number)(label, numbers.has(group) && !(0, label_1.isFixed)(label) ? (0, array_1.join)(numbers.get(group).split('.').slice(0, bases.length), '.') : base);
8199
8238
  if (number.endsWith('.0')) {
8200
- if (number.split('.').length > 2)
8201
- continue;
8202
- if (group !== '$' || def.tagName === 'FIGURE' && def.firstChild)
8239
+ if (group !== '$' || tagName === 'FIGURE' && def.firstChild)
8203
8240
  continue;
8204
8241
  if (number.startsWith('0.')) {
8205
- number = (0, array_1.join)(index.slice(0).reduce((ns, _, i, bs) => {
8206
- i === ns.length ? bs.length = i : ns[i] = +ns[i] > +bs[i] ? ns[i] : +ns[i] === 0 ? bs[i] : `${ +bs[i] + 1 }`;
8242
+ number = (0, array_1.join)(index.slice(0).reduce((ns, _, i, xs) => {
8243
+ i === ns.length ? xs.length = i : ns[i] = +ns[i] > +xs[i] ? ns[i] : +ns[i] === 0 ? xs[i] : `${ +xs[i] + 1 }`;
8207
8244
  return ns;
8208
8245
  }, number.split('.')), '.');
8209
8246
  }
8210
8247
  base = number;
8211
8248
  bases = index = base.split('.');
8212
- numbers.clear();
8249
+ tagName !== 'FIGURE' && numbers.clear();
8213
8250
  continue;
8214
8251
  }
8215
8252
  !(0, label_1.isFixed)(label) && numbers.set(group, number);
8216
- opts.id !== '' && def.setAttribute('id', `label:${ opts.id ? `${ opts.id }:` : '' }${ label }`);
8217
8253
  const figindex = group === '$' ? `(${ number })` : `${ capitalize(group) }${ group === 'fig' ? '.' : '' } ${ number }`;
8218
8254
  (0, typed_dom_1.define)(def.querySelector(':scope > figcaption > .figindex'), group === '$' ? figindex : `${ figindex }. `);
8219
8255
  if (labels.has(label)) {
8220
- if (def.classList.contains('invalid') && def.getAttribute('data-invalid-message') !== 'Duplicate label')
8256
+ if (def.classList.contains('invalid'))
8221
8257
  continue;
8222
8258
  (0, typed_dom_1.define)(def, {
8223
8259
  id: null,
@@ -8227,8 +8263,7 @@ require = function () {
8227
8263
  'data-invalid-message': 'Duplicate label'
8228
8264
  });
8229
8265
  continue;
8230
- } else {
8231
- labels.add(label);
8266
+ } else if (def.getAttribute('data-invalid-message') === 'Duplicate label') {
8232
8267
  (0, typed_dom_1.define)(def, {
8233
8268
  class: void def.classList.remove('invalid'),
8234
8269
  'data-invalid-syntax': null,
@@ -8236,16 +8271,26 @@ require = function () {
8236
8271
  'data-invalid-message': null
8237
8272
  });
8238
8273
  }
8274
+ labels.add(label);
8275
+ opts.id !== '' && def.setAttribute('id', `label:${ opts.id ? `${ opts.id }:` : '' }${ label }`);
8239
8276
  for (const ref of refs.take(label, global_1.Infinity)) {
8277
+ if (ref.getAttribute('data-invalid-message') === 'Missing the target figure') {
8278
+ (0, typed_dom_1.define)(ref, {
8279
+ class: void ref.classList.remove('invalid'),
8280
+ 'data-invalid-syntax': null,
8281
+ 'data-invalid-type': null,
8282
+ 'data-invalid-message': null
8283
+ });
8284
+ }
8240
8285
  if (ref.hash.slice(1) === def.id && ref.innerText === figindex)
8241
8286
  continue;
8242
8287
  yield (0, typed_dom_1.define)(ref, opts.id !== '' ? { href: `#${ def.id }` } : { class: `${ ref.className } disabled` }, figindex);
8243
8288
  }
8244
8289
  }
8245
8290
  for (const [, ref] of refs) {
8246
- if (opts.id !== '') {
8291
+ if (opts.id !== '' && !ref.classList.contains('invalid')) {
8247
8292
  (0, typed_dom_1.define)(ref, {
8248
- class: `${ ref.className } disabled invalid`,
8293
+ class: void ref.classList.add('invalid'),
8249
8294
  'data-invalid-syntax': 'label',
8250
8295
  'data-invalid-type': 'reference',
8251
8296
  'data-invalid-message': 'Missing the target figure'
@@ -8320,7 +8365,7 @@ require = function () {
8320
8365
  style !== null && style !== void 0 ? style : style = abbr ? 'abbr' : 'count';
8321
8366
  if (style === 'count' ? abbr : !abbr) {
8322
8367
  (0, typed_dom_1.define)(ref, {
8323
- class: `${ ref.className } invalid`,
8368
+ class: void ref.classList.add('invalid'),
8324
8369
  'data-invalid-syntax': syntax,
8325
8370
  'data-invalid-type': 'style',
8326
8371
  'data-invalid-message': `${ syntax[0].toUpperCase() + syntax.slice(1) } style must be consistent`
@@ -8437,14 +8482,14 @@ require = function () {
8437
8482
  ]);
8438
8483
  function* segment(source) {
8439
8484
  if (!validate(source, exports.MAX_INPUT_SIZE))
8440
- return yield `\0Too large input over ${ exports.MAX_INPUT_SIZE.toLocaleString('en') } bytes.\n${ source.slice(0, 1001) }`;
8485
+ return yield `\x07Too large input over ${ exports.MAX_INPUT_SIZE.toLocaleString('en') } bytes.\n${ source.slice(0, 1001) }`;
8441
8486
  while (source !== '') {
8442
8487
  const result = parser(source, {});
8443
8488
  const rest = (0, parser_1.exec)(result);
8444
8489
  const segs = (0, parser_1.eval)(result).length ? (0, parser_1.eval)(result) : [source.slice(0, source.length - rest.length)];
8445
8490
  for (let i = 0; i < segs.length; ++i) {
8446
8491
  const seg = segs[i];
8447
- validate(seg, exports.MAX_SEGMENT_SIZE) ? yield seg : yield `\0Too large segment over ${ exports.MAX_SEGMENT_SIZE.toLocaleString('en') } bytes.\n${ seg }`;
8492
+ validate(seg, exports.MAX_SEGMENT_SIZE) ? yield seg : yield `\x07Too large segment over ${ exports.MAX_SEGMENT_SIZE.toLocaleString('en') } bytes.\n${ seg }`;
8448
8493
  }
8449
8494
  source = rest;
8450
8495
  }
@@ -8470,7 +8515,7 @@ require = function () {
8470
8515
  function (_dereq_, module, exports) {
8471
8516
  'use strict';
8472
8517
  Object.defineProperty(exports, '__esModule', { value: true });
8473
- exports.anyline = exports.emptyline = exports.contentline = exports.str = exports.unescsource = exports.escsource = exports.linebreak = exports.txt = exports.text = void 0;
8518
+ exports.anyline = exports.emptyline = exports.contentline = exports.stropt = exports.str = exports.unescsource = exports.escsource = exports.linebreak = exports.txt = exports.text = void 0;
8474
8519
  var text_1 = _dereq_('./source/text');
8475
8520
  Object.defineProperty(exports, 'text', {
8476
8521
  enumerable: true,
@@ -8511,6 +8556,12 @@ require = function () {
8511
8556
  return str_1.str;
8512
8557
  }
8513
8558
  });
8559
+ Object.defineProperty(exports, 'stropt', {
8560
+ enumerable: true,
8561
+ get: function () {
8562
+ return str_1.stropt;
8563
+ }
8564
+ });
8514
8565
  var line_1 = _dereq_('./source/line');
8515
8566
  Object.defineProperty(exports, 'contentline', {
8516
8567
  enumerable: true,
@@ -8619,10 +8670,10 @@ require = function () {
8619
8670
  function (_dereq_, module, exports) {
8620
8671
  'use strict';
8621
8672
  Object.defineProperty(exports, '__esModule', { value: true });
8622
- exports.str = void 0;
8673
+ exports.stropt = exports.str = void 0;
8623
8674
  const global_1 = _dereq_('spica/global');
8624
8675
  const combinator_1 = _dereq_('../../combinator');
8625
- function str(pattern, mustConsume = true) {
8676
+ function str(pattern) {
8626
8677
  return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
8627
8678
  if (source === '')
8628
8679
  return;
@@ -8634,14 +8685,38 @@ require = function () {
8634
8685
  if (source === '')
8635
8686
  return;
8636
8687
  const m = source.match(pattern);
8637
- return m && (!mustConsume || m[0].length > 0) ? [
8688
+ return m && m[0].length > 0 ? [
8638
8689
  [m[0]],
8639
8690
  source.slice(m[0].length)
8640
8691
  ] : global_1.undefined;
8641
8692
  });
8642
8693
  }
8643
8694
  exports.str = str;
8644
- ;
8695
+ function stropt(pattern) {
8696
+ return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
8697
+ if (source === '')
8698
+ return;
8699
+ return source.slice(0, pattern.length) === pattern ? [
8700
+ [pattern],
8701
+ source.slice(pattern.length)
8702
+ ] : [
8703
+ [],
8704
+ source
8705
+ ];
8706
+ }) : (0, combinator_1.creator)(source => {
8707
+ if (source === '')
8708
+ return;
8709
+ const m = source.match(pattern);
8710
+ return m ? [
8711
+ [m[0]],
8712
+ source.slice(m[0].length)
8713
+ ] : [
8714
+ [],
8715
+ source
8716
+ ];
8717
+ });
8718
+ }
8719
+ exports.stropt = stropt;
8645
8720
  },
8646
8721
  {
8647
8722
  '../../combinator': 27,
@@ -8858,7 +8933,7 @@ require = function () {
8858
8933
  exports.startLoose = startLoose;
8859
8934
  exports.isStartLoose = (0, memoize_1.reduce)((source, context, except) => {
8860
8935
  return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
8861
- }, (source, _, except = '') => `${ source }\0${ except }`);
8936
+ }, (source, _, except = '') => `${ source }\x1E${ except }`);
8862
8937
  function startTight(parser, except) {
8863
8938
  return (source, context) => isStartTight(source, context, except) ? parser(source, context) : global_1.undefined;
8864
8939
  }
@@ -8892,7 +8967,7 @@ require = function () {
8892
8967
  default:
8893
8968
  return source[0].trimStart() !== '';
8894
8969
  }
8895
- }, (source, _, except = '') => `${ source }\0${ except }`);
8970
+ }, (source, _, except = '') => `${ source }\x1E${ except }`);
8896
8971
  function isStartTightNodes(nodes) {
8897
8972
  if (nodes.length === 0)
8898
8973
  return true;
@@ -9477,6 +9552,7 @@ require = function () {
9477
9552
  'use strict';
9478
9553
  Object.defineProperty(exports, '__esModule', { value: true });
9479
9554
  exports.quote = void 0;
9555
+ const global_1 = _dereq_('spica/global');
9480
9556
  const parser_1 = _dereq_('../combinator/data/parser');
9481
9557
  const cite_1 = _dereq_('../parser/block/reply/cite');
9482
9558
  const typed_dom_1 = _dereq_('typed-dom');
@@ -9511,7 +9587,7 @@ require = function () {
9511
9587
  }
9512
9588
  for (let es = node.querySelectorAll('br'), i = 0, len = es.length; i < len; ++i) {
9513
9589
  const el = es[i];
9514
- if (anchor && el.nextSibling instanceof Element && el.nextSibling.matches('.cite, .quote')) {
9590
+ if (anchor && el.nextSibling instanceof global_1.Element && el.nextSibling.matches('.cite, .quote')) {
9515
9591
  el.replaceWith(`\n>${ el.nextSibling.matches('.quote.invalid') ? ' ' : '' }`);
9516
9592
  continue;
9517
9593
  }
@@ -9538,7 +9614,7 @@ require = function () {
9538
9614
  if ((_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.matches('.cite > .anchor')) {
9539
9615
  return void range.setStart(node.parentElement.previousSibling, 0);
9540
9616
  }
9541
- if (node.nodeName === 'BR' && node.nextSibling instanceof Element && node.nextSibling.matches('.cite, .quote')) {
9617
+ if (node.nodeName === 'BR' && node.nextSibling instanceof global_1.Element && node.nextSibling.matches('.cite, .quote')) {
9542
9618
  return void range.setStart(node.nextSibling.firstChild, 0);
9543
9619
  }
9544
9620
  const offset = range.startOffset;
@@ -9558,6 +9634,7 @@ require = function () {
9558
9634
  {
9559
9635
  '../combinator/data/parser': 47,
9560
9636
  '../parser/block/reply/cite': 83,
9637
+ 'spica/global': 15,
9561
9638
  'typed-dom': 26
9562
9639
  }
9563
9640
  ],