securemark 0.237.2 → 0.240.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 (42) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/securemark.js +153 -92
  3. package/markdown.d.ts +6 -4
  4. package/package-lock.json +53 -53
  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/api/header.test.ts +1 -1
  11. package/src/parser/api/header.ts +3 -3
  12. package/src/parser/api/parse.test.ts +7 -7
  13. package/src/parser/block/blockquote.test.ts +1 -1
  14. package/src/parser/block/extension/aside.test.ts +1 -1
  15. package/src/parser/block/extension/example.test.ts +2 -2
  16. package/src/parser/block/extension/fig.test.ts +22 -22
  17. package/src/parser/block/extension/fig.ts +1 -1
  18. package/src/parser/block/extension/figure.test.ts +39 -33
  19. package/src/parser/block/extension/figure.ts +51 -25
  20. package/src/parser/block/olist.test.ts +2 -0
  21. package/src/parser/block/ulist.test.ts +2 -0
  22. package/src/parser/block.ts +2 -2
  23. package/src/parser/header.test.ts +4 -4
  24. package/src/parser/header.ts +7 -5
  25. package/src/parser/inline/extension/index.test.ts +19 -13
  26. package/src/parser/inline/extension/index.ts +4 -3
  27. package/src/parser/inline/extension/indexee.ts +7 -3
  28. package/src/parser/inline/extension/indexer.test.ts +2 -1
  29. package/src/parser/inline/extension/indexer.ts +6 -3
  30. package/src/parser/inline/htmlentity.ts +2 -2
  31. package/src/parser/inline/media.ts +2 -2
  32. package/src/parser/inline/reference.test.ts +7 -7
  33. package/src/parser/inline/reference.ts +1 -1
  34. package/src/parser/inline/ruby.ts +2 -2
  35. package/src/parser/processor/figure.test.ts +79 -77
  36. package/src/parser/processor/figure.ts +32 -19
  37. package/src/parser/segment.test.ts +2 -2
  38. package/src/parser/segment.ts +2 -2
  39. package/src/parser/source/str.ts +23 -4
  40. package/src/parser/source/text.ts +3 -0
  41. package/src/parser/source.ts +1 -1
  42. package/src/parser/util.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.240.0
4
+
5
+ - Extend reference syntax not to require leading whitespace after abbr syntax.
6
+
7
+ ## 0.239.0
8
+
9
+ - Extend indexer syntax to make its own index optional.
10
+
11
+ ## 0.238.0
12
+
13
+ - Revert signature syntax not to require leading whitespace.
14
+
3
15
  ## 0.237.2
4
16
 
5
17
  - Refactoring.
