securemark 0.260.1 → 0.260.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.260.4
4
+
5
+ - Refactoring.
6
+
7
+ ## 0.260.3
8
+
9
+ - Refactoring.
10
+
11
+ ## 0.260.2
12
+
13
+ - Refactoring.
14
+
3
15
  ## 0.260.1
4
16
 
5
17
  - Refactoring.
package/design.md CHANGED
@@ -332,3 +332,7 @@ Data URIは保存および転送容量削減ならびにユーザーおよび管
332
332
  - \<small>: 法的表記を縮小表示すべきでないため削除。
333
333
  - \<sub>: \<small>の代わりに使用されないよう削除。他の構文との相性も悪い。
334
334
  - \<sup>: 同上。
335
+
336
+ ### _ emphasis
337
+
338
+ オートリンクと非常に相性が悪いため不採用。
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.260.1 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.260.4 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("DOMPurify"), require("Prism"));
@@ -2979,8 +2979,9 @@ function syntax(syntax, prec, cost, state, parser) {
2979
2979
 
2980
2980
  exports.syntax = syntax;
2981
2981
 
2982
- function creation(cost, parser) {
2983
- if (typeof cost === 'function') return creation(1, cost);
2982
+ function creation(cost, recursion, parser) {
2983
+ if (typeof cost === 'function') return creation(1, true, cost);
2984
+ if (typeof recursion === 'function') return creation(cost, true, recursion);
2984
2985
  return ({
2985
2986
  source,
2986
2987
  context
@@ -2991,12 +2992,12 @@ function creation(cost, parser) {
2991
2992
  };
2992
2993
  if (resources.clock <= 0) throw new Error('Too many creations');
2993
2994
  if (resources.recursion <= 0) throw new Error('Too much recursion');
2994
- --resources.recursion;
2995
+ recursion && --resources.recursion;
2995
2996
  const result = parser({
2996
2997
  source,
2997
2998
  context
2998
2999
  });
2999
- ++resources.recursion;
3000
+ recursion && ++resources.recursion;
3000
3001
 
3001
3002
  if (result) {
3002
3003
  resources.clock -= cost;
@@ -3208,14 +3209,14 @@ class Memo {
3208
3209
  }
3209
3210
 
3210
3211
  get(position, syntax, state) {
3211
- //console.log('get', position + this.offset, syntax, state, this.memory[position + this.offset - 1]?.[`${syntax}:${state}`]);;
3212
+ //console.log('get', position, syntax, state, this.memory[position - 1]?.[`${syntax}:${state}`]);;
3212
3213
  const cache = this.memory[position - 1]?.[`${syntax}:${state}`];
3213
3214
  return cache?.length === 2 ? [cache[0].slice(), cache[1]] : cache;
3214
3215
  }
3215
3216
 
3216
3217
  set(position, syntax, state, nodes, offset) {
3217
3218
  const record = this.memory[position - 1] ??= {};
3218
- record[`${syntax}:${state}`] = nodes ? [nodes.slice(), offset] : []; //console.log('set', position + this.offset, syntax, state, record[`${syntax}:${state}`]);
3219
+ record[`${syntax}:${state}`] = nodes ? [nodes.slice(), offset] : []; //console.log('set', position, syntax, state, record[`${syntax}:${state}`]);
3219
3220
  }
3220
3221
 
3221
3222
  clear(position) {
@@ -3223,7 +3224,7 @@ class Memo {
3223
3224
 
3224
3225
  for (let i = position, len = memory.length; i < len; ++i) {
3225
3226
  memory.pop();
3226
- } //console.log('clear', position + this.offset + 1);
3227
+ } //console.log('clear', position + 1);
3227
3228
 
3228
3229
  }
3229
3230
 
@@ -4115,7 +4116,7 @@ const dom_1 = __webpack_require__(3252);
4115
4116
 
4116
4117
  const random_1 = __webpack_require__(7325);
4117
4118
 
4118
- exports.block = (0, combinator_1.creation)(error((0, combinator_1.reset)({
4119
+ exports.block = (0, combinator_1.creation)(1, false, error((0, combinator_1.reset)({
4119
4120
  resources: {
4120
4121
  clock: 50 * 1000,
4121
4122
  recursion: 20
@@ -4171,8 +4172,8 @@ const indent = (0, combinator_1.block)((0, combinator_1.open)(opener, (0, combin
4171
4172
 
4172
4173
  const unindent = source => source.replace(/(^|\n)>(?:[^\S\n]|(?=>*(?:$|\s)))|\n$/g, '$1');
4173
4174
 
4174
- const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)((0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, source)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)((0, combinator_1.some)(autolink_1.autolink), ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))])))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
4175
- const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)((0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, markdown)), (0, combinator_1.creation)(99, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, ({
4175
+ const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, source)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)((0, combinator_1.some)(autolink_1.autolink), ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))])))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
4176
+ const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, markdown)), (0, combinator_1.creation)(99, false, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, ({
4176
4177
  source,
4177
4178
  context
4178
4179
  }) => {
@@ -4303,8 +4304,8 @@ exports.dlist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, locale_
4303
4304
  | 4
4304
4305
  /* State.media */
4305
4306
  , (0, combinator_1.some)(term)), (0, combinator_1.some)(desc)]))), es => [(0, dom_1.html)('dl', fillTrailingDescription(es))]))));
4306
- const term = (0, combinator_1.creation)((0, combinator_1.line)((0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.open)(/^~[^\S\n]+(?=\S)/, (0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))), true), ns => [(0, dom_1.html)('dt', (0, dom_1.defrag)(ns))]))));
4307
- const desc = (0, combinator_1.creation)((0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)(/^:[^\S\n]+(?=\S)|/, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.anyline, /^[~:][^\S\n]+\S/), (0, visibility_1.visualize)((0, combinator_1.trimEnd)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('dd', (0, dom_1.defrag)(ns))]), false));
4307
+ const term = (0, combinator_1.creation)(1, false, (0, combinator_1.line)((0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.open)(/^~[^\S\n]+(?=\S)/, (0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))), true), ns => [(0, dom_1.html)('dt', (0, dom_1.defrag)(ns))]))));
4308
+ const desc = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)(/^:[^\S\n]+(?=\S)|/, (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.anyline, /^[~:][^\S\n]+\S/), (0, visibility_1.visualize)((0, combinator_1.trimEnd)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('dd', (0, dom_1.defrag)(ns))]), false));
4308
4309
 
4309
4310
  function fillTrailingDescription(es) {
4310
4311
  return es.length > 0 && es[es.length - 1].tagName === 'DT' ? (0, array_1.push)(es, [(0, dom_1.html)('dd')]) : es;
@@ -4890,9 +4891,9 @@ const row = (0, combinator_1.lazy)(() => (0, combinator_1.dup)((0, combinator_1.
4890
4891
  const alignment = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)/;
4891
4892
  const align = (0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.union)([(0, source_1.str)(alignment)]), ([s]) => s.split('/').map(s => s.split(''))));
4892
4893
  const delimiter = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)|^[#:](?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/;
4893
- const head = (0, combinator_1.creation)((0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^#(?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.trim)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('th', attributes(ns.shift()), (0, dom_1.defrag)(ns))]), false));
4894
- const data = (0, combinator_1.creation)((0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^:(?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.trim)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('td', attributes(ns.shift()), (0, dom_1.defrag)(ns))]), false));
4895
- const dataline = (0, combinator_1.creation)((0, combinator_1.line)((0, combinator_1.rewrite)(source_1.contentline, (0, combinator_1.union)([(0, combinator_1.validate)(/^!+\s/, (0, combinator_1.convert)(source => `:${source}`, data)), (0, combinator_1.convert)(source => `: ${source}`, data)]))));
4894
+ const head = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^#(?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.trim)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('th', attributes(ns.shift()), (0, dom_1.defrag)(ns))]), false));
4895
+ const data = (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.open)((0, source_1.str)(/^:(?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/), (0, combinator_1.rewrite)((0, combinator_1.inits)([source_1.anyline, (0, combinator_1.some)(source_1.contentline, delimiter)]), (0, combinator_1.trim)((0, visibility_1.visualize)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]))))), true), ns => [(0, dom_1.html)('td', attributes(ns.shift()), (0, dom_1.defrag)(ns))]), false));
4896
+ const dataline = (0, combinator_1.creation)(1, false, (0, combinator_1.line)((0, combinator_1.rewrite)(source_1.contentline, (0, combinator_1.union)([(0, combinator_1.validate)(/^!+\s/, (0, combinator_1.convert)(source => `:${source}`, data)), (0, combinator_1.convert)(source => `: ${source}`, data)]))));
4896
4897
 
4897
4898
  function attributes(source) {
4898
4899
  let [, rowspan = global_1.undefined, colspan = global_1.undefined, highlight = global_1.undefined] = source.match(/^.(?:(\d+)?:(\d+)?)?(!+)?$/) ?? [];
@@ -5195,7 +5196,7 @@ const dom_1 = __webpack_require__(3252);
5195
5196
  exports.ilist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(/^[-+*](?=[^\S\n]|\n[^\S\n]*\S)/, (0, combinator_1.state)(4
5196
5197
  /* State.media */
5197
5198
  , exports.ilist_))));
5198
- exports.ilist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^[-+*](?:$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)((0, combinator_1.union)([(0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^[-+*](?:$|\s)/, (0, combinator_1.some)(inline_1.inline), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, olist_1.olist_, exports.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)((0, ulist_1.fillFirstLine)(ns)))])])))), es => [(0, dom_1.html)('ul', {
5199
+ exports.ilist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^[-+*](?:$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^[-+*](?:$|\s)/, (0, combinator_1.some)(inline_1.inline), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, olist_1.olist_, exports.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)((0, ulist_1.fillFirstLine)(ns)))])])))), es => [(0, dom_1.html)('ul', {
5199
5200
  class: 'invalid',
5200
5201
  'data-invalid-syntax': 'list',
5201
5202
  'data-invalid-type': 'syntax',
@@ -5284,7 +5285,7 @@ exports.olist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combina
5284
5285
  , exports.olist_))));
5285
5286
  exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => type(ms[1]).charCodeAt(0) || 0, [])), (0, combinator_1.match)(openers['('], (0, memoize_1.memoize)(ms => list(type(ms[1]), '('), ms => type(ms[1]).charCodeAt(0) || 0, []))])));
5286
5287
 
5287
- const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)((0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), exports.invalid), ns => [(0, dom_1.html)('li', {
5288
+ const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(heads[form], (0, combinator_1.subsequence)([ulist_1.checkbox, (0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, exports.olist_, ilist_1.ilist_]))]), exports.invalid), ns => [(0, dom_1.html)('li', {
5288
5289
  'data-marker': ns[0] || global_1.undefined
5289
5290
  }, (0, dom_1.defrag)((0, ulist_1.fillFirstLine)((0, array_1.shift)(ns)[1])))]), true)]))), es => [format((0, dom_1.html)('ol', es), type, form)]);
5290
5291
 
@@ -5477,7 +5478,7 @@ const source_1 = __webpack_require__(6743);
5477
5478
 
5478
5479
  const dom_1 = __webpack_require__(3252);
5479
5480
 