@@ -1,4 +1,4 @@
1
- /*! securemark v0.237.2 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED */
1
+ /*! securemark v0.240.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 + 1 < parsers.length ? (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;
@@ -4426,13 +4415,13 @@ require = function () {
4426
4415
  function headers(source) {
4427
4416
  var _a;
4428
4417
  const [el] = parse(source);
4429
- return (_a = el === null || el === void 0 ? void 0 : el.textContent.trimEnd().slice(el.firstChild.textContent.length).split('\n')) !== null && _a !== void 0 ? _a : [];
4418
+ return (_a = el === null || el === void 0 ? void 0 : el.textContent.trimEnd().slice(el.firstChild.firstChild.textContent.length).split('\n')) !== null && _a !== void 0 ? _a : [];
4430
4419
  }
4431
4420
  exports.headers = headers;
4432
4421
  function parse(source) {
4433
4422
  const result = (0, header_1.header)(source, {});
4434
4423
  const [el] = (0, parser_1.eval)(result, []);
4435
- return el instanceof HTMLDetailsElement ? [
4424
+ return (el === null || el === void 0 ? void 0 : el.tagName) === 'ASIDE' ? [
4436
4425
  el,
4437
4426
  (0, parser_1.exec)(result)
4438
4427
  ] : [];
@@ -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
  ]);
@@ -5043,7 +5032,7 @@ require = function () {
5043
5032
  '[$',
5044
5033
  '$'
5045
5034
  ], (0, combinator_1.sequence)([
5046
- (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/)),
5047
5036
  (0, combinator_1.union)([
5048
5037
  codeblock_1.segment,
5049
5038
  mathblock_1.segment,
@@ -5119,7 +5108,7 @@ require = function () {
5119
5108
  const memoize_1 = _dereq_('spica/memoize');
5120
5109
  const array_1 = _dereq_('spica/array');
5121
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)([
5122
- (0, combinator_1.line)((0, combinator_1.close)(label_1.segment, /^.*\n/)),
5111
+ source_1.contentline,
5123
5112
  (0, combinator_1.inits)([
5124
5113
  (0, combinator_1.union)([
5125
5114
  codeblock_1.segment_,
@@ -5159,19 +5148,16 @@ require = function () {
5159
5148
  (0, combinator_1.block)((0, locale_1.localize)((0, combinator_1.context)({ syntax: { inline: { media: false } } }, (0, combinator_1.trim)((0, util_1.visualize)((0, combinator_1.some)(inline_1.inline))))))
5160
5149
  ])
5161
5150
  ])), ([label, param, content, ...caption]) => [(0, typed_dom_1.html)('figure', attributes(label.getAttribute('data-label'), param, content, caption), [
5162
- (0, typed_dom_1.html)('div', [content]),
5163
- (0, typed_dom_1.html)('figcaption', (0, array_1.unshift)([(0, typed_dom_1.html)('span', { class: 'figindex' })], (0, typed_dom_1.defrag)(caption)))
5151
+ (0, typed_dom_1.html)('figcaption', (0, array_1.unshift)([(0, typed_dom_1.html)('span', { class: 'figindex' })], (0, typed_dom_1.defrag)(caption))),
5152
+ (0, typed_dom_1.html)('div', [content])
5164
5153
  ])])));
5165
5154
  function attributes(label, param, content, caption) {
5166
5155
  const group = label.split('-', 1)[0];
5167
- const invalidLabel = /^[^-]+-(?:[0-9]+\.)*0$/.test(label);
5168
- const invalidParam = param.trimStart() !== '';
5169
- const invalidContent = group === '$' && (!content.classList.contains('math') || caption.length > 0);
5170
- const invalid = invalidLabel || invalidParam || invalidContent || global_1.undefined;
5171
5156
  let type = content.className.split(/\s/)[0];
5172
5157
  switch (type || content.tagName) {
5173
5158
  case 'UL':
5174
5159
  case 'OL':
5160
+ case 'checklist':
5175
5161
  type = 'list';
5176
5162
  break;
5177
5163
  case 'TABLE':
@@ -5191,24 +5177,49 @@ require = function () {
5191
5177
  break;
5192
5178
  default:
5193
5179
  }
5180
+ const invalid = /^[^-]+-(?:[0-9]+\.)*0$/.test(label) && {
5181
+ 'data-invalid-type': 'label',
5182
+ 'data-invalid-message': 'The last part of the fixed label numbers must not be 0'
5183
+ } || param.trimStart() !== '' && {
5184
+ 'data-invalid-type': 'argument',
5185
+ 'data-invalid-message': 'Invalid argument'
5186
+ } || group === '$' && (type !== 'math' || caption.length > 0) && {
5187
+ 'data-invalid-type': 'content',
5188
+ 'data-invalid-message': '`$` label group can only be used with a math formula with no caption'
5189
+ } || [
5190
+ 'fig',
5191
+ 'figure'
5192
+ ].includes(group) && type !== 'media' && {
5193
+ 'data-invalid-type': 'content',
5194
+ 'data-invalid-message': '`fig` and `figure` label groups can only be used with media'
5195
+ } || group === 'table' && type !== group && {
5196
+ 'data-invalid-type': 'content',
5197
+ 'data-invalid-message': '`table` label group can only be used with a table'
5198
+ } || group === 'list' && type !== group && {
5199
+ 'data-invalid-type': 'content',
5200
+ 'data-invalid-message': '`list` label group can only be used with a list'
5201
+ } || group === 'quote' && type !== group && {
5202
+ 'data-invalid-type': 'content',
5203
+ 'data-invalid-message': '`quote` label group can only be used with a blockquote'
5204
+ } || group === 'text' && type !== group && {
5205
+ 'data-invalid-type': 'content',
5206
+ 'data-invalid-message': '`text` label group can only be used with a codeblock with no language'
5207
+ } || group === 'code' && type !== group && {
5208
+ 'data-invalid-type': 'content',
5209
+ 'data-invalid-message': '`code` label group can only be used with a codeblock'
5210
+ } || group === 'example' && type !== group && {
5211
+ 'data-invalid-type': 'content',
5212
+ 'data-invalid-message': '`example` label group can only be used with an example'
5213
+ } || global_1.undefined;
5194
5214
  return {
5195
5215
  'data-type': type,
5196
5216
  'data-label': label,
5197
5217
  'data-group': group,
5198
- class: invalid && 'invalid',
5199
- ...invalidLabel && {
5200
- 'data-invalid-syntax': 'figure',
5201
- 'data-invalid-type': 'label',
5202
- 'data-invalid-message': 'The last part of the fixed label numbers must not be 0'
5203
- } || invalidParam && {
5204
- 'data-invalid-syntax': 'figure',
5205
- 'data-invalid-type': 'argument',
5206
- 'data-invalid-message': 'Invalid argument'
5207
- } || invalidContent && {
5218
+ ...invalid && {
5219
+ class: 'invalid',
5208
5220
  'data-invalid-syntax': 'figure',
5209
- 'data-invalid-type': 'content',
5210
- 'data-invalid-message': 'A figure labeled to define a formula number can contain only a math formula and no caption'
5211
- } || global_1.undefined
5221
+ ...invalid
5222
+ }
5212
5223
  };
5213
5224
  }
5214
5225
  },
@@ -6209,13 +6220,10 @@ require = function () {
6209
6220
  (0, combinator_1.guard)(context => {
6210
6221
  var _a;
6211
6222
  return (_a = context.header) !== null && _a !== void 0 ? _a : true;
6212
- }, (0, combinator_1.focus)(/^---[^\S\v\f\r\n]*\r?\n(?:[A-Za-z][0-9A-Za-z]*(?:-[A-Za-z][0-9A-Za-z]*)*:[ \t]+\S[^\v\f\r\n]*\r?\n){1,100}---[^\S\v\f\r\n]*(?:$|\r?\n)/, (0, combinator_1.convert)(source => (0, normalize_1.normalize)(source.slice(source.indexOf('\n') + 1, source.trimEnd().lastIndexOf('\n'))).replace(/(\S)\s+$/mg, '$1'), (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.union)([field])), es => [(0, typed_dom_1.html)('details', {
6213
- class: 'header',
6214
- open: ''
6215
- }, (0, typed_dom_1.defrag)([
6216
- (0, typed_dom_1.html)('summary', 'Header'),
6217
- ...es
6218
- ]))])))),
6223
+ }, (0, combinator_1.focus)(/^---[^\S\v\f\r\n]*\r?\n(?:[A-Za-z][0-9A-Za-z]*(?:-[A-Za-z][0-9A-Za-z]*)*:[ \t]+\S[^\v\f\r\n]*\r?\n){1,100}---[^\S\v\f\r\n]*(?:$|\r?\n)/, (0, combinator_1.convert)(source => (0, normalize_1.normalize)(source.slice(source.indexOf('\n') + 1, source.trimEnd().lastIndexOf('\n'))).replace(/(\S)\s+$/mg, '$1'), (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.union)([field])), es => [(0, typed_dom_1.html)('aside', { class: 'header' }, [(0, typed_dom_1.html)('details', { open: '' }, (0, typed_dom_1.defrag)([
6224
+ (0, typed_dom_1.html)('summary', 'Header'),
6225
+ ...es
6226
+ ]))])])))),
6219
6227
  source => [
6220
6228
  [(0, typed_dom_1.html)('pre', {
6221
6229
  class: 'invalid',
@@ -6235,7 +6243,7 @@ require = function () {
6235
6243
  return [
6236
6244
  [(0, typed_dom_1.html)('span', {
6237
6245
  class: 'field',
6238
- 'data-name': name,
6246
+ 'data-name': name.toLowerCase(),
6239
6247
  'data-value': value
6240
6248
  }, [
6241
6249
  (0, typed_dom_1.html)('span', { class: 'field-name' }, name),
@@ -6989,15 +6997,15 @@ require = function () {
6989
6997
  autolink: false
6990
6998
  }
6991
6999
  }
6992
- }, (0, combinator_1.some)((0, combinator_1.union)([
7000
+ }, (0, combinator_1.open)((0, source_1.stropt)('|'), (0, combinator_1.some)((0, combinator_1.union)([
6993
7001
  signature,
6994
7002
  inline_1.inline
6995
- ]), ']', /^\\?\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, {
7003
+ ]), ']', /^\\?\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, {
6996
7004
  id: el.id ? null : global_1.undefined,
6997
7005
  class: 'index',
6998
7006
  href: el.id ? `#${ el.id }` : global_1.undefined
6999
7007
  }, el.childNodes)]))));
7000
- 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)([
7008
+ 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)([
7001
7009
  bracket,
7002
7010
  source_1.txt
7003
7011
  ]), ']'))), ns => [(0, typed_dom_1.html)('span', {
@@ -7051,12 +7059,13 @@ require = function () {
7051
7059
  function text(source, optional = false) {
7052
7060
  var _a;
7053
7061
  const indexer = source.querySelector(':scope > .indexer');
7054
- if (indexer)
7055
- return indexer.getAttribute('data-index');
7056
- if (optional)
7062
+ if (!indexer && optional)
7057
7063
  return '';
7064
+ const index = indexer === null || indexer === void 0 ? void 0 : indexer.getAttribute('data-index');
7065
+ if (index)
7066
+ return index;
7058
7067
  const target = source.cloneNode(true);
7059
- for (let es = target.querySelectorAll('code[data-src], .math[data-src], .comment, rt, rp, .reference'), i = 0, len = es.length; i < len; ++i) {
7068
+ 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) {
7060
7069
  const el = es[i];
7061
7070
  switch (el.tagName) {
7062
7071
  case 'CODE':
@@ -7064,6 +7073,8 @@ require = function () {
7064
7073
  continue;
7065
7074
  case 'RT':
7066
7075
  case 'RP':
7076
+ case 'UL':
7077
+ case 'OL':
7067
7078
  el.remove();
7068
7079
  continue;
7069
7080
  }
@@ -7072,6 +7083,7 @@ require = function () {
7072
7083
  (0, typed_dom_1.define)(el, el.getAttribute('data-src'));
7073
7084
  continue;
7074
7085
  case 'comment':
7086
+ case 'checkbox':
7075
7087
  el.remove();
7076
7088
  continue;
7077
7089
  case 'reference':
@@ -7097,7 +7109,13 @@ require = function () {
7097
7109
  const combinator_1 = _dereq_('../../../combinator');
7098
7110
  const index_1 = _dereq_('./index');
7099
7111
  const typed_dom_1 = _dereq_('typed-dom');
7100
- 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', {
7112
+ 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)([
7113
+ (0, combinator_1.focus)('[#]', () => [
7114
+ [(0, typed_dom_1.html)('a', { href: '#' })],
7115
+ ''
7116
+ ]),
7117
+ index_1.index
7118
+ ])), /^\s*$/), ([el]) => el.getElementsByClassName('invalid').length === 0), ([el]) => [(0, typed_dom_1.html)('span', {
7101
7119
  class: 'indexer',
7102
7120
  'data-index': el.getAttribute('href').slice(7)
7103
7121
  })]));
@@ -7378,11 +7396,11 @@ require = function () {
7378
7396
  exports.unsafehtmlentity = (0, combinator_1.creator)((0, combinator_1.validate)('&', (0, combinator_1.focus)(/^&[0-9A-Za-z]+;/, entity => {
7379
7397
  var _a;
7380
7398
  return [
7381
- [(_a = parse(entity)) !== null && _a !== void 0 ? _a : `\0${ entity }`],
7399
+ [(_a = parse(entity)) !== null && _a !== void 0 ? _a : `\x1B${ entity }`],
7382
7400
  ''
7383
7401
  ];
7384
7402
  })));
7385
- exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([test]) => [test[0] === '\0' ? (0, typed_dom_1.html)('span', {
7403
+ exports.htmlentity = (0, combinator_1.fmap)((0, combinator_1.union)([exports.unsafehtmlentity]), ([test]) => [test[0] === '\x1B' ? (0, typed_dom_1.html)('span', {
7386
7404
  class: 'invalid',
7387
7405
  'data-invalid-syntax': 'htmlentity',
7388
7406
  'data-invalid-type': 'syntax',
@@ -7780,13 +7798,13 @@ require = function () {
7780
7798
  });
7781
7799
  return false;
7782
7800
  }
7783
- if (alt.includes('\0')) {
7801
+ if (alt.includes('\x1B')) {
7784
7802
  (0, typed_dom_1.define)(target, {
7785
7803
  class: void target.classList.add('invalid'),
7786
7804
  'data-invalid-syntax': 'media',
7787
7805
  'data-invalid-type': 'content',
7788
7806
  'data-invalid-message': `Cannot use invalid HTML entitiy "${ alt.match(/&[0-9A-Za-z]+;/)[0] }"`,
7789
- alt: (_a = target.getAttribute('alt')) === null || _a === void 0 ? void 0 : _a.replace(/\0/g, '')
7807
+ alt: (_a = target.getAttribute('alt')) === null || _a === void 0 ? void 0 : _a.replace(/\x1B/g, '')
7790
7808
  });
7791
7809
  return false;
7792
7810
  }
@@ -7840,7 +7858,7 @@ require = function () {
7840
7858
  ]),
7841
7859
  (0, util_1.trimSpaceStart)((0, combinator_1.some)(inline_1.inline, ']', /^\\?\n/))
7842
7860
  ])))), ']]'), ns => [(0, typed_dom_1.html)('sup', attributes(ns), (0, util_1.trimNodeEnd)((0, typed_dom_1.defrag)(ns)))]))));
7843
- const abbr = (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.verify)((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]+/), (_, rest, context) => (0, util_1.isStartLoose)(rest, context)), ([source]) => [(0, typed_dom_1.html)('abbr', source)]));
7861
+ const abbr = (0, combinator_1.creator)((0, combinator_1.fmap)((0, combinator_1.verify)((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]*/), (_, rest, context) => (0, util_1.isStartLoose)(rest, context)), ([source]) => [(0, typed_dom_1.html)('abbr', source)]));
7844
7862
  function attributes(ns) {
7845
7863
  return typeof ns[0] === 'object' && ns[0].tagName === 'ABBR' ? {
7846
7864
  class: 'reference',
@@ -7949,9 +7967,9 @@ require = function () {
7949
7967
  rubies
7950
7968
  ]) {
7951
7969
  for (let i = 0; i < ss.length; ++i) {
7952
- if (ss[i].indexOf('\0') === -1)
7970
+ if (ss[i].indexOf('\x1B') === -1)
7953
7971
  continue;
7954
- ss[i] = ss[i].replace(/\0/g, '');
7972
+ ss[i] = ss[i].replace(/\x1B/g, '');
7955
7973
  attrs !== null && attrs !== void 0 ? attrs : attrs = {
7956
7974
  class: 'invalid',
7957
7975
  'data-invalid-syntax': 'ruby',
@@ -8190,7 +8208,7 @@ require = function () {
8190
8208
  const def = defs[i];
8191
8209
  if (def.parentNode !== target)
8192
8210
  continue;
8193
- const {tagName, classList} = def;
8211
+ const {tagName} = def;
8194
8212
  if (bases.length === 1 && tagName[0] === 'H')
8195
8213
  continue;
8196
8214
  const label = tagName === 'FIGURE' ? def.getAttribute('data-label') : `$-${ increment(index, def) }`;
@@ -8198,7 +8216,7 @@ require = function () {
8198
8216
  continue;
8199
8217
  if (label.endsWith('-0')) {
8200
8218
  (0, typed_dom_1.define)(def, {
8201
- class: void classList.add('invalid'),
8219
+ class: void def.classList.add('invalid'),
8202
8220
  'data-invalid-syntax': 'figure',
8203
8221
  'data-invalid-type': 'argument',
8204
8222
  'data-invalid-message': 'Invalid base index',
@@ -8209,7 +8227,7 @@ require = function () {
8209
8227
  if (tagName === 'FIGURE' && label.endsWith('.0')) {
8210
8228
  if (label.lastIndexOf('.', label.length - 3) !== -1) {
8211
8229
  (0, typed_dom_1.define)(def, {
8212
- class: void classList.add('invalid'),
8230
+ class: void def.classList.add('invalid'),
8213
8231
  'data-invalid-syntax': 'figure',
8214
8232
  'data-invalid-type': 'argument',
8215
8233
  'data-invalid-message': 'Base index must be $-x.0 format',
@@ -8219,16 +8237,16 @@ require = function () {
8219
8237
  }
8220
8238
  if (!/^H[1-6]$/.test((_d = (_c = def.previousElementSibling) === null || _c === void 0 ? void 0 : _c.tagName) !== null && _d !== void 0 ? _d : '')) {
8221
8239
  (0, typed_dom_1.define)(def, {
8222
- class: void classList.add('invalid'),
8240
+ class: void def.classList.add('invalid'),
8223
8241
  'data-invalid-syntax': 'figure',
8224
8242
  'data-invalid-type': 'position',
8225
- 'data-invalid-message': 'Base index declarations must be after level 1 to 6 headings',
8243
+ 'data-invalid-message': messages.declaration,
8226
8244
  hidden: null
8227
8245
  });
8228
8246
  continue;
8229
- } else {
8230
- classList.contains('invalid') && (0, typed_dom_1.define)(def, {
8231
- class: void classList.remove('invalid'),
8247
+ } else if (def.getAttribute('data-invalid-message') === messages.declaration) {
8248
+ (0, typed_dom_1.define)(def, {
8249
+ class: void def.classList.remove('invalid'),
8232
8250
  'data-invalid-syntax': null,
8233
8251
  'data-invalid-type': null,
8234
8252
  'data-invalid-message': null,
@@ -8253,42 +8271,50 @@ require = function () {
8253
8271
  continue;
8254
8272
  }
8255
8273
  !(0, label_1.isFixed)(label) && numbers.set(group, number);
8256
- opts.id !== '' && def.setAttribute('id', `label:${ opts.id ? `${ opts.id }:` : '' }${ label }`);
8257
8274
  const figindex = group === '$' ? `(${ number })` : `${ capitalize(group) }${ group === 'fig' ? '.' : '' } ${ number }`;
8258
8275
  (0, typed_dom_1.define)(def.querySelector(':scope > figcaption > .figindex'), group === '$' ? figindex : `${ figindex }. `);
8259
8276
  if (labels.has(label)) {
8260
- if (classList.contains('invalid') && def.getAttribute('data-invalid-message') !== 'Duplicate label')
8277
+ if (def.classList.contains('invalid'))
8261
8278
  continue;
8262
8279
  (0, typed_dom_1.define)(def, {
8263
8280
  id: null,
8264
- class: void classList.add('invalid'),
8281
+ class: void def.classList.add('invalid'),
8265
8282
  'data-invalid-syntax': 'figure',
8266
8283
  'data-invalid-type': 'argument',
8267
- 'data-invalid-message': 'Duplicate label'
8284
+ 'data-invalid-message': messages.duplicate
8268
8285
  });
8269
8286
  continue;
8270
- } else {
8271
- labels.add(label);
8287
+ } else if (def.getAttribute('data-invalid-message') === messages.duplicate) {
8272
8288
  (0, typed_dom_1.define)(def, {
8273
- class: void classList.remove('invalid'),
8289
+ class: void def.classList.remove('invalid'),
8274
8290
  'data-invalid-syntax': null,
8275
8291
  'data-invalid-type': null,
8276
8292
  'data-invalid-message': null
8277
8293
  });
8278
8294
  }
8295
+ labels.add(label);
8296
+ opts.id !== '' && def.setAttribute('id', `label:${ opts.id ? `${ opts.id }:` : '' }${ label }`);
8279
8297
  for (const ref of refs.take(label, global_1.Infinity)) {
8298
+ if (ref.getAttribute('data-invalid-message') === messages.reference) {
8299
+ (0, typed_dom_1.define)(ref, {
8300
+ class: void ref.classList.remove('invalid'),
8301
+ 'data-invalid-syntax': null,
8302
+ 'data-invalid-type': null,
8303
+ 'data-invalid-message': null
8304
+ });
8305
+ }
8280
8306
  if (ref.hash.slice(1) === def.id && ref.innerText === figindex)
8281
8307
  continue;
8282
8308
  yield (0, typed_dom_1.define)(ref, opts.id !== '' ? { href: `#${ def.id }` } : { class: `${ ref.className } disabled` }, figindex);
8283
8309
  }
8284
8310
  }
8285
8311
  for (const [, ref] of refs) {
8286
- if (opts.id !== '') {
8312
+ if (opts.id !== '' && !ref.classList.contains('invalid')) {
8287
8313
  (0, typed_dom_1.define)(ref, {
8288
- class: `${ ref.className } disabled invalid`,
8314
+ class: void ref.classList.add('invalid'),
8289
8315
  'data-invalid-syntax': 'label',
8290
8316
  'data-invalid-type': 'reference',
8291
- 'data-invalid-message': 'Missing the target figure'
8317
+ 'data-invalid-message': messages.reference
8292
8318
  });
8293
8319
  }
8294
8320
  yield ref;
@@ -8296,6 +8322,11 @@ require = function () {
8296
8322
  return;
8297
8323
  }
8298
8324
  exports.figure = figure;
8325
+ const messages = {
8326
+ declaration: 'Base index declarations must be after level 1 to 6 headings',
8327
+ duplicate: 'Duplicate label',
8328
+ reference: 'Missing the target figure'
8329
+ };
8299
8330
  function increment(bases, el) {
8300
8331
  const index = (+el.tagName[1] - 1 || 1) - 1;
8301
8332
  return index + 1 < bases.length ? (0, array_1.join)(bases.slice(0, index + 2).map((v, i) => {
@@ -8477,14 +8508,14 @@ require = function () {
8477
8508
  ]);
8478
8509
  function* segment(source) {
8479
8510
  if (!validate(source, exports.MAX_INPUT_SIZE))
8480
- return yield `\0Too large input over ${ exports.MAX_INPUT_SIZE.toLocaleString('en') } bytes.\n${ source.slice(0, 1001) }`;
8511
+ return yield `\x07Too large input over ${ exports.MAX_INPUT_SIZE.toLocaleString('en') } bytes.\n${ source.slice(0, 1001) }`;
8481
8512
  while (source !== '') {
8482
8513
  const result = parser(source, {});
8483
8514
  const rest = (0, parser_1.exec)(result);
8484
8515
  const segs = (0, parser_1.eval)(result).length ? (0, parser_1.eval)(result) : [source.slice(0, source.length - rest.length)];
8485
8516
  for (let i = 0; i < segs.length; ++i) {
8486
8517
  const seg = segs[i];
8487
- validate(seg, exports.MAX_SEGMENT_SIZE) ? yield seg : yield `\0Too large segment over ${ exports.MAX_SEGMENT_SIZE.toLocaleString('en') } bytes.\n${ seg }`;
8518
+ validate(seg, exports.MAX_SEGMENT_SIZE) ? yield seg : yield `\x07Too large segment over ${ exports.MAX_SEGMENT_SIZE.toLocaleString('en') } bytes.\n${ seg }`;
8488
8519
  }
8489
8520
  source = rest;
8490
8521
  }
@@ -8510,7 +8541,7 @@ require = function () {
8510
8541
  function (_dereq_, module, exports) {
8511
8542
  'use strict';
8512
8543
  Object.defineProperty(exports, '__esModule', { value: true });
8513
- exports.anyline = exports.emptyline = exports.contentline = exports.str = exports.unescsource = exports.escsource = exports.linebreak = exports.txt = exports.text = void 0;
8544
+ exports.anyline = exports.emptyline = exports.contentline = exports.stropt = exports.str = exports.unescsource = exports.escsource = exports.linebreak = exports.txt = exports.text = void 0;
8514
8545
  var text_1 = _dereq_('./source/text');
8515
8546
  Object.defineProperty(exports, 'text', {
8516
8547
  enumerable: true,
@@ -8551,6 +8582,12 @@ require = function () {
8551
8582
  return str_1.str;
8552
8583
  }
8553
8584
  });
8585
+ Object.defineProperty(exports, 'stropt', {
8586
+ enumerable: true,
8587
+ get: function () {
8588
+ return str_1.stropt;
8589
+ }
8590
+ });
8554
8591
  var line_1 = _dereq_('./source/line');
8555
8592
  Object.defineProperty(exports, 'contentline', {
8556
8593
  enumerable: true,
@@ -8659,10 +8696,10 @@ require = function () {
8659
8696
  function (_dereq_, module, exports) {
8660
8697
  'use strict';
8661
8698
  Object.defineProperty(exports, '__esModule', { value: true });
8662
- exports.str = void 0;
8699
+ exports.stropt = exports.str = void 0;
8663
8700
  const global_1 = _dereq_('spica/global');
8664
8701
  const combinator_1 = _dereq_('../../combinator');
8665
- function str(pattern, mustConsume = true) {
8702
+ function str(pattern) {
8666
8703
  return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
8667
8704
  if (source === '')
8668
8705
  return;
@@ -8674,14 +8711,38 @@ require = function () {
8674
8711
  if (source === '')
8675
8712
  return;
8676
8713
  const m = source.match(pattern);
8677
- return m && (!mustConsume || m[0].length > 0) ? [
8714
+ return m && m[0].length > 0 ? [
8678
8715
  [m[0]],
8679
8716
  source.slice(m[0].length)
8680
8717
  ] : global_1.undefined;
8681
8718
  });
8682
8719
  }
8683
8720
  exports.str = str;
8684
- ;
8721
+ function stropt(pattern) {
8722
+ return typeof pattern === 'string' ? (0, combinator_1.creator)(source => {
8723
+ if (source === '')
8724
+ return;
8725
+ return source.slice(0, pattern.length) === pattern ? [
8726
+ [pattern],
8727
+ source.slice(pattern.length)
8728
+ ] : [
8729
+ [],
8730
+ source
8731
+ ];
8732
+ }) : (0, combinator_1.creator)(source => {
8733
+ if (source === '')
8734
+ return;
8735
+ const m = source.match(pattern);
8736
+ return m ? [
8737
+ [m[0]],
8738
+ source.slice(m[0].length)
8739
+ ] : [
8740
+ [],
8741
+ source
8742
+ ];
8743
+ });
8744
+ }
8745
+ exports.stropt = stropt;
8685
8746
  },
8686
8747
  {
8687
8748
  '../../combinator': 27,
@@ -8898,7 +8959,7 @@ require = function () {
8898
8959
  exports.startLoose = startLoose;
8899
8960
  exports.isStartLoose = (0, memoize_1.reduce)((source, context, except) => {
8900
8961
  return isStartTight(source.replace(/^[^\S\n]+/, ''), context, except);
8901
- }, (source, _, except = '') => `${ source }\0${ except }`);
8962
+ }, (source, _, except = '') => `${ source }\x1E${ except }`);
8902
8963
  function startTight(parser, except) {
8903
8964
  return (source, context) => isStartTight(source, context, except) ? parser(source, context) : global_1.undefined;
8904
8965
  }
@@ -8932,7 +8993,7 @@ require = function () {
8932
8993
  default:
8933
8994
  return source[0].trimStart() !== '';
8934
8995
  }
8935
- }, (source, _, except = '') => `${ source }\0${ except }`);
8996
+ }, (source, _, except = '') => `${ source }\x1E${ except }`);
8936
8997
  function isStartTightNodes(nodes) {
8937
8998
  if (nodes.length === 0)
8938
8999
  return true;
package/markdown.d.ts CHANGED
@@ -56,9 +56,9 @@ export namespace MarkdownParser {
56
56
  // url: https://host/path
57
57
  // ---
58
58
  Markdown<'header'>,
59
- Parser<HTMLDetailsElement | HTMLPreElement, Context, [
60
- Parser<HTMLDetailsElement | HTMLPreElement, Context, [
61
- Parser<HTMLDetailsElement, Context, [
59
+ Parser<HTMLElement | HTMLPreElement, Context, [
60
+ Parser<HTMLElement | HTMLPreElement, Context, [
61
+ Parser<HTMLElement, Context, [
62
62
  HeaderParser.FieldParser,
63
63
  ]>,
64
64
  Parser<HTMLPreElement, Context, []>,
@@ -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
  }