5480
- exports.cite = (0, combinator_1.creation)((0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.validate)('>>', (0, combinator_1.reverse)((0, combinator_1.tails)([(0, source_1.str)(/^>*(?=>>[^>\s]+[^\S\n]*(?:$|\n))/), (0, combinator_1.union)([anchor_1.anchor, // Subject page representation.
5481
+ exports.cite = (0, combinator_1.creation)(1, false, (0, combinator_1.line)((0, combinator_1.fmap)((0, combinator_1.validate)('>>', (0, combinator_1.reverse)((0, combinator_1.tails)([(0, source_1.str)(/^>*(?=>>[^>\s]+[^\S\n]*(?:$|\n))/), (0, combinator_1.union)([anchor_1.anchor, // Subject page representation.
5481
5482
  // リンクの実装は後で検討
5482
5483
  (0, combinator_1.focus)(/^>>\.[^\S\n]*(?:$|\n)/, () => [[(0, dom_1.html)('a', {
5483
5484
  class: 'anchor'
@@ -5523,7 +5524,7 @@ const autolink_1 = __webpack_require__(6578);
5523
5524
  const dom_1 = __webpack_require__(3252);
5524
5525
 
5525
5526
  exports.syntax = /^>+(?=[^\S\n])|^>(?=[^\s>])|^>+(?=[^\s>])(?![0-9a-z]+(?:-[0-9a-z]+)*(?![0-9A-Za-z@#:]))/;
5526
- exports.quote = (0, combinator_1.lazy)(() => (0, combinator_1.creation)((0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)('>', (0, combinator_1.union)([(0, combinator_1.rewrite)((0, combinator_1.some)((0, combinator_1.validate)(new RegExp(exports.syntax.source.split('|')[0]), source_1.anyline)), qblock), (0, combinator_1.rewrite)((0, combinator_1.validate)(new RegExp(exports.syntax.source.split('|').slice(1).join('|')), source_1.anyline), (0, combinator_1.line)((0, combinator_1.union)([(0, source_1.str)(/^.+/)])))])), ns => [(0, dom_1.html)('span', ns.length > 1 ? {
5527
+ exports.quote = (0, combinator_1.lazy)(() => (0, combinator_1.creation)(1, false, (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)('>', (0, combinator_1.union)([(0, combinator_1.rewrite)((0, combinator_1.some)((0, combinator_1.validate)(new RegExp(exports.syntax.source.split('|')[0]), source_1.anyline)), qblock), (0, combinator_1.rewrite)((0, combinator_1.validate)(new RegExp(exports.syntax.source.split('|').slice(1).join('|')), source_1.anyline), (0, combinator_1.line)((0, combinator_1.union)([(0, source_1.str)(/^.+/)])))])), ns => [(0, dom_1.html)('span', ns.length > 1 ? {
5527
5528
  class: 'quote'
5528
5529
  } : {
5529
5530
  class: 'quote invalid',
@@ -5606,7 +5607,7 @@ const opener = /^(?=\|\|+(?:$|\s))/;
5606
5607
 
5607
5608
  const unindent = source => source.replace(/(^|\n)\|(?:[^\S\n]|(?=\|*(?:$|\s)))|\n$/g, '$1');
5608
5609
 
5609
- const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)((0, combinator_1.union)([(0, combinator_1.focus)(/^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/, (0, combinator_1.convert)(unindent, source)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)((0, combinator_1.some)(autolink_1.autolink), ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))])))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
5610
+ const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, combinator_1.focus)(/^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/, (0, combinator_1.convert)(unindent, source)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)((0, combinator_1.some)(autolink_1.autolink), ns => [(0, dom_1.html)('pre', (0, dom_1.defrag)(ns))])))]))), ns => [(0, dom_1.html)('blockquote', ns)]));
5610
5611
 
5611
5612
  /***/ }),
5612
5613
 
@@ -5637,7 +5638,7 @@ const array_1 = __webpack_require__(8112);
5637
5638
 
5638
5639
  exports.table = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^\|[^\n]*(?:\n\|[^\n]*){2}/, (0, combinator_1.sequence)([row((0, combinator_1.some)(head), true), row((0, combinator_1.some)(align), false), (0, combinator_1.some)(row((0, combinator_1.some)(data), true))])), rows => [(0, dom_1.html)('table', [(0, dom_1.html)('thead', [rows.shift()]), (0, dom_1.html)('tbody', format(rows))])])));
5639
5640
 
5640
- const row = (parser, optional) => (0, combinator_1.creation)((0, combinator_1.fallback)((0, combinator_1.fmap)((0, combinator_1.line)((0, combinator_1.surround)(/^(?=\|)/, (0, combinator_1.some)((0, combinator_1.union)([parser])), /^[|\\]?\s*$/, optional)), es => [(0, dom_1.html)('tr', es)]), (0, combinator_1.rewrite)(source_1.contentline, ({
5641
+ const row = (parser, optional) => (0, combinator_1.creation)(1, false, (0, combinator_1.fallback)((0, combinator_1.fmap)((0, combinator_1.line)((0, combinator_1.surround)(/^(?=\|)/, (0, combinator_1.some)((0, combinator_1.union)([parser])), /^[|\\]?\s*$/, optional)), es => [(0, dom_1.html)('tr', es)]), (0, combinator_1.rewrite)(source_1.contentline, ({
5641
5642
  source
5642
5643
  }) => [[(0, dom_1.html)('tr', {
5643
5644
  class: 'invalid',
@@ -5646,10 +5647,10 @@ const row = (parser, optional) => (0, combinator_1.creation)((0, combinator_1.fa
5646
5647
  'data-invalid-message': 'Missing the start symbol of the table row'
5647
5648
  }, [(0, dom_1.html)('td', source.replace('\n', ''))])], ''])));
5648
5649
 
5649
- const align = (0, combinator_1.creation)((0, combinator_1.fmap)((0, combinator_1.open)('|', (0, combinator_1.union)([(0, combinator_1.focus)(/^:-+:/, () => [['center'], '']), (0, combinator_1.focus)(/^:-+/, () => [['start'], '']), (0, combinator_1.focus)(/^-+:/, () => [['end'], '']), (0, combinator_1.focus)(/^-+/, () => [[''], ''])])), ns => [(0, dom_1.html)('td', (0, dom_1.defrag)(ns))]));
5650
+ const align = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)((0, combinator_1.open)('|', (0, combinator_1.union)([(0, combinator_1.focus)(/^:-+:/, () => [['center'], '']), (0, combinator_1.focus)(/^:-+/, () => [['start'], '']), (0, combinator_1.focus)(/^-+:/, () => [['end'], '']), (0, combinator_1.focus)(/^-+/, () => [[''], ''])])), ns => [(0, dom_1.html)('td', (0, dom_1.defrag)(ns))]));
5650
5651
  const cell = (0, combinator_1.surround)(/^\|\s*(?=\S)/, (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]), /^[^|]*/, true);
5651
- const head = (0, combinator_1.creation)((0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('th', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))]));
5652
- const data = (0, combinator_1.creation)((0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('td', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))]));
5652
+ const head = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('th', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))]));
5653
+ const data = (0, combinator_1.creation)(1, false, (0, combinator_1.fmap)(cell, ns => [(0, dom_1.html)('td', (0, visibility_1.trimNode)((0, dom_1.defrag)(ns)))]));
5653
5654
 
5654
5655
  function format(rows) {
5655
5656
  const aligns = rows[0].className === 'invalid' ? [] : (0, duff_1.duffReduce)(rows.shift().children, (acc, el) => (0, array_1.push)(acc, [el.textContent]), []);
@@ -5698,8 +5699,8 @@ const array_1 = __webpack_require__(8112);
5698
5699
  exports.ulist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(/^-(?=[^\S\n]|\n[^\S\n]*\S)/, (0, combinator_1.state)(4
5699
5700
  /* State.media */
5700
5701
  , exports.ulist_))));
5701
- exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^-(?=$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)((0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^-(?:$|\s)/, (0, combinator_1.subsequence)([exports.checkbox, (0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([exports.ulist_, olist_1.olist_, ilist_1.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)(fillFirstLine(ns)))]), true)])))), es => [format((0, dom_1.html)('ul', es))])));
5702
- exports.checkbox = (0, combinator_1.creation)((0, combinator_1.focus)(/^\[[xX ]\](?=$|\s)/, ({
5702
+ exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/^-(?=$|\s)/, (0, combinator_1.some)((0, combinator_1.creation)(1, false, (0, combinator_1.union)([(0, inline_1.indexee)((0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/^-(?:$|\s)/, (0, combinator_1.subsequence)([exports.checkbox, (0, visibility_1.trimBlank)((0, combinator_1.some)((0, combinator_1.union)([inline_1.indexer, inline_1.inline])))]), true)), (0, combinator_1.indent)((0, combinator_1.union)([exports.ulist_, olist_1.olist_, ilist_1.ilist_]))]), olist_1.invalid), ns => [(0, dom_1.html)('li', (0, dom_1.defrag)(fillFirstLine(ns)))]), true)])))), es => [format((0, dom_1.html)('ul', es))])));
5703
+ exports.checkbox = (0, combinator_1.creation)(1, false, (0, combinator_1.focus)(/^\[[xX ]\](?=$|\s)/, ({
5703
5704
  source
5704
5705
  }) => [[(0, dom_1.html)('span', {
5705
5706
  class: 'checkbox'
@@ -5943,15 +5944,15 @@ const source_1 = __webpack_require__(6743);
5943
5944
 
5944
5945
  const util_1 = __webpack_require__(9437);
5945
5946
 
5946
- exports.autolink = (0, combinator_1.fmap)((0, combinator_1.validate)(/^(?:[@#>0-9A-Za-z]|\S[#>])/, (0, combinator_1.constraint)(2
5947
+ exports.autolink = (0, combinator_1.fmap)((0, combinator_1.validate)(/^(?:[@#>0-9a-z]|\S[#>])/i, (0, combinator_1.constraint)(2
5947
5948
  /* State.autolink */
5948
5949
  , false, (0, combinator_1.syntax)(2
5949
5950
  /* Syntax.autolink */
5950
5951
  , 1, 1, 0
5951
5952
  /* State.none */
5952
5953
  , (0, combinator_1.some)((0, combinator_1.union)([url_1.url, email_1.email, // Escape unmatched email-like strings.
5953
- (0, source_1.str)(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*(?:@(?:[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?)*/), channel_1.channel, account_1.account, // Escape unmatched account-like strings.
5954
- (0, source_1.str)(/^@+[0-9A-Za-z]*(?:-[0-9A-Za-z]+)*/), // Escape invalid leading characters.
5954
+ (0, source_1.str)(/^[0-9a-z]+(?:[.+_-][0-9a-z]+)*(?:@(?:[0-9a-z]+(?:[.-][0-9a-z]+)*)?)*/i), channel_1.channel, account_1.account, // Escape unmatched account-like strings.
5955
+ (0, source_1.str)(/^@+[0-9a-z]*(?:-[0-9a-z]+)*/i), // Escape invalid leading characters.
5955
5956
  (0, source_1.str)(new RegExp(/^(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])(?=#)/u.source.replace('emoji', hashtag_1.emoji), 'u')), hashtag_1.hashtag, hashnum_1.hashnum, // Escape unmatched hashtag-like strings.
5956
5957
  (0, source_1.str)(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])*/u.source.replace('emoji', hashtag_1.emoji), 'u')), anchor_1.anchor]))))), ns => ns.length === 1 ? ns : [(0, util_1.stringify)(ns)]);
5957
5958
 
@@ -5979,7 +5980,7 @@ const dom_1 = __webpack_require__(3252); // https://example/@user must be a user
5979
5980
 
5980
5981
  exports.account = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.constraint)(1
5981
5982
  /* State.shortcut */
5982
- , false, (0, combinator_1.open)('@', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(/^[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*/), ([source]) => source.length <= 64)]))), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/@')}` : `/${source}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
5983
+ , false, (0, combinator_1.open)('@', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?)*\//i), ([source]) => source.length <= 253 + 1), (0, source_1.str)(/^[a-z](?:-(?=[0-9a-z])|[0-9a-z]){0,63}/i)]))), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/@')}` : `/${source}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
5983
5984
  class: 'account'
5984
5985
  })]));
5985
5986
 
@@ -6010,7 +6011,7 @@ const dom_1 = __webpack_require__(3252); // Timeline(pseudonym): user/tid
6010
6011
 
6011
6012
  exports.anchor = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('>>', (0, combinator_1.fmap)((0, combinator_1.constraint)(1
6012
6013
  /* State.shortcut */
6013
- , false, (0, combinator_1.focus)(/^>>(?:[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*\/)?[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*(?![0-9A-Za-z@#:])/, (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `/@${source.slice(2).replace('/', '/timeline/')}` : `?at=${source.slice(2)}`} }`, (0, combinator_1.union)([link_1.unsafelink])))), ([el]) => [(0, dom_1.define)(el, {
6014
+ , false, (0, combinator_1.focus)(/^>>(?:[a-z][0-9a-z]*(?:-[0-9a-z]+)*\/)?[0-9a-z]+(?:-[0-9a-z]+)*(?![0-9a-z@#:])/i, (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `/@${source.slice(2).replace('/', '/timeline/')}` : `?at=${source.slice(2)}`} }`, (0, combinator_1.union)([link_1.unsafelink])))), ([el]) => [(0, dom_1.define)(el, {
6014
6015
  class: 'anchor'
6015
6016
  })])));
6016
6017
 
@@ -6069,7 +6070,7 @@ const source_1 = __webpack_require__(6743);
6069
6070
  const dom_1 = __webpack_require__(3252); // https://html.spec.whatwg.org/multipage/input.html
6070
6071
 
6071
6072
 
6072
- exports.email = (0, combinator_1.creation)((0, combinator_1.rewrite)((0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*@[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*(?![0-9A-Za-z])/), ([source]) => source.indexOf('@') <= 64 && source.length <= 255), ({
6073
+ exports.email = (0, combinator_1.creation)((0, combinator_1.rewrite)((0, combinator_1.verify)((0, source_1.str)(/^[0-9a-z](?:[.+_-](?=[^\W_])|[0-9a-z]){0,255}@[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?)*(?![0-9a-z])/i), ([source]) => source.length <= 255), ({
6073
6074
  source
6074
6075
  }) => [[(0, dom_1.html)('a', {
6075
6076
  class: 'email',
@@ -6132,7 +6133,7 @@ const dom_1 = __webpack_require__(3252); // https://example/hashtags/a must be a
6132
6133
  exports.emoji = String.raw`\p{Emoji_Modifier_Base}\p{Emoji_Modifier}?|\p{Emoji_Presentation}|\p{Emoji}\uFE0F`;
6133
6134
  exports.hashtag = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.rewrite)((0, combinator_1.constraint)(1
6134
6135
  /* State.shortcut */
6135
- , false, (0, combinator_1.open)('#', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(new RegExp([/^(?=[0-9]{0,127}_?(?:[^\d\p{C}\p{S}\p{P}\s]|emoji))/u.source, /(?:[^\p{C}\p{S}\p{P}\s]|emoji|_(?=[^\p{C}\p{S}\p{P}\s]|emoji)){1,128}/u.source, /(?!_?(?:[^\p{C}\p{S}\p{P}\s]|emoji)|')/u.source].join('').replace(/emoji/g, exports.emoji), 'u')), ([source]) => source.length <= 128)]))), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/hashtags/')}` : `/hashtags/${source.slice(1)}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
6136
+ , false, (0, combinator_1.open)('#', (0, combinator_1.tails)([(0, combinator_1.verify)((0, source_1.str)(/^[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?)*\//i), ([source]) => source.length <= 253 + 1), (0, combinator_1.verify)((0, source_1.str)(new RegExp([/^(?=[0-9]{0,127}_?(?:[^\d\p{C}\p{S}\p{P}\s]|emoji))/u.source, /(?:[^\p{C}\p{S}\p{P}\s]|emoji|_(?=[^\p{C}\p{S}\p{P}\s]|emoji)){1,128}/u.source, /(?!_?(?:[^\p{C}\p{S}\p{P}\s]|emoji)|')/u.source].join('').replace(/emoji/g, exports.emoji), 'u')), ([source]) => source.length <= 128)]))), (0, combinator_1.convert)(source => `[${source}]{ ${source.includes('/') ? `https://${source.slice(1).replace('/', '/hashtags/')}` : `/hashtags/${source.slice(1)}`} }`, (0, combinator_1.union)([link_1.unsafelink]))), ([el]) => [(0, dom_1.define)(el, {
6136
6137
  class: 'hashtag'
6137
6138
  }, el.innerText)]));
6138
6139
 
@@ -6706,8 +6707,8 @@ const array_1 = __webpack_require__(8112); // Don't use the symbols already used
6706
6707
  // All syntax surrounded by square brackets shouldn't contain line breaks.
6707
6708
 
6708
6709
 
6709
- exports.placeholder = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[:', '[^'], (0, combinator_1.surround)((0, source_1.str)(/^\[[:^]/), (0, combinator_1.syntax)(0
6710
- /* Syntax.none */
6710
+ exports.placeholder = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(['[:', '[^'], (0, combinator_1.surround)((0, source_1.str)(/^\[[:^]/), (0, combinator_1.syntax)(512
6711
+ /* Syntax.placeholder */
6711
6712
  , 2, 1, 0
6712
6713
  /* State.none */
6713
6714
  , (0, visibility_1.startTight)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[/^\\?\n/, 9], [']', 2]]))), (0, source_1.str)(']'), false, ([as, bs], rest) => [[(0, dom_1.html)('span', {
@@ -6930,17 +6931,6 @@ const textlink = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(8
6930
6931
  , 2, 10, 254
6931
6932
  /* State.linkable */
6932
6933
  , (0, combinator_1.bind)((0, combinator_1.reverse)((0, combinator_1.tails)([(0, combinator_1.dup)((0, combinator_1.surround)('[', (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), ']', [[/^\\?\n/, 9], [']', 2]]), ']', true)), (0, combinator_1.dup)((0, combinator_1.surround)(/^{(?![{}])/, (0, combinator_1.inits)([exports.uri, (0, combinator_1.some)(exports.option)]), /^[^\S\n]*}/))])), ([params, content = []], rest, context) => {
6933
- if (content.length !== 0 && (0, visibility_1.trimNode)(content).length === 0) return;
6934
-
6935
- for (let source = (0, util_1.stringify)(content); source;) {
6936
- const result = autolink({
6937
- source,
6938
- context
6939
- });
6940
- if (typeof (0, parser_1.eval)(result, [])[0] === 'object') return;
6941
- source = (0, parser_1.exec)(result, '');
6942
- }
6943
-
6944
6934
  return parse(content, params, rest, context);
6945
6935
  }))));
6946
6936
  const medialink = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(8
@@ -6964,8 +6954,37 @@ const autolink = (0, combinator_1.state)(2
6964
6954
  , autolink_1.autolink));
6965
6955
 
6966
6956
  function parse(content, params, rest, context) {
6957
+ if (content.length !== 0 && (0, visibility_1.trimNode)(content).length === 0) return;
6958
+ content = (0, dom_1.defrag)(content);
6959
+
6960
+ for (let source = (0, util_1.stringify)(content); source;) {
6961
+ if (/^[a-z][0-9a-z]*(?:[-.][0-9a-z]+)*:(?:\/{0,2}[^/?#\s]+|\/\/(?=[/]))/i.test(source)) return;
6962
+ const result = autolink({
6963
+ source,
6964
+ context
6965
+ });
6966
+ if (typeof (0, parser_1.eval)(result, [])[0] === 'object') return;
6967
+ source = (0, parser_1.exec)(result, '');
6968
+ }
6969
+
6967
6970
  const INSECURE_URI = params.shift();
6968
- const el = elem(INSECURE_URI, (0, dom_1.defrag)(content), new url_1.ReadonlyURL(resolve(INSECURE_URI, context.host ?? global_1.location, context.url ?? context.host ?? global_1.location), context.host?.href || global_1.location.href), context.host?.origin || global_1.location.origin);
6971
+ const uri = new url_1.ReadonlyURL(resolve(INSECURE_URI, context.host ?? global_1.location, context.url ?? context.host ?? global_1.location), context.host?.href || global_1.location.href);
6972
+
6973
+ switch (uri.protocol) {
6974
+ case 'tel:':
6975
+ {
6976
+ const tel = content.length === 0 ? INSECURE_URI : content[0];
6977
+ const pattern = /^(?:tel:)?(?:\+(?!0))?\d+(?:-\d+)*$/i;
6978
+
6979
+ if (content.length <= 1 && typeof tel === 'string' && pattern.test(tel) && pattern.test(INSECURE_URI) && tel.replace(/[^+\d]/g, '') === INSECURE_URI.replace(/[^+\d]/g, '')) {
6980
+ break;
6981
+ }
6982
+
6983
+ return;
6984
+ }
6985
+ }
6986
+
6987
+ const el = elem(INSECURE_URI, content, uri, context.host?.origin || global_1.location.origin);
6969
6988
  if (el.className === 'invalid') return [[el], rest];
6970
6989
  return [[(0, dom_1.define)(el, (0, html_1.attributes)('link', [], optspec, params))], rest];
6971
6990
  }
@@ -6990,23 +7009,10 @@ function elem(INSECURE_URI, content, uri, origin) {
6990
7009
  }, content.length === 0 ? decode(INSECURE_URI) : content);
6991
7010
 
6992
7011
  case 'tel:':
6993
- if (content.length === 0) {
6994
- content = [INSECURE_URI];
6995
- }
6996
-
6997
- const pattern = /^(?:tel:)?(?:\+(?!0))?\d+(?:-\d+)*$/i;
6998
-
6999
- switch (true) {
7000
- case content.length === 1 && typeof content[0] === 'string' && pattern.test(INSECURE_URI) && pattern.test(content[0]) && INSECURE_URI.replace(/[^+\d]/g, '') === content[0].replace(/[^+\d]/g, ''):
7001
- return (0, dom_1.html)('a', {
7002
- class: 'tel',
7003
- href: uri.source
7004
- }, content);
7005
- }
7006
-
7007
- type = 'content';
7008
- message = 'Invalid phone number';
7009
- break;
7012
+ return (0, dom_1.html)('a', {
7013
+ class: 'tel',
7014
+ href: uri.source
7015
+ }, content.length === 0 ? [INSECURE_URI] : content);
7010
7016
  }
7011
7017
 
7012
7018
  return (0, dom_1.html)('a', {
@@ -7022,7 +7028,7 @@ function resolve(uri, host, source) {
7022
7028
  case uri.slice(0, 2) === '^/':
7023
7029
  const last = host.pathname.slice(host.pathname.lastIndexOf('/') + 1);
7024
7030
  return last.includes('.') // isFile
7025
- && /^[0-9]*[A-Za-z][0-9A-Za-z]*$/.test(last.slice(last.lastIndexOf('.') + 1)) ? `${host.pathname.slice(0, -last.length)}${uri.slice(2)}` : `${host.pathname.replace(/\/?$/, '/')}${uri.slice(2)}`;
7031
+ && /^[0-9]*[a-z][0-9a-z]*$/i.test(last.slice(last.lastIndexOf('.') + 1)) ? `${host.pathname.slice(0, -last.length)}${uri.slice(2)}` : `${host.pathname.replace(/\/?$/, '/')}${uri.slice(2)}`;
7026
7032
 
7027
7033
  case host.origin === source.origin && host.pathname === source.pathname:
7028
7034
  case uri.slice(0, 2) === '//':
@@ -7038,9 +7044,16 @@ exports.resolve = resolve;
7038
7044
 
7039
7045
  function decode(uri) {
7040
7046
  if (!uri.includes('%')) return uri;
7047
+ const origin = uri.match(/^[a-z](?:[-.](?=\w)|[0-9a-z])*:(?:\/{0,2}[^/?#\s]+|\/\/(?=[/]))/i)?.[0] ?? '';
7041
7048
 
7042
7049
  try {
7043
- uri = (0, global_1.decodeURI)(uri);
7050
+ let path = (0, global_1.decodeURI)(uri.slice(origin.length));
7051
+
7052
+ if (!origin && /^[a-z](?:[-.](?=\w)|[0-9a-z])*:(?:\/{0,2}[^/?#\s]+|\/\/(?=[/]))/i.test(path)) {
7053
+ path = uri.slice(origin.length);
7054
+ }
7055
+
7056
+ uri = origin + path;
7044
7057
  } finally {
7045
7058
  return uri.replace(/\s+/g, global_1.encodeURI);
7046
7059
  }
@@ -7340,7 +7353,7 @@ exports.ruby = (0, combinator_1.lazy)(() => (0, combinator_1.validate)('[', (0,
7340
7353
  return [(0, dom_1.html)('ruby', attributes(texts, rubies), (0, dom_1.defrag)((0, array_1.unshift)([texts.join(' ')], [(0, dom_1.html)('rp', '('), (0, dom_1.html)('rt', rubies.join(' ').trim()), (0, dom_1.html)('rp', ')')])))];
7341
7354
  }
7342
7355
  }))));
7343
- const text = (0, combinator_1.creation)(({
7356
+ const text = (0, combinator_1.creation)(1, false, ({
7344
7357
  source,
7345
7358
  context
7346
7359
  }) => {
@@ -8151,7 +8164,7 @@ const combinator_1 = __webpack_require__(2087);
8151
8164
  const text_1 = __webpack_require__(7763);
8152
8165
 
8153
8166
  const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
8154
- exports.escsource = (0, combinator_1.creation)(({
8167
+ exports.escsource = (0, combinator_1.creation)(1, false, ({
8155
8168
  source
8156
8169
  }) => {
8157
8170
  if (source === '') return;
@@ -8219,12 +8232,12 @@ const global_1 = __webpack_require__(4128);
8219
8232
  const combinator_1 = __webpack_require__(2087);
8220
8233
 
8221
8234
  function str(pattern) {
8222
- return typeof pattern === 'string' ? (0, combinator_1.creation)(({
8235
+ return typeof pattern === 'string' ? (0, combinator_1.creation)(1, false, ({
8223
8236
  source
8224
8237
  }) => {
8225
8238
  if (source === '') return;
8226
8239
  return source.slice(0, pattern.length) === pattern ? [[pattern], source.slice(pattern.length)] : global_1.undefined;
8227
- }) : (0, combinator_1.creation)(({
8240
+ }) : (0, combinator_1.creation)(1, false, ({
8228
8241
  source
8229
8242
  }) => {
8230
8243
  if (source === '') return;
@@ -8236,12 +8249,12 @@ function str(pattern) {
8236
8249
  exports.str = str;
8237
8250
 
8238
8251
  function stropt(pattern) {
8239
- return typeof pattern === 'string' ? (0, combinator_1.creation)(({
8252
+ return typeof pattern === 'string' ? (0, combinator_1.creation)(1, false, ({
8240
8253
  source
8241
8254
  }) => {
8242
8255
  if (source === '') return;
8243
8256
  return source.slice(0, pattern.length) === pattern ? [[pattern], source.slice(pattern.length)] : global_1.undefined;
8244
- }) : (0, combinator_1.creation)(({
8257
+ }) : (0, combinator_1.creation)(1, false, ({
8245
8258
  source
8246
8259
  }) => {
8247
8260
  if (source === '') return;
@@ -8277,11 +8290,7 @@ exports.delimiter = /[\s\x00-\x7F]|\S[#>]|[()、。!?][^\S\n]*(?=\\\n)/;
8277
8290
  exports.nonWhitespace = /[\S\n]|$/;
8278
8291
  exports.nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/;
8279
8292
  const repeat = (0, str_1.str)(/^(.)\1*/);
8280
- exports.text = (0, combinator_1.syntax)(0
8281
- /* Syntax.none */
8282
- , 1, 1, 0
8283
- /* State.none */
8284
- , ({
8293
+ exports.text = (0, combinator_1.creation)(1, false, ({
8285
8294
  source,
8286
8295
  context
8287
8296
  }) => {
@@ -8385,7 +8394,7 @@ const combinator_1 = __webpack_require__(2087);
8385
8394
 
8386
8395
  const text_1 = __webpack_require__(7763);
8387
8396
 
8388
- exports.unescsource = (0, combinator_1.creation)(({
8397
+ exports.unescsource = (0, combinator_1.creation)(1, false, ({
8389
8398
  source
8390
8399
  }) => {
8391
8400
  if (source === '') return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.260.1",
3
+ "version": "0.260.4",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -34,11 +34,11 @@
34
34
  "@types/mocha": "9.1.1",
35
35
  "@types/power-assert": "1.5.8",
36
36
  "@types/prismjs": "1.26.0",
37
- "@typescript-eslint/parser": "^5.29.0",
37
+ "@typescript-eslint/parser": "^5.30.7",
38
38
  "babel-loader": "^8.2.5",
39
39
  "babel-plugin-unassert": "^3.2.0",
40
- "concurrently": "^7.2.2",
41
- "eslint": "^8.18.0",
40
+ "concurrently": "^7.3.0",
41
+ "eslint": "^8.20.0",
42
42
  "eslint-plugin-redos": "^4.4.1",
43
43
  "eslint-webpack-plugin": "^3.2.0",
44
44
  "glob": "^8.0.3",
@@ -49,7 +49,7 @@
49
49
  "karma-mocha": "^2.0.1",
50
50
  "karma-power-assert": "^1.0.0",
51
51
  "mocha": "^10.0.0",
52
- "npm-check-updates": "^14.1.1",
52
+ "npm-check-updates": "^15.3.4",
53
53
  "semver": "^7.3.7",
54
54
  "spica": "0.0.573",
55
55
  "ts-loader": "^9.3.1",
@@ -8,7 +8,7 @@ export class Memo {
8
8
  syntax: number,
9
9
  state: number,
10
10
  ): readonly [any[], number] | readonly [] | undefined {
11
- //console.log('get', position + this.offset, syntax, state, this.memory[position + this.offset - 1]?.[`${syntax}:${state}`]);;
11
+ //console.log('get', position, syntax, state, this.memory[position - 1]?.[`${syntax}:${state}`]);;
12
12
  const cache = this.memory[position - 1]?.[`${syntax}:${state}`];
13
13
  return cache?.length === 2
14
14
  ? [cache[0].slice(), cache[1]]
@@ -26,13 +26,13 @@ export class Memo {
26
26
  record[`${syntax}:${state}`] = nodes
27
27
  ? [nodes.slice(), offset]
28
28
  : [];
29
- //console.log('set', position + this.offset, syntax, state, record[`${syntax}:${state}`]);
29
+ //console.log('set', position, syntax, state, record[`${syntax}:${state}`]);
30
30
  }
31
31
  public clear(position: number): void {
32
32
  const memory = this.memory;
33
33
  for (let i = position, len = memory.length; i < len; ++i) {
34
34
  memory.pop();
35
35
  }
36
- //console.log('clear', position + this.offset + 1);
36
+ //console.log('clear', position + 1);
37
37
  }
38
38
  }
@@ -87,16 +87,18 @@ export function syntax<T>(syntax: number, prec: number, cost: number, state: num
87
87
 
88
88
  export function creation<P extends Parser<unknown>>(parser: P): P;
89
89
  export function creation<P extends Parser<unknown>>(cost: number, parser: P): P;
90
- export function creation(cost: number | Parser<unknown>, parser?: Parser<unknown>): Parser<unknown> {
91
- if (typeof cost === 'function') return creation(1, cost);
90
+ export function creation<P extends Parser<unknown>>(cost: number, recursion: boolean, parser: P): P;
91
+ export function creation(cost: number | Parser<unknown>, recursion?: boolean | Parser<unknown>, parser?: Parser<unknown>): Parser<unknown> {
92
+ if (typeof cost === 'function') return creation(1, true, cost);
93
+ if (typeof recursion === 'function') return creation(cost, true, recursion);
92
94
  assert(cost > 0);
93
95
  return ({ source, context }) => {
94
96
  const resources = context.resources ?? { clock: 1, recursion: 1 };
95
97
  if (resources.clock <= 0) throw new Error('Too many creations');
96
98
  if (resources.recursion <= 0) throw new Error('Too much recursion');
97
- --resources.recursion;
99
+ recursion && --resources.recursion;
98
100
  const result = parser!({ source, context });
99
- ++resources.recursion;
101
+ recursion && ++resources.recursion;
100
102
  if (result) {
101
103
  resources.clock -= cost;
102
104
  }
@@ -19,7 +19,7 @@ const indent = block(open(opener, some(contentline, /^>(?:$|\s)/)), false);
19
19
  const unindent = (source: string) => source.replace(/(^|\n)>(?:[^\S\n]|(?=>*(?:$|\s)))|\n$/g, '$1');
20
20
 
21
21
  const source: BlockquoteParser.SourceParser = lazy(() => fmap(
22
- some(creation(union([
22
+ some(creation(1, false, union([
23
23
  rewrite(
24
24
  indent,
25
25
  convert(unindent, source)),
@@ -30,11 +30,11 @@ const source: BlockquoteParser.SourceParser = lazy(() => fmap(
30
30
  ns => [html('blockquote', ns)]));
31
31
 
32
32
  const markdown: BlockquoteParser.MarkdownParser = lazy(() => fmap(
33
- some(creation(union([
33
+ some(creation(1, false, union([
34
34
  rewrite(
35
35
  indent,
36
36
  convert(unindent, markdown)),
37
- creation(99,
37
+ creation(99, false,
38
38
  rewrite(
39
39
  some(contentline, opener),
40
40
  convert(unindent, ({ source, context }) => {
@@ -17,13 +17,13 @@ export const dlist: DListParser = lazy(() => block(localize(fmap(validate(
17
17
  ]))),
18
18
  es => [html('dl', fillTrailingDescription(es))]))));
19
19
 
20
- const term: DListParser.TermParser = creation(line(indexee(fmap(open(
20
+ const term: DListParser.TermParser = creation(1, false, line(indexee(fmap(open(
21
21
  /^~[^\S\n]+(?=\S)/,
22
22
  visualize(trimBlank(some(union([indexer, inline])))),
23
23
  true),
24
24
  ns => [html('dt', defrag(ns))]))));
25
25
 
26
- const desc: DListParser.DescriptionParser = creation(block(fmap(open(
26
+ const desc: DListParser.DescriptionParser = creation(1, false, block(fmap(open(
27
27
  /^:[^\S\n]+(?=\S)|/,
28
28
  rewrite(
29
29
  some(anyline, /^[~:][^\S\n]+\S/),
@@ -79,7 +79,7 @@ const align: AlignParser = line(fmap(
79
79
 
80
80
  const delimiter = /^[-=<>]+(?:\/[-=^v]*)?(?=[^\S\n]*\n)|^[#:](?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/;
81
81
 
82
- const head: CellParser.HeadParser = creation(block(fmap(open(
82
+ const head: CellParser.HeadParser = creation(1, false, block(fmap(open(
83
83
  str(/^#(?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/),
84
84
  rewrite(
85
85
  inits([
@@ -91,7 +91,7 @@ const head: CellParser.HeadParser = creation(block(fmap(open(
91
91
  ns => [html('th', attributes(ns.shift()! as string), defrag(ns))]),
92
92
  false));
93
93
 
94
- const data: CellParser.DataParser = creation(block(fmap(open(
94
+ const data: CellParser.DataParser = creation(1, false, block(fmap(open(
95
95
  str(/^:(?:(?!:\D|0)\d*:(?!0)\d*)?!*(?=\s)/),
96
96
  rewrite(
97
97
  inits([
@@ -103,7 +103,7 @@ const data: CellParser.DataParser = creation(block(fmap(open(
103
103
  ns => [html('td', attributes(ns.shift()! as string), defrag(ns))]),
104
104
  false));
105
105
 
106
- const dataline: CellParser.DatalineParser = creation(line(
106
+ const dataline: CellParser.DatalineParser = creation(1, false, line(
107
107
  rewrite(
108
108
  contentline,
109
109
  union([
@@ -13,7 +13,7 @@ export const ilist: IListParser = lazy(() => block(validate(
13
13
 
14
14
  export const ilist_: IListParser = lazy(() => block(fmap(validate(
15
15
  /^[-+*](?:$|\s)/,
16
- some(creation(union([
16
+ some(creation(1, false, union([
17
17
  fmap(fallback(
18
18
  inits([
19
19
  line(open(/^[-+*](?:$|\s)/, some(inline), true)),
@@ -36,7 +36,7 @@ export const olist_: OListParser = lazy(() => block(union([
36
36
  ])));
37
37
 
38
38
  const list = (type: string, form: string): OListParser.ListParser => fmap(
39
- some(creation(union([
39
+ some(creation(1, false, union([
40
40
  indexee(fmap(fallback(
41
41
  inits([
42
42
  line(open(heads[form], subsequence([checkbox, trimBlank(some(union([indexer, inline])))]), true)),
@@ -4,7 +4,7 @@ import { anchor } from '../../inline/autolink/anchor';
4
4
  import { str } from '../../source';
5
5
  import { html, define, defrag } from 'typed-dom/dom';
6
6
 
7
- export const cite: ReplyParser.CiteParser = creation(line(fmap(validate(
7
+ export const cite: ReplyParser.CiteParser = creation(1, false, line(fmap(validate(
8
8
  '>>',
9
9
  reverse(tails([
10
10
  str(/^>*(?=>>[^>\s]+[^\S\n]*(?:$|\n))/),
@@ -8,7 +8,7 @@ import { html, defrag } from 'typed-dom/dom';
8
8
 
9
9
  export const syntax = /^>+(?=[^\S\n])|^>(?=[^\s>])|^>+(?=[^\s>])(?![0-9a-z]+(?:-[0-9a-z]+)*(?![0-9A-Za-z@#:]))/;
10
10
 
11
- export const quote: ReplyParser.QuoteParser = lazy(() => creation(block(fmap(validate(
11
+ export const quote: ReplyParser.QuoteParser = lazy(() => creation(1, false, block(fmap(validate(
12
12
  '>',
13
13
  union([
14
14
  rewrite(
@@ -20,7 +20,7 @@ const opener = /^(?=\|\|+(?:$|\s))/;
20
20
  const unindent = (source: string) => source.replace(/(^|\n)\|(?:[^\S\n]|(?=\|*(?:$|\s)))|\n$/g, '$1');
21
21
 
22
22
  const source: SidefenceParser.SourceParser = lazy(() => fmap(
23
- some(creation(union([
23
+ some(creation(1, false, union([
24
24
  focus(
25
25
  /^(?:\|\|+(?:[^\S\n][^\n]*)?(?:$|\n))+/,
26
26
  convert(unindent, source)),
@@ -25,7 +25,7 @@ export const table: TableParser = lazy(() => block(fmap(validate(
25
25
  ]),
26
26
  ])));
27
27
 
28
- const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean): RowParser<P> => creation(fallback(fmap(
28
+ const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean): RowParser<P> => creation(1, false, fallback(fmap(
29
29
  line(surround(/^(?=\|)/, some(union([parser])), /^[|\\]?\s*$/, optional)),
30
30
  es => [html('tr', es)]),
31
31
  rewrite(contentline, ({ source }) => [[
@@ -37,7 +37,7 @@ const row = <P extends CellParser | AlignParser>(parser: P, optional: boolean):
37
37
  }, [html('td', source.replace('\n', ''))])
38
38
  ], ''])));
39
39
 
40
- const align: AlignParser = creation(fmap(open(
40
+ const align: AlignParser = creation(1, false, fmap(open(
41
41
  '|',
42
42
  union([
43
43
  focus(/^:-+:/, () => [['center'], '']),
@@ -52,11 +52,11 @@ const cell: CellParser = surround(
52
52
  some(union([inline]), /^\|/, [[/^[|\\]?\s*$/, 9]]),
53
53
  /^[^|]*/, true);
54
54
 
55
- const head: CellParser.HeadParser = creation(fmap(
55
+ const head: CellParser.HeadParser = creation(1, false, fmap(
56
56
  cell,
57
57
  ns => [html('th', trimNode(defrag(ns)))]));
58
58
 
59
- const data: CellParser.DataParser = creation(fmap(
59
+ const data: CellParser.DataParser = creation(1, false, fmap(
60
60
  cell,
61
61
  ns => [html('td', trimNode(defrag(ns)))]));
62
62
 
@@ -15,7 +15,7 @@ export const ulist: UListParser = lazy(() => block(validate(
15
15
 
16
16
  export const ulist_: UListParser = lazy(() => block(fmap(validate(
17
17
  /^-(?=$|\s)/,
18
- some(creation(union([
18
+ some(creation(1, false, union([
19
19
  indexee(fmap(fallback(
20
20
  inits([
21
21
  line(open(/^-(?:$|\s)/, subsequence([checkbox, trimBlank(some(union([indexer, inline])))]), true)),
@@ -26,7 +26,7 @@ export const ulist_: UListParser = lazy(() => block(fmap(validate(
26
26
  ])))),
27
27
  es => [format(html('ul', es))])));
28
28
 
29
- export const checkbox = creation(focus(
29
+ export const checkbox = creation(1, false, focus(
30
30
  /^\[[xX ]\](?=$|\s)/,
31
31
  ({ source }) => [[
32
32
  html('span', { class: 'checkbox' }, source[1].trimStart() ? '☑' : '☐'),
@@ -35,7 +35,7 @@ export import BlockquoteParser = BlockParser.BlockquoteParser;
35
35
  export import ReplyParser = BlockParser.ReplyParser;
36
36
  export import ParagraphParser = BlockParser.ParagraphParser;
37
37
 
38
- export const block: BlockParser = creation(error(
38
+ export const block: BlockParser = creation(1, false, error(
39
39
  reset({ resources: { clock: 50 * 1000, recursion: 20 } },
40
40
  union([
41
41
  emptyline,
@@ -13,11 +13,9 @@ export const account: AutolinkParser.AccountParser = lazy(() => fmap(rewrite(
13
13
  '@',
14
14
  tails([
15
15
  verify(
16
- str(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//),
16
+ str(/^[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?)*\//i),
17
17
  ([source]) => source.length <= 253 + 1),
18
- verify(
19
- str(/^[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*/),
20
- ([source]) => source.length <= 64),
18
+ str(/^[a-z](?:-(?=[0-9a-z])|[0-9a-z]){0,63}/i),
21
19
  ]))),
22
20
  convert(
23
21
  source =>
@@ -16,7 +16,7 @@ import { define } from 'typed-dom/dom';
16
16
  export const anchor: AutolinkParser.AnchorParser = lazy(() => validate('>>', fmap(
17
17
  constraint(State.shortcut, false,
18
18
  focus(
19
- /^>>(?:[A-Za-z][0-9A-Za-z]*(?:-[0-9A-Za-z]+)*\/)?[0-9A-Za-z]+(?:-[0-9A-Za-z]+)*(?![0-9A-Za-z@#:])/,
19
+ /^>>(?:[a-z][0-9a-z]*(?:-[0-9a-z]+)*\/)?[0-9a-z]+(?:-[0-9a-z]+)*(?![0-9a-z@#:])/i,
20
20
  convert(
21
21
  source =>
22
22
  `[${source}]{ ${
@@ -21,6 +21,7 @@ describe('Unit: parser/inline/autolink/email', () => {
21
21
  assert.deepStrictEqual(inspect(parser('a@@')), [['a@@'], '']);
22
22
  assert.deepStrictEqual(inspect(parser('a@@b')), [['a@@b'], '']);
23
23
  assert.deepStrictEqual(inspect(parser('a+@b')), [['a'], '+@b']);
24
+ assert.deepStrictEqual(inspect(parser('a__b@c')), [['a'], '__b@c']);
24
25
  assert.deepStrictEqual(inspect(parser('a..b@c')), [['a'], '..b@c']);
25
26
  assert.deepStrictEqual(inspect(parser('a++b@c')), [['a'], '++b@c']);
26
27
  assert.deepStrictEqual(inspect(parser(`a@${'b'.repeat(64)}`)), [[`a@${'b'.repeat(64)}`], '']);
@@ -6,6 +6,6 @@ import { html } from 'typed-dom/dom';
6
6
  // https://html.spec.whatwg.org/multipage/input.html
7
7
 
8
8
  export const email: AutolinkParser.EmailParser = creation(rewrite(verify(
9
- str(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*@[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*(?![0-9A-Za-z])/),
10
- ([source]) => source.indexOf('@') <= 64 && source.length <= 255),
9
+ str(/^[0-9a-z](?:[.+_-](?=[^\W_])|[0-9a-z]){0,255}@[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?)*(?![0-9a-z])/i),
10
+ ([source]) => source.length <= 255),
11
11
  ({ source }) => [[html('a', { class: 'email', href: `mailto:${source}` }, source)], '']));
@@ -16,7 +16,7 @@ export const hashtag: AutolinkParser.HashtagParser = lazy(() => fmap(rewrite(
16
16
  '#',
17
17
  tails([
18
18
  verify(
19
- str(/^[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-(?=\w)){0,61}[0-9A-Za-z])?)*\//),
19
+ str(/^[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?(?:\.[0-9a-z](?:(?:[0-9a-z]|-(?=\w)){0,61}[0-9a-z])?)*\//i),
20
20
  ([source]) => source.length <= 253 + 1),
21
21
  verify(
22
22
  str(new RegExp([
@@ -12,18 +12,18 @@ import { Syntax, State } from '../context';
12
12
  import { stringify } from '../util';
13
13
 
14
14
  export const autolink: AutolinkParser = fmap(
15
- validate(/^(?:[@#>0-9A-Za-z]|\S[#>])/,
15
+ validate(/^(?:[@#>0-9a-z]|\S[#>])/i,
16
16
  constraint(State.autolink, false,
17
17
  syntax(Syntax.autolink, 1, 1, State.none,
18
18
  some(union([
19
19
  url,
20
20
  email,
21
21
  // Escape unmatched email-like strings.
22
- str(/^[0-9A-Za-z]+(?:[.+_-][0-9A-Za-z]+)*(?:@(?:[0-9A-Za-z]+(?:[.-][0-9A-Za-z]+)*)?)*/),
22
+ str(/^[0-9a-z]+(?:[.+_-][0-9a-z]+)*(?:@(?:[0-9a-z]+(?:[.-][0-9a-z]+)*)?)*/i),
23
23
  channel,
24
24
  account,
25
25
  // Escape unmatched account-like strings.
26
- str(/^@+[0-9A-Za-z]*(?:-[0-9A-Za-z]+)*/),
26
+ str(/^@+[0-9a-z]*(?:-[0-9a-z]+)*/i),
27
27
  // Escape invalid leading characters.
28
28
  str(new RegExp(/^(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])(?=#)/u.source.replace('emoji', emoji), 'u')),
29
29
  hashtag,
@@ -13,7 +13,7 @@ import { unshift } from 'spica/array';
13
13
 
14
14
  export const placeholder: ExtensionParser.PlaceholderParser = lazy(() => validate(['[:', '[^'], surround(
15
15
  str(/^\[[:^]/),
16
- syntax(Syntax.none, 2, 1, State.none,
16
+ syntax(Syntax.placeholder, 2, 1, State.none,
17
17
  startTight(some(union([inline]), ']', [[/^\\?\n/, 9], [']', 2]]))),
18
18
  str(']'), false,
19
19
  ([as, bs], rest) => [[
@@ -25,11 +25,18 @@ describe('Unit: parser/inline/link', () => {
25
25
  assert.deepStrictEqual(inspect(parser('[https://host]{http://host}')), undefined);
26
26
  assert.deepStrictEqual(inspect(parser('[[]{http://host}.com]{http://host}')), undefined);
27
27
  assert.deepStrictEqual(inspect(parser('[[]{http://host/a}b]{http://host/ab}')), undefined);
28
- assert.deepStrictEqual(inspect(parser('[0987654321]{tel:1234567890}')), [['<a class="invalid">0987654321</a>'], '']);
29
- assert.deepStrictEqual(inspect(parser('[1234567890-]{tel:1234567890}')), [[`<a class="invalid">1234567890-</a>`], '']);
30
- assert.deepStrictEqual(inspect(parser('[-1234567890]{tel:1234567890}')), [[`<a class="invalid">-1234567890</a>`], '']);
31
- assert.deepStrictEqual(inspect(parser('[123456789a]{tel:1234567890}')), [['<a class="invalid">123456789a</a>'], '']);
32
- assert.deepStrictEqual(inspect(parser('[1234567890]{tel:ttel:1234567890}')), [['<a class="invalid">1234567890</a>'], '']);
28
+ assert.deepStrictEqual(inspect(parser('{http%73://host}')), [['<a class="url" href="http%73://host">http%73://host</a>'], '']);
29
+ assert.deepStrictEqual(inspect(parser('{http://a%C3%A1}')), [['<a class="url" href="http://a%C3%A1" target="_blank">http://a%C3%A1</a>'], '']);
30
+ assert.deepStrictEqual(inspect(parser('[http://á]{http://evil}')), undefined);
31
+ assert.deepStrictEqual(inspect(parser('[xxx://á]{http://evil}')), undefined);
32
+ assert.deepStrictEqual(inspect(parser('[mailto:á]{http://evil}')), undefined);
33
+ assert.deepStrictEqual(inspect(parser('[file:///]{http://evil}')), undefined);
34
+ assert.deepStrictEqual(inspect(parser('[.http://á]{http://evil}')), undefined);
35
+ assert.deepStrictEqual(inspect(parser('[0987654321]{tel:1234567890}')), undefined);
36
+ assert.deepStrictEqual(inspect(parser('[1234567890-]{tel:1234567890}')), undefined);
37
+ assert.deepStrictEqual(inspect(parser('[-1234567890]{tel:1234567890}')), undefined);
38
+ assert.deepStrictEqual(inspect(parser('[123456789a]{tel:1234567890}')), undefined);
39
+ assert.deepStrictEqual(inspect(parser('[1234567890]{tel:ttel:1234567890}')), undefined);
33
40
  //assert.deepStrictEqual(inspect(parser('[#a]{b}')), undefined);
34
41
  //assert.deepStrictEqual(inspect(parser('[\\#a]{b}')), undefined);
35
42
  //assert.deepStrictEqual(inspect(parser('[c #a]{b}')), undefined);
@@ -36,12 +36,6 @@ const textlink: LinkParser.TextLinkParser = lazy(() =>
36
36
  ])),
37
37
  ([params, content = []]: [string[], (HTMLElement | string)[]], rest, context) => {
38
38
  assert(!html('div', content).querySelector('a, .media, .annotation, .reference'));
39
- if (content.length !== 0 && trimNode(content).length === 0) return;
40
- for (let source = stringify(content); source;) {
41
- const result = autolink({ source, context });
42
- if (typeof eval(result, [])[0] === 'object') return;
43
- source = exec(result, '');
44
- }
45
39
  return parse(content, params, rest, context);
46
40
  }))));
47
41
 
@@ -91,15 +85,40 @@ function parse(
91
85
  ): Result<HTMLAnchorElement, MarkdownParser.Context> {
92
86
  assert(params.length > 0);
93
87
  assert(params.every(p => typeof p === 'string'));
88
+ if (content.length !== 0 && trimNode(content).length === 0) return;
89
+ content = defrag(content);
90
+ for (let source = stringify(content); source;) {
91
+ if (/^[a-z][0-9a-z]*(?:[-.][0-9a-z]+)*:(?:\/{0,2}[^/?#\s]+|\/\/(?=[/]))/i.test(source)) return;
92
+ const result = autolink({ source, context });
93
+ if (typeof eval(result, [])[0] === 'object') return;
94
+ source = exec(result, '');
95
+ }
94
96
  const INSECURE_URI = params.shift()!;
95
97
  assert(INSECURE_URI === INSECURE_URI.trim());
96
98
  assert(!INSECURE_URI.match(/\s/));
99
+ const uri = new ReadonlyURL(
100
+ resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
101
+ context.host?.href || location.href);
102
+ switch (uri.protocol) {
103
+ case 'tel:': {
104
+ const tel = content.length === 0
105
+ ? INSECURE_URI
106
+ : content[0];
107
+ const pattern = /^(?:tel:)?(?:\+(?!0))?\d+(?:-\d+)*$/i;
108
+ if (content.length <= 1 &&
109
+ typeof tel === 'string' &&
110
+ pattern.test(tel) &&
111
+ pattern.test(INSECURE_URI) &&
112
+ tel.replace(/[^+\d]/g, '') === INSECURE_URI.replace(/[^+\d]/g, '')) {
113
+ break;
114
+ }
115
+ return;
116
+ }
117
+ }
97
118
  const el = elem(
98
119
  INSECURE_URI,
99
- defrag(content),
100
- new ReadonlyURL(
101
- resolve(INSECURE_URI, context.host ?? location, context.url ?? context.host ?? location),
102
- context.host?.href || location.href),
120
+ content,
121
+ uri,
103
122
  context.host?.origin || location.origin);
104
123
  if (el.className === 'invalid') return [[el], rest];
105
124
  return [[define(el, attributes('link', [], optspec, params))], rest];
@@ -137,21 +156,15 @@ function elem(
137
156
  ? decode(INSECURE_URI)
138
157
  : content);
139
158
  case 'tel:':
140
- if (content.length === 0) {
141
- content = [INSECURE_URI];
142
- }
143
- const pattern = /^(?:tel:)?(?:\+(?!0))?\d+(?:-\d+)*$/i;
144
- switch (true) {
145
- case content.length === 1
146
- && typeof content[0] === 'string'
147
- && pattern.test(INSECURE_URI)
148
- && pattern.test(content[0])
149
- && INSECURE_URI.replace(/[^+\d]/g, '') === content[0].replace(/[^+\d]/g, ''):
150
- return html('a', { class: 'tel', href: uri.source }, content);
151
- }
152
- type = 'content';
153
- message = 'Invalid phone number';
154
- break;
159
+ assert(content.length <= 1);
160
+ return html('a',
161
+ {
162
+ class: 'tel',
163
+ href: uri.source,
164
+ },
165
+ content.length === 0
166
+ ? [INSECURE_URI]
167
+ : content);
155
168
  }
156
169
  return html('a',
157
170
  {
@@ -172,7 +185,7 @@ export function resolve(uri: string, host: URL | Location, source: URL | Locatio
172
185
  case uri.slice(0, 2) === '^/':
173
186
  const last = host.pathname.slice(host.pathname.lastIndexOf('/') + 1);
174
187
  return last.includes('.') // isFile
175
- && /^[0-9]*[A-Za-z][0-9A-Za-z]*$/.test(last.slice(last.lastIndexOf('.') + 1))
188
+ && /^[0-9]*[a-z][0-9a-z]*$/i.test(last.slice(last.lastIndexOf('.') + 1))
176
189
  ? `${host.pathname.slice(0, -last.length)}${uri.slice(2)}`
177
190
  : `${host.pathname.replace(/\/?$/, '/')}${uri.slice(2)}`;
178
191
  case host.origin === source.origin
@@ -189,8 +202,13 @@ export function resolve(uri: string, host: URL | Location, source: URL | Locatio
189
202
 
190
203
  function decode(uri: string): string {
191
204
  if (!uri.includes('%')) return uri;
205
+ const origin = uri.match(/^[a-z](?:[-.](?=\w)|[0-9a-z])*:(?:\/{0,2}[^/?#\s]+|\/\/(?=[/]))/i)?.[0] ?? '';
192
206
  try {
193
- uri = decodeURI(uri);
207
+ let path = decodeURI(uri.slice(origin.length));
208
+ if (!origin && /^[a-z](?:[-.](?=\w)|[0-9a-z])*:(?:\/{0,2}[^/?#\s]+|\/\/(?=[/]))/i.test(path)) {
209
+ path = uri.slice(origin.length);
210
+ }
211
+ uri = origin + path;
194
212
  }
195
213
  finally {
196
214
  return uri.replace(/\s+/g, encodeURI);
@@ -48,7 +48,7 @@ export const ruby: RubyParser = lazy(() => validate('[', syntax(Syntax.none, 2,
48
48
  }
49
49
  }))));
50
50
 
51
- const text: RubyParser.TextParser = creation(({ source, context }) => {
51
+ const text: RubyParser.TextParser = creation(1, false, ({ source, context }) => {
52
52
  const acc = [''];
53
53
  while (source !== '') {
54
54
  assert(source[0] !== '\n');
@@ -4,7 +4,7 @@ import { nonWhitespace } from './text';
4
4
 
5
5
  const delimiter = /[\s\x00-\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]/;
6
6
 
7
- export const escsource: EscapableSourceParser = creation(({ source }) => {
7
+ export const escsource: EscapableSourceParser = creation(1, false, ({ source }) => {
8
8
  if (source === '') return;
9
9
  const i = source.search(delimiter);
10
10
  switch (i) {
@@ -7,13 +7,13 @@ export function str(pattern: string | RegExp): StrParser;
7
7
  export function str(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
8
8
  assert(pattern);
9
9
  return typeof pattern === 'string'
10
- ? creation(({ source }) => {
10
+ ? creation(1, false, ({ source }) => {
11
11
  if (source === '') return;
12
12
  return source.slice(0, pattern.length) === pattern
13
13
  ? [[pattern], source.slice(pattern.length)]
14
14
  : undefined;
15
15
  })
16
- : creation(({ source }) => {
16
+ : creation(1, false, ({ source }) => {
17
17
  if (source === '') return;
18
18
  const m = source.match(pattern);
19
19
  return m && m[0].length > 0
@@ -26,13 +26,13 @@ export function stropt(pattern: string | RegExp): StrParser;
26
26
  export function stropt(pattern: string | RegExp): Parser<string, Context<StrParser>, []> {
27
27
  assert(pattern);
28
28
  return typeof pattern === 'string'
29
- ? creation(({ source }) => {
29
+ ? creation(1, false, ({ source }) => {
30
30
  if (source === '') return;
31
31
  return source.slice(0, pattern.length) === pattern
32
32
  ? [[pattern], source.slice(pattern.length)]
33
33
  : undefined;
34
34
  })
35
- : creation(({ source }) => {
35
+ : creation(1, false, ({ source }) => {
36
36
  if (source === '') return;
37
37
  const m = source.match(pattern);
38
38
  return m
@@ -1,8 +1,7 @@
1
1
  import { undefined } from 'spica/global';
2
2
  import { TextParser, TxtParser, LinebreakParser } from '../source';
3
- import { union, syntax, focus } from '../../combinator';
3
+ import { union, creation, focus } from '../../combinator';
4
4
  import { str } from './str';
5
- import { Syntax, State } from '../context';
6
5
  import { html } from 'typed-dom/dom';
7
6
 
8
7
  export const delimiter = /[\s\x00-\x7F]|\S[#>]|[()、。!?][^\S\n]*(?=\\\n)/;
@@ -10,7 +9,7 @@ export const nonWhitespace = /[\S\n]|$/;
10
9
  export const nonAlphanumeric = /[^0-9A-Za-z]|\S[#>]|$/;
11
10
  const repeat = str(/^(.)\1*/);
12
11
 
13
- export const text: TextParser = syntax(Syntax.none, 1, 1, State.none, ({ source, context }) => {
12
+ export const text: TextParser = creation(1, false, ({ source, context }) => {
14
13
  if (source === '') return;
15
14
  const i = source.search(delimiter);
16
15
  switch (i) {
@@ -2,7 +2,7 @@ import { UnescapableSourceParser } from '../source';
2
2
  import { creation } from '../../combinator';
3
3
  import { delimiter, nonWhitespace, nonAlphanumeric, isAlphanumeric } from './text';
4
4
 
5
- export const unescsource: UnescapableSourceParser = creation(({ source }) => {
5
+ export const unescsource: UnescapableSourceParser = creation(1, false, ({ source }) => {
6
6
  assert(source[0] !== '\x1B');
7
7
  if (source === '') return;
8
8
  const i = source.search(delimiter);