securemark 0.295.5 → 0.295.6

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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.295.6
4
+
5
+ - Refactoring.
6
+
3
7
  ## 0.295.5
4
8
 
5
9
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.295.5 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.295.6 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("Prism"), require("DOMPurify"));
@@ -3439,14 +3439,15 @@ class Delimiters {
3439
3439
  return `r/${pattern.source}`;
3440
3440
  }
3441
3441
  }
3442
- static matcher(pattern) {
3442
+ static matcher(pattern, after) {
3443
3443
  switch (typeof pattern) {
3444
3444
  case 'undefined':
3445
3445
  return () => undefined;
3446
3446
  case 'string':
3447
3447
  case 'object':
3448
3448
  const match = (0, combinator_1.matcher)(pattern, false);
3449
- return input => match(input) !== undefined || undefined;
3449
+ const verify = after ? (0, combinator_1.matcher)(after, false) : undefined;
3450
+ return verify ? input => match(input) !== undefined && verify(input) !== undefined || undefined : input => match(input) !== undefined || undefined;
3450
3451
  }
3451
3452
  }
3452
3453
  registry(signature) {
@@ -3931,10 +3932,19 @@ Object.defineProperty(exports, "__esModule", ({
3931
3932
  }));
3932
3933
  exports.some = void 0;
3933
3934
  const delimiter_1 = __webpack_require__(385);
3934
- function some(parser, end, delimiters = [], limit = -1) {
3935
- if (typeof end === 'number') return some(parser, undefined, delimiters, end);
3936
- const match = delimiter_1.Delimiters.matcher(end);
3937
- const delims = delimiters.map(([delimiter, precedence]) => ({
3935
+ function some(parser, delimiter, after, delimiters, limit = -1) {
3936
+ if (typeof delimiter === 'number') {
3937
+ limit = delimiter;
3938
+ delimiter = undefined;
3939
+ } else if (Array.isArray(delimiter)) {
3940
+ delimiters = delimiter;
3941
+ delimiter = undefined;
3942
+ } else if (after === undefined || Array.isArray(after)) {
3943
+ delimiters = after;
3944
+ after = undefined;
3945
+ }
3946
+ const match = delimiter_1.Delimiters.matcher(delimiter, after);
3947
+ const delims = delimiters?.map(([delimiter, precedence]) => ({
3938
3948
  signature: delimiter_1.Delimiters.signature(delimiter),
3939
3949
  matcher: delimiter_1.Delimiters.matcher(delimiter),
3940
3950
  precedence
@@ -3949,9 +3959,7 @@ function some(parser, end, delimiters = [], limit = -1) {
3949
3959
  } = context;
3950
3960
  //assert(context.backtracks ??= {});
3951
3961
  let nodes;
3952
- if (delims.length > 0) {
3953
- context.delimiters.push(delims);
3954
- }
3962
+ delims && context.delimiters.push(delims);
3955
3963
  // whileは数倍遅い
3956
3964
  for (const len = source.length; context.position < len;) {
3957
3965
  if (match(input)) break;
@@ -3961,9 +3969,7 @@ function some(parser, end, delimiters = [], limit = -1) {
3961
3969
  nodes = nodes?.import(result) ?? result;
3962
3970
  if (limit >= 0 && context.position - position > limit) break;
3963
3971
  }
3964
- if (delims.length > 0) {
3965
- context.delimiters.pop(delims.length);
3966
- }
3972
+ delims && context.delimiters.pop(delims.length);
3967
3973
  return context.position > position ? nodes : undefined;
3968
3974
  };
3969
3975
  }
@@ -4676,8 +4682,8 @@ exports.blockquote = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, co
4676
4682
  const opener = /(?=>>+(?:$|[ \n]))/y;
4677
4683
  const indent = (0, combinator_1.block)((0, combinator_1.open)(opener, (0, combinator_1.some)(source_1.contentline, />(?:$|[ \n])/y)), false);
4678
4684
  const unindent = source => source.replace(/(?<=^|\n)>(?: |(?=>*(?:$|[ \n])))|\n$/g, '');
4679
- const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.recursion)(2 /* Recursion.blockquote */, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, source, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('pre', (0, dom_1.defrag)((0, util_1.unwrap)(ns))))])), true))]))), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('blockquote', (0, util_1.unwrap)(ns)))])));
4680
- const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.recursion)(2 /* Recursion.blockquote */, (0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, markdown, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, ({
4685
+ const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.recursion)(2 /* Recursion.blockquote */, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, source, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('pre', (0, dom_1.defrag)((0, util_1.unwrap)(ns))))])), true))]))), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('blockquote', (0, util_1.unwrap)(ns)))])));
4686
+ const markdown = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.recursion)(2 /* Recursion.blockquote */, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.rewrite)(indent, (0, combinator_1.convert)(unindent, markdown, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, ({
4681
4687
  context
4682
4688
  }) => {
4683
4689
  (0, combinator_1.consume)(10, context);
@@ -5497,7 +5503,7 @@ const visibility_1 = __webpack_require__(6364);
5497
5503
  const util_1 = __webpack_require__(4992);
5498
5504
  const dom_1 = __webpack_require__(394);
5499
5505
  exports.ilist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(/[-+*] /y, exports.ilist_)));
5500
- exports.ilist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/[-+*](?:$|[ \n])/y, (0, combinator_1.some)((0, combinator_1.recursion)(3 /* Recursion.listitem */, (0, combinator_1.union)([(0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/[-+*](?:$|[ \n])/y, (0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)(inline_1.inline))), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, olist_1.olist_, exports.ilist_]))]), exports.ilistitem), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('li', (0, dom_1.defrag)((0, util_1.unwrap)((0, ulist_1.fillFirstLine)(ns)))))]))])))), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('ul', {
5506
+ exports.ilist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/[-+*](?:$|[ \n])/y, (0, combinator_1.recursion)(3 /* Recursion.listitem */, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.fmap)((0, combinator_1.fallback)((0, combinator_1.inits)([(0, combinator_1.line)((0, combinator_1.open)(/[-+*](?:$|[ \n])/y, (0, visibility_1.visualize)((0, visibility_1.trimBlank)((0, combinator_1.some)(inline_1.inline))), true)), (0, combinator_1.indent)((0, combinator_1.union)([ulist_1.ulist_, olist_1.olist_, exports.ilist_]))]), exports.ilistitem), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('li', (0, dom_1.defrag)((0, util_1.unwrap)((0, ulist_1.fillFirstLine)(ns)))))]))])))), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('ul', {
5501
5507
  class: 'invalid',
5502
5508
  ...(0, util_1.invalid)('list', 'syntax', 'Use "-" instead of "+" or "*"')
5503
5509
  }, (0, util_1.unwrap)(ns)))]))));
@@ -5604,7 +5610,7 @@ const openers = {
5604
5610
  };
5605
5611
  exports.olist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)(new RegExp([/(?:[0-9]+)(?:-[0-9]+)*\. /y.source, /\((?:[0-9]+)\)(?:-[0-9]+)* /y.source].join('|'), 'y'), exports.olist_)));
5606
5612
  exports.olist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.union)([(0, combinator_1.match)(openers['.'], (0, memoize_1.memoize)(ms => list(type(ms[1]), '.'), ms => idx(ms[1]), [])), (0, combinator_1.match)(openers['('], (0, memoize_1.memoize)(ms => list(type(ms[1]), '('), ms => idx(ms[1]), []))])));
5607
- const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.recursion)(3 /* Recursion.listitem */, (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.visualize)((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_]))]), ilist_1.ilistitem), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('li', {
5613
+ const list = (type, form) => (0, combinator_1.fmap)((0, combinator_1.recursion)(3 /* Recursion.listitem */, (0, combinator_1.some)((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.visualize)((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_]))]), ilist_1.ilistitem), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('li', {
5608
5614
  'data-index': (0, inline_1.dataindex)(ns),
5609
5615
  'data-marker': ns.shift()?.value || undefined
5610
5616
  }, (0, dom_1.defrag)((0, util_1.unwrap)((0, ulist_1.fillFirstLine)(ns)))))])))]))), ns => new parser_1.List([new parser_1.Node(format((0, dom_1.html)('ol', (0, util_1.unwrap)(ns)), type, form))]));
@@ -5880,7 +5886,7 @@ exports.sidefence = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, com
5880
5886
  }))]))));
5881
5887
  const opener = /(?=\|\|+(?:$|[ \n]))/y;
5882
5888
  const unindent = source => source.replace(/(?<=^|\n)\|(?: |(?=\|*(?:$|[ \n])))|\n$/g, '');
5883
- const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.some)((0, combinator_1.recursion)(1 /* Recursion.block */, (0, combinator_1.union)([(0, combinator_1.focus)(/(?:\|\|+(?=$|[ \n])[^\n]*(?:$|\n))+/y, (0, combinator_1.convert)(unindent, source, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('pre', (0, dom_1.defrag)((0, util_1.unwrap)(ns))))])), true))]))), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('blockquote', (0, util_1.unwrap)(ns)))])));
5889
+ const source = (0, combinator_1.lazy)(() => (0, combinator_1.fmap)((0, combinator_1.recursion)(1 /* Recursion.block */, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.focus)(/(?:\|\|+(?=$|[ \n])[^\n]*(?:$|\n))+/y, (0, combinator_1.convert)(unindent, source, true)), (0, combinator_1.rewrite)((0, combinator_1.some)(source_1.contentline, opener), (0, combinator_1.convert)(unindent, (0, combinator_1.fmap)(autolink_1.autolink, ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('pre', (0, dom_1.defrag)((0, util_1.unwrap)(ns))))])), true))]))), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('blockquote', (0, util_1.unwrap)(ns)))])));
5884
5890
 
5885
5891
  /***/ },
5886
5892
 
@@ -5965,7 +5971,7 @@ const visibility_1 = __webpack_require__(6364);
5965
5971
  const util_1 = __webpack_require__(4992);
5966
5972
  const dom_1 = __webpack_require__(394);
5967
5973
  exports.ulist = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.validate)('- ', exports.ulist_)));
5968
- exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/-(?=$|[ \n])/y, (0, combinator_1.some)((0, combinator_1.recursion)(3 /* Recursion.listitem */, (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)(/-(?:$|[ \n])/y, (0, combinator_1.subsequence)([exports.checkbox, (0, visibility_1.visualize)((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_]))]), ilist_1.ilistitem), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('li', {
5974
+ exports.ulist_ = (0, combinator_1.lazy)(() => (0, combinator_1.block)((0, combinator_1.fmap)((0, combinator_1.validate)(/-(?=$|[ \n])/y, (0, combinator_1.recursion)(3 /* Recursion.listitem */, (0, combinator_1.some)((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)(/-(?:$|[ \n])/y, (0, combinator_1.subsequence)([exports.checkbox, (0, visibility_1.visualize)((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_]))]), ilist_1.ilistitem), ns => new parser_1.List([new parser_1.Node((0, dom_1.html)('li', {
5969
5975
  'data-index': (0, inline_1.dataindex)(ns)
5970
5976
  }, (0, dom_1.defrag)((0, util_1.unwrap)(fillFirstLine(ns)))))])))])))), ns => new parser_1.List([new parser_1.Node(format((0, dom_1.html)('ul', (0, util_1.unwrap)(ns))))]))));
5971
5977
  exports.checkbox = (0, combinator_1.focus)(/\[[xX ]\](?=$|[ \n])/y, ({
@@ -6505,7 +6511,7 @@ const combinator_1 = __webpack_require__(3484);
6505
6511
  const inline_1 = __webpack_require__(7973);
6506
6512
  const link_1 = __webpack_require__(3628);
6507
6513
  const source_1 = __webpack_require__(8745);
6508
- exports.url = (0, combinator_1.lazy)(() => (0, combinator_1.rewrite)((0, combinator_1.open)(/(?<![0-9A-Za-z][.+-]?|[@#])https?:\/\/(?=[\x21-\x7E])/y, (0, combinator_1.precedence)(0, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(source_1.unescsource, /(?<![-+*=~^_,.;:!?]|\/{3})(?:[-+*=~^_,.;:!?]|\/{3,}(?!\/))*(?=[\\$"`\[\](){}<>()[]{}|]|[^\x21-\x7E]|$)/y), (0, combinator_1.precedence)(1, (0, combinator_1.verify)(bracket, ns => ns.length > 0))]), undefined, [[/[^\x21-\x7E]|\$/y, 9]])), false, [3 | 8 /* Backtrack.unescapable */]), (0, combinator_1.union)([(0, combinator_1.constraint)(1 /* State.autolink */, (0, combinator_1.state)(1 /* State.autolink */, ({
6514
+ exports.url = (0, combinator_1.lazy)(() => (0, combinator_1.rewrite)((0, combinator_1.open)(/(?<![0-9A-Za-z][.+-]?|[@#])https?:\/\/(?=[\x21-\x7E])/y, (0, combinator_1.precedence)(0, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(source_1.unescsource, /(?<![-+*=~^_,.;:!?]|\/{3})(?:[-+*=~^_,.;:!?]|\/{3,}(?!\/))*(?=[\\$"`\[\](){}<>()[]{}|]|[^\x21-\x7E]|$)/y), (0, combinator_1.precedence)(1, (0, combinator_1.verify)(bracket, ns => ns.length > 0))]), [[/[^\x21-\x7E]|\$/y, 9]])), false, [3 | 8 /* Backtrack.unescapable */]), (0, combinator_1.union)([(0, combinator_1.constraint)(1 /* State.autolink */, (0, combinator_1.state)(1 /* State.autolink */, ({
6509
6515
  context
6510
6516
  }) => new parser_1.List([new parser_1.Node((0, link_1.parse)(new parser_1.List(), new parser_1.List([new parser_1.Node(context.source)]), context))]))), (0, combinator_1.open)((0, source_1.str)(/[^:]+/y), (0, combinator_1.some)(inline_1.inline))])));
6511
6517
  exports.lineurl = (0, combinator_1.lazy)(() => (0, combinator_1.focus)(/(?<=^|[\r\n])!?https?:\/\/\S+(?=[^\S\n]*(?=$|\n))/y, (0, combinator_1.tails)([(0, source_1.str)('!'), (0, combinator_1.union)([(0, combinator_1.constraint)(1 /* State.autolink */, (0, combinator_1.state)(1 /* State.autolink */, ({
@@ -6692,11 +6698,11 @@ const inline_1 = __webpack_require__(7973);
6692
6698
  const visibility_1 = __webpack_require__(6364);
6693
6699
  const util_1 = __webpack_require__(4992);
6694
6700
  const dom_1 = __webpack_require__(394);
6695
- exports.deletion = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, util_1.repeat)('~~', (0, combinator_1.surround)('', (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('\n', '~~')), (0, combinator_1.open)('\n', (0, combinator_1.some)(inline_1.inline, '~'), true)]))), '~~', false, [], ([, bs], {
6701
+ exports.deletion = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, util_1.repeat)('~~', (0, combinator_1.surround)('', (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('\n', '~~')), (0, combinator_1.open)('\n', (0, combinator_1.some)(inline_1.inline, '~'), true)])), '~~', false, [], ([, bs], {
6696
6702
  buffer
6697
6703
  }) => buffer.import(bs), ([, bs], {
6698
6704
  buffer
6699
- }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('del', (0, dom_1.defrag)((0, util_1.unwrap)(nodes))))]))));
6705
+ }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('del', (0, dom_1.defrag)((0, util_1.unwrap)(nodes))))])))));
6700
6706
 
6701
6707
  /***/ },
6702
6708
 
@@ -6718,7 +6724,7 @@ const source_1 = __webpack_require__(8745);
6718
6724
  const visibility_1 = __webpack_require__(6364);
6719
6725
  const util_1 = __webpack_require__(4992);
6720
6726
  const dom_1 = __webpack_require__(394);
6721
- exports.emphasis = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)(/\*(?!\*)/y), (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([strong_1.strong, (0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('*')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '*'), inline_1.inline)]))))), (0, source_1.str)('*'), false, [], ([, bs]) => new parser_1.List([new parser_1.Node((0, dom_1.html)('em', (0, dom_1.defrag)((0, util_1.unwrap)(bs))))]), ([as, bs]) => bs && as.import(bs)));
6727
+ exports.emphasis = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)(/\*(?!\*)/y), (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, '*', visibility_1.afterNonblank), strong_1.strong]))))), (0, source_1.str)('*'), false, [], ([, bs]) => new parser_1.List([new parser_1.Node((0, dom_1.html)('em', (0, dom_1.defrag)((0, util_1.unwrap)(bs))))]), ([as, bs]) => bs && as.import(bs)));
6722
6728
 
6723
6729
  /***/ },
6724
6730
 
@@ -6741,12 +6747,12 @@ const source_1 = __webpack_require__(8745);
6741
6747
  const visibility_1 = __webpack_require__(6364);
6742
6748
  const util_1 = __webpack_require__(4992);
6743
6749
  const dom_1 = __webpack_require__(394);
6744
- const substrong = (0, combinator_1.lazy)(() => (0, combinator_1.some)((0, combinator_1.union)([emphasis_1.emphasis, (0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('*')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '*'), inline_1.inline)])));
6745
- const subemphasis = (0, combinator_1.lazy)(() => (0, combinator_1.some)((0, combinator_1.union)([strong_1.strong, (0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('*')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '*'), inline_1.inline)])));
6750
+ const substrong = (0, combinator_1.lazy)(() => (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, '*', visibility_1.afterNonblank), emphasis_1.emphasis])));
6751
+ const subemphasis = (0, combinator_1.lazy)(() => (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, '*', visibility_1.afterNonblank), strong_1.strong])));
6746
6752
  // 開閉が明示的でない構文は開閉の不明確な記号による再帰的適用を行わず
6747
6753
  // 可能な限り早く閉じるよう解析しなければならない。
6748
6754
  // このため終端記号の後ろを見て終端を中止し同じ構文を再帰的に適用してはならない。
6749
- exports.emstrong = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, util_1.repeat)('***', (0, combinator_1.surround)('', (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('*')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '*'), inline_1.inline)])))), (0, source_1.str)(/\*{1,3}/y), false, [], ([, bs, cs], context) => {
6755
+ exports.emstrong = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, util_1.repeat)('***', (0, combinator_1.surround)('', (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, '*', visibility_1.afterNonblank)]))), (0, source_1.str)(/\*{1,3}/y), false, [], ([, bs, cs], context) => {
6750
6756
  const {
6751
6757
  buffer
6752
6758
  } = context;
@@ -6853,7 +6859,7 @@ nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('em', [(0, dom_1.h
6853
6859
  nodes = prepend('*'.repeat(prefix - postfix), nodes);
6854
6860
  }
6855
6861
  return nodes;
6856
- })));
6862
+ }))));
6857
6863
  function prepend(prefix, nodes) {
6858
6864
  if (typeof nodes.head?.value === 'string') {
6859
6865
  nodes.head.value = prefix + nodes.head.value;
@@ -7309,11 +7315,11 @@ const inline_1 = __webpack_require__(7973);
7309
7315
  const visibility_1 = __webpack_require__(6364);
7310
7316
  const util_1 = __webpack_require__(4992);
7311
7317
  const dom_1 = __webpack_require__(394);
7312
- exports.insertion = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, util_1.repeat)('++', (0, combinator_1.surround)('', (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('\n', '++')), (0, combinator_1.open)('\n', (0, combinator_1.some)(inline_1.inline, '+'), true)]))), '++', false, [], ([, bs], {
7318
+ exports.insertion = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, util_1.repeat)('++', (0, combinator_1.surround)('', (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('\n', '++')), (0, combinator_1.open)('\n', (0, combinator_1.some)(inline_1.inline, '+'), true)])), '++', false, [], ([, bs], {
7313
7319
  buffer
7314
7320
  }) => buffer.import(bs), ([, bs], {
7315
7321
  buffer
7316
- }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('ins', (0, dom_1.defrag)((0, util_1.unwrap)(nodes))))]))));
7322
+ }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('ins', (0, dom_1.defrag)((0, util_1.unwrap)(nodes))))])))));
7317
7323
 
7318
7324
  /***/ },
7319
7325
 
@@ -7336,11 +7342,11 @@ const dom_1 = __webpack_require__(394);
7336
7342
  // 可読性のため実際にはオブリーク体を指定する。
7337
7343
  // 斜体は単語に使うとかえって見づらく読み飛ばしやすくなるため使わないべきであり
7338
7344
  // ある程度の長さのある文に使うのが望ましい。
7339
- exports.italic = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, util_1.repeat)('///', (0, combinator_1.surround)('', (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('///')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '/'), inline_1.inline)])))), '///', false, [], ([, bs], {
7345
+ exports.italic = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, util_1.repeat)('///', (0, combinator_1.surround)('', (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), '///', visibility_1.afterNonblank)), '///', false, [], ([, bs], {
7340
7346
  buffer
7341
7347
  }) => buffer.import(bs), ([, bs], {
7342
7348
  buffer
7343
- }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('i', (0, dom_1.defrag)((0, util_1.unwrap)(nodes))))]))));
7349
+ }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), nodes => new parser_1.List([new parser_1.Node((0, dom_1.html)('i', (0, dom_1.defrag)((0, util_1.unwrap)(nodes))))])))));
7344
7350
 
7345
7351
  /***/ },
7346
7352
 
@@ -7517,21 +7523,23 @@ const indexee_1 = __webpack_require__(7610);
7517
7523
  const visibility_1 = __webpack_require__(6364);
7518
7524
  const util_1 = __webpack_require__(4992);
7519
7525
  const dom_1 = __webpack_require__(394);
7520
- exports.mark = (0, combinator_1.lazy)(() => (0, combinator_1.constraint)(251 /* State.linkers */ & ~2 /* State.mark */, (0, combinator_1.precedence)(0, (0, combinator_1.state)(2 /* State.mark */, (0, util_1.repeat)('==', (0, combinator_1.surround)('', (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('==')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '='), inline_1.inline)])))), '==', false, [], ([, bs], {
7526
+ exports.mark = (0, combinator_1.lazy)(() => (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, util_1.repeat)('==', (0, combinator_1.surround)('', (0, visibility_1.tightStart)((0, combinator_1.state)(2 /* State.mark */, (0, combinator_1.some)((0, combinator_1.union)([inline_1.inline]), '==', visibility_1.afterNonblank))), '==', false, [], ([, bs], {
7521
7527
  buffer
7522
7528
  }) => buffer.import(bs), ([, bs], {
7523
7529
  buffer
7524
7530
  }) => bs && buffer.import(bs).push(new parser_1.Node("\u0018" /* Command.Cancel */)) && buffer), (nodes, {
7525
- id
7531
+ id,
7532
+ state
7526
7533
  }) => {
7527
7534
  const el = (0, dom_1.html)('mark', (0, dom_1.defrag)((0, util_1.unwrap)(nodes)));
7535
+ if (state & 251 /* State.linkers */) return new parser_1.List([new parser_1.Node(el)]);
7528
7536
  (0, dom_1.define)(el, {
7529
7537
  id: (0, indexee_1.identity)('mark', id, (0, indexee_1.signature)(el))
7530
7538
  });
7531
7539
  return el.id ? new parser_1.List([new parser_1.Node(el), new parser_1.Node((0, dom_1.html)('a', {
7532
7540
  href: `#${el.id}`
7533
7541
  }))]) : new parser_1.List([new parser_1.Node(el)]);
7534
- })))));
7542
+ }))));
7535
7543
 
7536
7544
  /***/ },
7537
7545
 
@@ -7948,7 +7956,7 @@ const source_1 = __webpack_require__(8745);
7948
7956
  const visibility_1 = __webpack_require__(6364);
7949
7957
  const util_1 = __webpack_require__(4992);
7950
7958
  const dom_1 = __webpack_require__(394);
7951
- exports.strong = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)(/\*\*(?!\*)/y), (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([emphasis_1.emphasis, (0, combinator_1.some)(inline_1.inline, (0, visibility_1.blankWith)('*')), (0, combinator_1.open)((0, combinator_1.some)(inline_1.inline, '*'), inline_1.inline)]))))), (0, source_1.str)('**'), false, [], ([, bs]) => new parser_1.List([new parser_1.Node((0, dom_1.html)('strong', (0, dom_1.defrag)((0, util_1.unwrap)(bs))))]), ([as, bs]) => bs && as.import(bs)));
7959
+ exports.strong = (0, combinator_1.lazy)(() => (0, combinator_1.surround)((0, source_1.str)(/\*\*(?!\*)/y), (0, combinator_1.precedence)(0, (0, combinator_1.recursion)(4 /* Recursion.inline */, (0, visibility_1.tightStart)((0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(inline_1.inline, '*', visibility_1.afterNonblank), emphasis_1.emphasis]))))), (0, source_1.str)('**'), false, [], ([, bs]) => new parser_1.List([new parser_1.Node((0, dom_1.html)('strong', (0, dom_1.defrag)((0, util_1.unwrap)(bs))))]), ([as, bs]) => bs && as.import(bs)));
7952
7960
 
7953
7961
  /***/ },
7954
7962
 
@@ -8450,7 +8458,8 @@ const escsource = ({
8450
8458
  }) => {
8451
8459
  const {
8452
8460
  source,
8453
- position
8461
+ position,
8462
+ state
8454
8463
  } = context;
8455
8464
  if (position === source.length) return;
8456
8465
  const char = source[position];
@@ -8480,7 +8489,7 @@ const escsource = ({
8480
8489
  return new parser_1.List([new parser_1.Node((0, dom_1.html)('br'))]);
8481
8490
  default:
8482
8491
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8483
- let i = (0, text_1.next)(source, position, delimiter);
8492
+ let i = (0, text_1.next)(source, position, state, delimiter);
8484
8493
  i -= position;
8485
8494
  (0, combinator_1.consume)(i - 1, context);
8486
8495
  context.position += i - 1;
@@ -8612,7 +8621,8 @@ const text = input => {
8612
8621
  } = input;
8613
8622
  const {
8614
8623
  source,
8615
- position
8624
+ position,
8625
+ state
8616
8626
  } = context;
8617
8627
  if (position === source.length) return;
8618
8628
  const char = source[position];
@@ -8641,7 +8651,7 @@ const text = input => {
8641
8651
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8642
8652
  exports.nonWhitespace.lastIndex = position + 1;
8643
8653
  const s = canSkip(source, position);
8644
- let i = s ? exports.nonWhitespace.test(source) ? exports.nonWhitespace.lastIndex - 1 : source.length : next(source, position);
8654
+ let i = s ? exports.nonWhitespace.test(source) ? exports.nonWhitespace.lastIndex - 1 : source.length : next(source, position, state);
8645
8655
  const lineend = false || s && i === source.length || s && source[i] === '\n';
8646
8656
  i -= position;
8647
8657
  i = lineend ? i : i - +s || 1;
@@ -8672,14 +8682,14 @@ function isWhitespace(char, linebreak) {
8672
8682
  return false;
8673
8683
  }
8674
8684
  }
8675
- function next(source, position, delimiter) {
8685
+ function next(source, position, state, delimiter) {
8676
8686
  let index;
8677
8687
  if (delimiter) {
8678
8688
  delimiter.lastIndex = position + 1;
8679
8689
  delimiter.test(source);
8680
8690
  index = delimiter.lastIndex;
8681
8691
  } else {
8682
- index = seek(source, position);
8692
+ index = seek(source, position, state);
8683
8693
  }
8684
8694
  if (index === 0) return source.length;
8685
8695
  const char = source[index];
@@ -8702,7 +8712,7 @@ function next(source, position, delimiter) {
8702
8712
  index = source.startsWith('//', index + 1) ? backToUrlHead(source, position, index) : index;
8703
8713
  break;
8704
8714
  case '@':
8705
- index = backToEmailHead(source, position, index);
8715
+ index = ~state & 1 /* State.autolink */ ? backToEmailHead(source, position, index) : index;
8706
8716
  break;
8707
8717
  }
8708
8718
  return index;
@@ -8797,15 +8807,13 @@ exports.isAlphanumeric = isAlphanumeric;
8797
8807
  // this[c.charCodeAt(0)] = undefined);
8798
8808
  // }
8799
8809
  //};
8800
- function seek(source, position) {
8810
+ function seek(source, position, state) {
8801
8811
  for (let i = position + 1; i < source.length; ++i) {
8802
8812
  const fst = source[i];
8803
8813
  //if (fst.charCodeAt(0) in dict) return i;
8804
8814
  switch (fst) {
8805
8815
  case '\\':
8806
8816
  case '!':
8807
- case '@':
8808
- case '#':
8809
8817
  case '$':
8810
8818
  case '"':
8811
8819
  case '`':
@@ -8828,6 +8836,10 @@ function seek(source, position) {
8828
8836
  case '\r':
8829
8837
  case '\n':
8830
8838
  return i;
8839
+ case '@':
8840
+ case '#':
8841
+ if (~state & 1 /* State.autolink */) return i;
8842
+ continue;
8831
8843
  case '+':
8832
8844
  case '~':
8833
8845
  case '=':
@@ -8897,7 +8909,8 @@ const unescsource = ({
8897
8909
  }) => {
8898
8910
  const {
8899
8911
  source,
8900
- position
8912
+ position,
8913
+ state
8901
8914
  } = context;
8902
8915
  if (position === source.length) return;
8903
8916
  const char = source[position];
@@ -8916,7 +8929,7 @@ const unescsource = ({
8916
8929
  default:
8917
8930
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8918
8931
  text_1.nonWhitespace.lastIndex = position + 1;
8919
- let i = (0, text_1.canSkip)(source, position) ? text_1.nonWhitespace.test(source) ? text_1.nonWhitespace.lastIndex - 1 : source.length : (0, text_1.next)(source, position, exports.delimiter);
8932
+ let i = (0, text_1.canSkip)(source, position) ? text_1.nonWhitespace.test(source) ? text_1.nonWhitespace.lastIndex - 1 : source.length : (0, text_1.next)(source, position, state, exports.delimiter);
8920
8933
  i -= position;
8921
8934
  (0, combinator_1.consume)(i - 1, context);
8922
8935
  context.position += i - 1;
@@ -9068,7 +9081,7 @@ exports.stringify = stringify;
9068
9081
  Object.defineProperty(exports, "__esModule", ({
9069
9082
  value: true
9070
9083
  }));
9071
- exports.trimBlankNodeEnd = exports.trimBlankEnd = exports.trimBlankStart = exports.trimBlank = exports.isTightNodeStart = exports.isLooseNodeStart = exports.tightStart = exports.blankWith = exports.visualize = void 0;
9084
+ exports.trimBlankNodeEnd = exports.trimBlankEnd = exports.trimBlankStart = exports.trimBlank = exports.isTightNodeStart = exports.isLooseNodeStart = exports.tightStart = exports.blankWith = exports.afterNonblank = exports.visualize = void 0;
9072
9085
  const parser_1 = __webpack_require__(605);
9073
9086
  const combinator_1 = __webpack_require__(3484);
9074
9087
  const htmlentity_1 = __webpack_require__(470);
@@ -9082,14 +9095,17 @@ function visualize(parser) {
9082
9095
  return (0, combinator_1.convert)(source => source.replace(blank.line, `$1${"\u001B" /* Command.Escape */}$2`), parser);
9083
9096
  }
9084
9097
  exports.visualize = visualize;
9098
+ exports.afterNonblank = nonblankWith('');
9085
9099
  function blankWith(starts, delimiter) {
9086
- if (delimiter === undefined) return blankWith('', starts);
9087
- return new RegExp(String.raw`(?:(?=${starts})(?:\\?\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)${
9100
+ return new RegExp([
9088
9101
  // 空行除去
9089
9102
  // 完全な空行はエスケープ済みなので再帰的バックトラックにはならない。
9090
- starts && '+'})?${typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source}`, 'y');
9103
+ String.raw`(?:${starts}(?:\\?\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)*)?`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9091
9104
  }
9092
9105
  exports.blankWith = blankWith;
9106
+ function nonblankWith(delimiter) {
9107
+ return new RegExp([String.raw`(?<!\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9108
+ }
9093
9109
  function tightStart(parser, except) {
9094
9110
  return input => isTightStart(input, except) ? parser(input) : undefined;
9095
9111
  }
package/markdown.d.ts CHANGED
@@ -959,7 +959,6 @@ export namespace MarkdownParser {
959
959
  Inline<'mark'>,
960
960
  Parser<HTMLElement | string, Context, [
961
961
  InlineParser,
962
- InlineParser,
963
962
  ]> {
964
963
  }
965
964
  export interface EmStrongParser extends
@@ -967,25 +966,22 @@ export namespace MarkdownParser {
967
966
  Inline<'emstrong'>,
968
967
  Parser<HTMLElement | string, Context, [
969
968
  InlineParser,
970
- InlineParser,
971
969
  ]> {
972
970
  }
973
971
  export interface StrongParser extends
974
972
  // **abc**
975
973
  Inline<'strong'>,
976
974
  Parser<HTMLElement | string, Context, [
977
- EmphasisParser,
978
- InlineParser,
979
975
  InlineParser,
976
+ EmphasisParser,
980
977
  ]> {
981
978
  }
982
979
  export interface EmphasisParser extends
983
980
  // *abc*
984
981
  Inline<'emphasis'>,
985
982
  Parser<HTMLElement | string, Context, [
986
- StrongParser,
987
- InlineParser,
988
983
  InlineParser,
984
+ StrongParser,
989
985
  ]> {
990
986
  }
991
987
  export interface ItalicParser extends
@@ -993,7 +989,6 @@ export namespace MarkdownParser {
993
989
  Inline<'italic'>,
994
990
  Parser<HTMLElement | string, Context, [
995
991
  InlineParser,
996
- InlineParser,
997
992
  ]> {
998
993
  }
999
994
  export interface MathParser extends
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.295.5",
3
+ "version": "0.295.6",
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",
@@ -27,14 +27,17 @@ export class Delimiters {
27
27
  return `r/${pattern.source}`;
28
28
  }
29
29
  }
30
- public static matcher(pattern: string | RegExp | undefined): (input: Input<Context>) => true | undefined {
30
+ public static matcher(pattern: string | RegExp | undefined, after?: string | RegExp): (input: Input<Context>) => true | undefined {
31
31
  switch (typeof pattern) {
32
32
  case 'undefined':
33
33
  return () => undefined;
34
34
  case 'string':
35
35
  case 'object':
36
36
  const match = matcher(pattern, false);
37
- return input => match(input) !== undefined || undefined;
37
+ const verify = after ? matcher(after, false) : undefined;
38
+ return verify
39
+ ? input => match(input) !== undefined && verify(input) !== undefined || undefined
40
+ : input => match(input) !== undefined || undefined;
38
41
  }
39
42
  }
40
43
  private readonly tree: Record<number, Delimiter[]> = {};
@@ -4,12 +4,25 @@ import { Delimiters } from '../delimiter';
4
4
  type DelimiterOption = readonly [delimiter: string | RegExp, precedence: number];
5
5
 
6
6
  export function some<P extends Parser>(parser: P, limit?: number): P;
7
- export function some<P extends Parser>(parser: P, end?: string | RegExp, delimiters?: readonly DelimiterOption[], limit?: number): P;
8
- export function some<N>(parser: Parser<N>, end?: string | RegExp | number, delimiters: readonly DelimiterOption[] = [], limit = -1): Parser<N> {
9
- if (typeof end === 'number') return some(parser, undefined, delimiters, end);
7
+ export function some<P extends Parser>(parser: P, delimiters?: readonly DelimiterOption[]): P;
8
+ export function some<P extends Parser>(parser: P, delimiter: string | RegExp, delimiters?: readonly DelimiterOption[]): P;
9
+ export function some<P extends Parser>(parser: P, delimiter: string | RegExp, after: string | RegExp, delimiters?: readonly DelimiterOption[]): P;
10
+ export function some<N>(parser: Parser<N>, delimiter?: number | string | RegExp | readonly DelimiterOption[], after?: string | RegExp | readonly DelimiterOption[], delimiters?: readonly DelimiterOption[], limit = -1): Parser<N> {
11
+ if (typeof delimiter === 'number') {
12
+ limit = delimiter;
13
+ delimiter = undefined;
14
+ }
15
+ else if (Array.isArray(delimiter)) {
16
+ delimiters = delimiter;
17
+ delimiter = undefined;
18
+ }
19
+ else if (after === undefined || Array.isArray(after)) {
20
+ delimiters = after;
21
+ after = undefined;
22
+ }
10
23
  assert(parser);
11
- const match = Delimiters.matcher(end);
12
- const delims = delimiters.map(([delimiter, precedence]) => ({
24
+ const match = Delimiters.matcher(delimiter as string, after as string);
25
+ const delims = delimiters?.map(([delimiter, precedence]) => ({
13
26
  signature: Delimiters.signature(delimiter),
14
27
  matcher: Delimiters.matcher(delimiter),
15
28
  precedence,
@@ -19,9 +32,7 @@ export function some<N>(parser: Parser<N>, end?: string | RegExp | number, delim
19
32
  const { source, position } = context;
20
33
  //assert(context.backtracks ??= {});
21
34
  let nodes: List<Node<N>> | undefined;
22
- if (delims.length > 0) {
23
- context.delimiters.push(delims);
24
- }
35
+ delims && context.delimiters.push(delims);
25
36
  // whileは数倍遅い
26
37
  for (const len = source.length; context.position < len;) {
27
38
  if (match(input)) break;
@@ -31,9 +42,7 @@ export function some<N>(parser: Parser<N>, end?: string | RegExp | number, delim
31
42
  nodes = nodes?.import(result) ?? result;
32
43
  if (limit >= 0 && context.position - position > limit) break;
33
44
  }
34
- if (delims.length > 0) {
35
- context.delimiters.pop(delims.length);
36
- }
45
+ delims && context.delimiters.pop(delims.length);
37
46
  assert(context.position >= position);
38
47
  return context.position > position
39
48
  ? nodes
@@ -22,7 +22,7 @@ const indent = block(open(opener, some(contentline, />(?:$|[ \n])/y)), false);
22
22
  const unindent = (source: string) => source.replace(/(?<=^|\n)>(?: |(?=>*(?:$|[ \n])))|\n$/g, '');
23
23
 
24
24
  const source: BlockquoteParser.SourceParser = lazy(() => fmap(
25
- some(recursion(Recursion.blockquote, union([
25
+ recursion(Recursion.blockquote, some(union([
26
26
  rewrite(
27
27
  indent,
28
28
  convert(unindent, source, true)),
@@ -33,7 +33,7 @@ const source: BlockquoteParser.SourceParser = lazy(() => fmap(
33
33
  ns => new List([new Node(html('blockquote', unwrap(ns)))])));
34
34
 
35
35
  const markdown: BlockquoteParser.MarkdownParser = lazy(() => fmap(
36
- some(recursion(Recursion.blockquote, union([
36
+ recursion(Recursion.blockquote, some(union([
37
37
  rewrite(
38
38
  indent,
39
39
  convert(unindent, markdown, true)),
@@ -17,7 +17,7 @@ export const ilist: IListParser = lazy(() => block(validate(
17
17
 
18
18
  export const ilist_: IListParser = lazy(() => block(fmap(validate(
19
19
  /[-+*](?:$|[ \n])/y,
20
- some(recursion(Recursion.listitem, union([
20
+ recursion(Recursion.listitem, some(union([
21
21
  fmap(fallback(
22
22
  inits([
23
23
  line(open(/[-+*](?:$|[ \n])/y, visualize(trimBlank(some(inline))), true)),
@@ -32,7 +32,7 @@ export const olist_: OListParser = lazy(() => block(union([
32
32
  ])));
33
33
 
34
34
  const list = (type: string, form: string): OListParser.ListParser => fmap(
35
- some(recursion(Recursion.listitem, union([
35
+ recursion(Recursion.listitem, some(union([
36
36
  indexee(fmap(fallback(
37
37
  inits([
38
38
  line(open(heads[form], subsequence([
@@ -21,7 +21,7 @@ const opener = /(?=\|\|+(?:$|[ \n]))/y;
21
21
  const unindent = (source: string) => source.replace(/(?<=^|\n)\|(?: |(?=\|*(?:$|[ \n])))|\n$/g, '');
22
22
 
23
23
  const source: SidefenceParser.SourceParser = lazy(() => fmap(
24
- some(recursion(Recursion.block, union([
24
+ recursion(Recursion.block, some(union([
25
25
  focus(
26
26
  /(?:\|\|+(?=$|[ \n])[^\n]*(?:$|\n))+/y,
27
27
  convert(unindent, source, true)),
@@ -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
  /-(?=$|[ \n])/y,
18
- some(recursion(Recursion.listitem, union([
18
+ recursion(Recursion.listitem, some(union([
19
19
  indexee(fmap(fallback(
20
20
  inits([
21
21
  line(open(/-(?:$|[ \n])/y, subsequence([
@@ -12,7 +12,7 @@ export const url: AutolinkParser.UrlParser = lazy(() => rewrite(
12
12
  precedence(0, some(union([
13
13
  some(unescsource, /(?<![-+*=~^_,.;:!?]|\/{3})(?:[-+*=~^_,.;:!?]|\/{3,}(?!\/))*(?=[\\$"`\[\](){}<>()[]{}|]|[^\x21-\x7E]|$)/y),
14
14
  precedence(1, verify(bracket, ns => ns.length > 0)),
15
- ]), undefined, [[/[^\x21-\x7E]|\$/y, 9]])),
15
+ ]), [[/[^\x21-\x7E]|\$/y, 9]])),
16
16
  false,
17
17
  [3 | Backtrack.unescapable]),
18
18
  union([
@@ -8,15 +8,14 @@ import { unwrap, repeat } from '../util';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
 
10
10
  export const deletion: DeletionParser = lazy(() =>
11
- precedence(0, repeat('~~', surround(
11
+ precedence(0, recursion(Recursion.inline, repeat('~~', surround(
12
12
  '',
13
- recursion(Recursion.inline,
14
13
  some(union([
15
14
  some(inline, blankWith('\n', '~~')),
16
15
  open('\n', some(inline, '~'), true),
17
- ]))),
16
+ ])),
18
17
  '~~',
19
18
  false, [],
20
19
  ([, bs], { buffer }) => buffer.import(bs),
21
20
  ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
22
- nodes => new List([new Node(html('del', defrag(unwrap(nodes))))]))));
21
+ nodes => new List([new Node(html('del', defrag(unwrap(nodes))))])))));
@@ -1,11 +1,11 @@
1
1
  import { EmphasisParser } from '../inline';
2
2
  import { Recursion } from '../context';
3
3
  import { List, Node } from '../../combinator/data/parser';
4
- import { union, some, recursion, precedence, surround, open, lazy } from '../../combinator';
4
+ import { union, some, recursion, precedence, surround, lazy } from '../../combinator';
5
5
  import { inline } from '../inline';
6
6
  import { strong } from './strong';
7
7
  import { str } from '../source';
8
- import { tightStart, blankWith } from '../visibility';
8
+ import { tightStart, afterNonblank } from '../visibility';
9
9
  import { unwrap } from '../util';
10
10
  import { html, defrag } from 'typed-dom/dom';
11
11
 
@@ -13,9 +13,8 @@ export const emphasis: EmphasisParser = lazy(() => surround(
13
13
  str(/\*(?!\*)/y),
14
14
  precedence(0, recursion(Recursion.inline,
15
15
  tightStart(some(union([
16
+ some(inline, '*', afterNonblank),
16
17
  strong,
17
- some(inline, blankWith('*')),
18
- open(some(inline, '*'), inline),
19
18
  ]))))),
20
19
  str('*'),
21
20
  false, [],
@@ -1,37 +1,31 @@
1
1
  import { EmStrongParser, EmphasisParser, StrongParser } from '../inline';
2
2
  import { Recursion, Command } from '../context';
3
3
  import { Parser, Result, List, Node } from '../../combinator/data/parser';
4
- import { union, some, recursion, precedence, surround, open, lazy, bind } from '../../combinator';
4
+ import { union, some, recursion, precedence, surround, lazy, bind } from '../../combinator';
5
5
  import { inline } from '../inline';
6
6
  import { strong } from './strong';
7
7
  import { emphasis } from './emphasis';
8
8
  import { str } from '../source';
9
- import { tightStart, blankWith } from '../visibility';
9
+ import { tightStart, afterNonblank } from '../visibility';
10
10
  import { unwrap, repeat } from '../util';
11
11
  import { html, defrag } from 'typed-dom/dom';
12
12
 
13
13
  const substrong: Parser.IntermediateParser<StrongParser> = lazy(() => some(union([
14
+ some(inline, '*', afterNonblank),
14
15
  emphasis,
15
- some(inline, blankWith('*')),
16
- open(some(inline, '*'), inline),
17
16
  ])));
18
17
  const subemphasis: Parser.IntermediateParser<EmphasisParser> = lazy(() => some(union([
18
+ some(inline, '*', afterNonblank),
19
19
  strong,
20
- some(inline, blankWith('*')),
21
- open(some(inline, '*'), inline),
22
20
  ])));
23
21
 
24
22
  // 開閉が明示的でない構文は開閉の不明確な記号による再帰的適用を行わず
25
23
  // 可能な限り早く閉じるよう解析しなければならない。
26
24
  // このため終端記号の後ろを見て終端を中止し同じ構文を再帰的に適用してはならない。
27
25
  export const emstrong: EmStrongParser = lazy(() =>
28
- precedence(0, repeat('***', surround(
26
+ precedence(0, recursion(Recursion.inline, repeat('***', surround(
29
27
  '',
30
- recursion(Recursion.inline,
31
- tightStart(some(union([
32
- some(inline, blankWith('*')),
33
- open(some(inline, '*'), inline),
34
- ])))),
28
+ tightStart(some(union([some(inline, '*', afterNonblank)]))),
35
29
  str(/\*{1,3}/y),
36
30
  false, [],
37
31
  ([, bs, cs], context): Result<Parser.Node<EmStrongParser>, Parser.Context<EmStrongParser>> => {
@@ -143,7 +137,7 @@ export const emstrong: EmStrongParser = lazy(() =>
143
137
  nodes = prepend('*'.repeat(prefix - postfix), nodes);
144
138
  }
145
139
  return nodes;
146
- })));
140
+ }))));
147
141
 
148
142
  function prepend<N>(prefix: string, nodes: List<Node<N>>): List<Node<N>> {
149
143
  if (typeof nodes.head?.value === 'string') {
@@ -8,15 +8,14 @@ import { unwrap, repeat } from '../util';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
 
10
10
  export const insertion: InsertionParser = lazy(() =>
11
- precedence(0, repeat('++', surround(
11
+ precedence(0, recursion(Recursion.inline, repeat('++', surround(
12
12
  '',
13
- recursion(Recursion.inline,
14
13
  some(union([
15
14
  some(inline, blankWith('\n', '++')),
16
15
  open('\n', some(inline, '+'), true),
17
- ]))),
16
+ ])),
18
17
  '++',
19
18
  false, [],
20
19
  ([, bs], { buffer }) => buffer.import(bs),
21
20
  ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
22
- nodes => new List([new Node(html('ins', defrag(unwrap(nodes))))]))));
21
+ nodes => new List([new Node(html('ins', defrag(unwrap(nodes))))])))));
@@ -1,9 +1,9 @@
1
1
  import { ItalicParser } from '../inline';
2
2
  import { Recursion, Command } from '../context';
3
3
  import { List, Node } from '../../combinator/data/parser';
4
- import { union, some, recursion, precedence, surround, open, lazy } from '../../combinator';
4
+ import { union, some, recursion, precedence, surround, lazy } from '../../combinator';
5
5
  import { inline } from '../inline';
6
- import { tightStart, blankWith } from '../visibility';
6
+ import { tightStart, afterNonblank } from '../visibility';
7
7
  import { unwrap, repeat } from '../util';
8
8
  import { html, defrag } from 'typed-dom/dom';
9
9
 
@@ -11,15 +11,11 @@ import { html, defrag } from 'typed-dom/dom';
11
11
  // 斜体は単語に使うとかえって見づらく読み飛ばしやすくなるため使わないべきであり
12
12
  // ある程度の長さのある文に使うのが望ましい。
13
13
  export const italic: ItalicParser = lazy(() =>
14
- precedence(0, repeat('///', surround(
14
+ precedence(0, recursion(Recursion.inline, repeat('///', surround(
15
15
  '',
16
- recursion(Recursion.inline,
17
- tightStart(some(union([
18
- some(inline, blankWith('///')),
19
- open(some(inline, '/'), inline),
20
- ])))),
16
+ tightStart(some(union([inline]), '///', afterNonblank)),
21
17
  '///',
22
18
  false, [],
23
19
  ([, bs], { buffer }) => buffer.import(bs),
24
20
  ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
25
- nodes => new List([new Node(html('i', defrag(unwrap(nodes))))]))));
21
+ nodes => new List([new Node(html('i', defrag(unwrap(nodes))))])))));
@@ -183,7 +183,7 @@ describe('Unit: parser/inline/link', () => {
183
183
  assert.deepStrictEqual(inspect(parser, input('[@a]{b}', new Context())), [['<a class="link" href="b">@a</a>'], '']);
184
184
  assert.deepStrictEqual(inspect(parser, input('[@a@b]{c}', new Context())), [['<a class="link" href="c">@a@b</a>'], '']);
185
185
  assert.deepStrictEqual(inspect(parser, input('[a@b]{c}', new Context())), [['<a class="link" href="c">a@b</a>'], '']);
186
- assert.deepStrictEqual(inspect(parser, input('[==a==]{b}', new Context())), [['<a class="link" href="b">==a==</a>'], '']);
186
+ assert.deepStrictEqual(inspect(parser, input('[==a==]{b}', new Context())), [['<a class="link" href="b"><mark>a</mark></a>'], '']);
187
187
  assert.deepStrictEqual(inspect(parser, input('[*a*]{b}', new Context())), [['<a class="link" href="b"><em>a</em></a>'], '']);
188
188
  });
189
189
 
@@ -38,12 +38,12 @@ describe('Unit: parser/inline/mark', () => {
38
38
  });
39
39
 
40
40
  it('nest', () => {
41
- assert.deepStrictEqual(inspect(parser, input('==a ==b====', new Context())), [['<mark id="mark::a_b">a <mark id="mark::b">b</mark><a href="#mark::b"></a></mark>', '<a href="#mark::a_b"></a>'], '']);
42
- assert.deepStrictEqual(inspect(parser, input('==- ==b====', new Context())), [['<mark id="mark::-_b">- <mark id="mark::b">b</mark><a href="#mark::b"></a></mark>', '<a href="#mark::-_b"></a>'], '']);
43
- assert.deepStrictEqual(inspect(parser, input('==a\\ ==b====', new Context())), [['<mark id="mark::a_b">a <mark id="mark::b">b</mark><a href="#mark::b"></a></mark>', '<a href="#mark::a_b"></a>'], '']);
44
- assert.deepStrictEqual(inspect(parser, input('==a&Tab;==b====', new Context())), [['<mark id="mark::a_b=33Mw2l">a\t<mark id="mark::b">b</mark><a href="#mark::b"></a></mark>', '<a href="#mark::a_b=33Mw2l"></a>'], '']);
45
- assert.deepStrictEqual(inspect(parser, input('==a<wbr>==b====', new Context())), [['<mark id="mark::ab">a<wbr><mark id="mark::b">b</mark><a href="#mark::b"></a></mark>', '<a href="#mark::ab"></a>'], '']);
46
- assert.deepStrictEqual(inspect(parser, input('==*==a==*==', new Context())), [['<mark id="mark::a"><em><mark id="mark::a">a</mark><a href="#mark::a"></a></em></mark>', '<a href="#mark::a"></a>'], '']);
41
+ assert.deepStrictEqual(inspect(parser, input('==a ==b====', new Context())), [['<mark id="mark::a_b">a <mark>b</mark></mark>', '<a href="#mark::a_b"></a>'], '']);
42
+ assert.deepStrictEqual(inspect(parser, input('==- ==b====', new Context())), [['<mark id="mark::-_b">- <mark>b</mark></mark>', '<a href="#mark::-_b"></a>'], '']);
43
+ assert.deepStrictEqual(inspect(parser, input('==a\\ ==b====', new Context())), [['<mark id="mark::a_b">a <mark>b</mark></mark>', '<a href="#mark::a_b"></a>'], '']);
44
+ assert.deepStrictEqual(inspect(parser, input('==a&Tab;==b====', new Context())), [['<mark id="mark::a_b=33Mw2l">a\t<mark>b</mark></mark>', '<a href="#mark::a_b=33Mw2l"></a>'], '']);
45
+ assert.deepStrictEqual(inspect(parser, input('==a<wbr>==b====', new Context())), [['<mark id="mark::ab">a<wbr><mark>b</mark></mark>', '<a href="#mark::ab"></a>'], '']);
46
+ assert.deepStrictEqual(inspect(parser, input('==*==a==*==', new Context())), [['<mark id="mark::a"><em><mark>a</mark></em></mark>', '<a href="#mark::a"></a>'], '']);
47
47
  });
48
48
 
49
49
  });
@@ -1,29 +1,26 @@
1
1
  import { MarkParser } from '../inline';
2
2
  import { State, Recursion, Command } from '../context';
3
3
  import { List, Node } from '../../combinator/data/parser';
4
- import { union, some, recursion, precedence, state, constraint, surround, open, lazy } from '../../combinator';
4
+ import { union, some, recursion, precedence, state, surround, lazy } from '../../combinator';
5
5
  import { inline } from '../inline';
6
6
  import { identity, signature } from './extension/indexee';
7
- import { tightStart, blankWith } from '../visibility';
7
+ import { tightStart, afterNonblank } from '../visibility';
8
8
  import { unwrap, repeat } from '../util';
9
9
  import { html, define, defrag } from 'typed-dom/dom';
10
10
 
11
- export const mark: MarkParser = lazy(() => constraint(State.linkers & ~State.mark,
12
- precedence(0, state(State.mark, repeat('==', surround(
11
+ export const mark: MarkParser = lazy(() =>
12
+ precedence(0, recursion(Recursion.inline, repeat('==', surround(
13
13
  '',
14
- recursion(Recursion.inline,
15
- tightStart(some(union([
16
- some(inline, blankWith('==')),
17
- open(some(inline, '='), inline),
18
- ])))),
14
+ tightStart(state(State.mark, some(union([inline]), '==', afterNonblank))),
19
15
  '==',
20
16
  false, [],
21
17
  ([, bs], { buffer }) => buffer.import(bs),
22
18
  ([, bs], { buffer }) => bs && buffer.import(bs).push(new Node(Command.Cancel)) && buffer),
23
- (nodes, { id }) => {
19
+ (nodes, { id, state }) => {
24
20
  const el = html('mark', defrag(unwrap(nodes)));
21
+ if (state & State.linkers) return new List([new Node(el)]);
25
22
  define(el, { id: identity('mark', id, signature(el)) });
26
23
  return el.id
27
24
  ? new List([new Node(el), new Node(html('a', { href: `#${el.id}` }))])
28
25
  : new List([new Node(el)]);
29
- })))));
26
+ }))));
@@ -1,11 +1,11 @@
1
1
  import { StrongParser } from '../inline';
2
2
  import { Recursion } from '../context';
3
3
  import { List, Node } from '../../combinator/data/parser';
4
- import { union, some, recursion, precedence, surround, open, lazy } from '../../combinator';
4
+ import { union, some, recursion, precedence, surround, lazy } from '../../combinator';
5
5
  import { inline } from '../inline';
6
6
  import { emphasis } from './emphasis';
7
7
  import { str } from '../source';
8
- import { tightStart, blankWith } from '../visibility';
8
+ import { tightStart, afterNonblank } from '../visibility';
9
9
  import { unwrap } from '../util';
10
10
  import { html, defrag } from 'typed-dom/dom';
11
11
 
@@ -13,9 +13,8 @@ export const strong: StrongParser = lazy(() => surround(
13
13
  str(/\*\*(?!\*)/y),
14
14
  precedence(0, recursion(Recursion.inline,
15
15
  tightStart(some(union([
16
+ some(inline, '*', afterNonblank),
16
17
  emphasis,
17
- some(inline, blankWith('*')),
18
- open(some(inline, '*'), inline),
19
18
  ]))))),
20
19
  str('**'),
21
20
  false, [],
@@ -154,7 +154,7 @@ describe('Unit: parser/inline', () => {
154
154
  assert.deepStrictEqual(inspect(parser, input('[[a\nb]]', new Context())), [['[', '[', 'a', '<br>', 'b', ']', ']'], '']);
155
155
  assert.deepStrictEqual(inspect(parser, input('[[[a\nb]]]', new Context())), [['[', '[', '[', 'a', '<br>', 'b', ']', ']', ']'], '']);
156
156
  assert.deepStrictEqual(inspect(parser, input('"[[""]]', new Context())), [['"', '[', '[', '"', '"', ']', ']'], '']);
157
- assert.deepStrictEqual(inspect(parser, input('[==a==]{b}', new Context())), [['<a class="link" href="b">==a==</a>'], '']);
157
+ assert.deepStrictEqual(inspect(parser, input('[==a==]{b}', new Context())), [['<a class="link" href="b"><mark>a</mark></a>'], '']);
158
158
  assert.deepStrictEqual(inspect(parser, input('[[a](b)]{c}', new Context())), [['<a class="link" href="c"><ruby>a<rp>(</rp><rt>b</rt><rp>)</rp></ruby></a>'], '']);
159
159
  assert.deepStrictEqual(inspect(parser, input('[[[[[[[{a}', new Context())), [['[', '[', '[', '[', '[', '[', '[', '<a class="url" href="a">a</a>'], '']);
160
160
  assert.deepStrictEqual(inspect(parser, input('<http://host>', new Context())), [['<', '<a class="url" href="http://host" target="_blank">http://host</a>', '>'], '']);
@@ -170,6 +170,7 @@ describe('Unit: parser/inline', () => {
170
170
  assert.deepStrictEqual(inspect(parser, input('[#@a/http://host/(<bdi>)]</bdi>', new Context())), [['<a class="index" href="#index::@a/http://host/(&lt;bdi&gt;)">@a/http://host/<span class="paren">(<span class="invalid">&lt;bdi&gt;</span>)</span></a>', '</bdi', '>'], '']);
171
171
  assert.deepStrictEqual(inspect(parser, input('[#a|<bdi>]</bdi>', new Context())), [['<a class="index" href="#index::a|&lt;bdi&gt;">a|<span class="invalid">&lt;bdi&gt;</span></a>', '</bdi', '>'], '']);
172
172
  assert.deepStrictEqual(inspect(parser, input('[[#a|<bdi>]</bdi>', new Context())), [['[', '<a class="index" href="#index::a|&lt;bdi&gt;">a|<span class="invalid">&lt;bdi&gt;</span></a>', '</bdi', '>'], '']);
173
+ assert.deepStrictEqual(inspect(parser, input('[*==*]{a}', new Context())), [['<a class="link" href="a">*==*</a>'], '']);
173
174
  assert.deepStrictEqual(inspect(parser, input('[]{"}[[""]]}]', new Context())), [['<a class="url" href="&quot;">"</a>', '<sup class="reference"><span>""</span></sup>', '}', ']'], '']);
174
175
  assert.deepStrictEqual(inspect(parser, input('[ []{"}[[""]]}]', new Context())), [['[', ' ', '<a class="url" href="&quot;">"</a>', '<sup class="reference"><span>""</span></sup>', '}', ']'], '']);
175
176
  });
@@ -8,7 +8,7 @@ import { html } from 'typed-dom/dom';
8
8
  const delimiter = /(?=[\\$"`\[\](){}\r\n]|\s\$|:\/\/)/g;
9
9
 
10
10
  export const escsource: EscapableSourceParser = ({ context }) => {
11
- const { source, position } = context;
11
+ const { source, position, state } = context;
12
12
  if (position === source.length) return;
13
13
  const char = source[position];
14
14
  consume(1, context);
@@ -38,7 +38,7 @@ export const escsource: EscapableSourceParser = ({ context }) => {
38
38
  default:
39
39
  assert(char !== '\n');
40
40
  if (context.sequential) return new List([new Node(char)]);
41
- let i = next(source, position, delimiter);
41
+ let i = next(source, position, state, delimiter);
42
42
  assert(i > position);
43
43
  i -= position;
44
44
  consume(i - 1, context);
@@ -1,5 +1,5 @@
1
1
  import { TextParser, TxtParser } from '../source';
2
- import { Command } from '../context';
2
+ import { State, Command } from '../context';
3
3
  import { List, Node } from '../../combinator/data/parser';
4
4
  import { union, consume } from '../../combinator';
5
5
  import { html } from 'typed-dom/dom';
@@ -9,7 +9,7 @@ export const nonWhitespace = /[^ \t ]/g;
9
9
 
10
10
  export const text: TextParser = input => {
11
11
  const { context } = input;
12
- const { source, position } = context;
12
+ const { source, position, state } = context;
13
13
  if (position === source.length) return;
14
14
  const char = source[position];
15
15
  consume(1, context);
@@ -43,7 +43,7 @@ export const text: TextParser = input => {
43
43
  ? nonWhitespace.test(source)
44
44
  ? nonWhitespace.lastIndex - 1
45
45
  : source.length
46
- : next(source, position);
46
+ : next(source, position, state);
47
47
  assert(i > position);
48
48
  const lineend = 0
49
49
  || s && i === source.length
@@ -83,7 +83,7 @@ function isWhitespace(char: string, linebreak: boolean): boolean {
83
83
  }
84
84
  }
85
85
 
86
- export function next(source: string, position: number, delimiter?: RegExp): number {
86
+ export function next(source: string, position: number, state: number, delimiter?: RegExp): number {
87
87
  let index: number;
88
88
  if (delimiter) {
89
89
  delimiter.lastIndex = position + 1;
@@ -91,7 +91,7 @@ export function next(source: string, position: number, delimiter?: RegExp): numb
91
91
  index = delimiter.lastIndex;
92
92
  }
93
93
  else {
94
- index = seek(source, position);
94
+ index = seek(source, position, state);
95
95
  }
96
96
  if (index === 0) return source.length;
97
97
  assert(index > position);
@@ -121,7 +121,9 @@ export function next(source: string, position: number, delimiter?: RegExp): numb
121
121
  : index;
122
122
  break;
123
123
  case '@':
124
- index = backToEmailHead(source, position, index);
124
+ index = ~state & State.autolink
125
+ ? backToEmailHead(source, position, index)
126
+ : index;
125
127
  break;
126
128
  }
127
129
  assert(index > position);
@@ -223,15 +225,13 @@ export function isAlphanumeric(char: string): boolean {
223
225
  // }
224
226
  //};
225
227
 
226
- function seek(source: string, position: number): number {
228
+ function seek(source: string, position: number, state: number): number {
227
229
  for (let i = position + 1; i < source.length; ++i) {
228
230
  const fst = source[i];
229
231
  //if (fst.charCodeAt(0) in dict) return i;
230
232
  switch (fst) {
231
233
  case '\\':
232
234
  case '!':
233
- case '@':
234
- case '#':
235
235
  case '$':
236
236
  case '"':
237
237
  case '`':
@@ -254,6 +254,10 @@ function seek(source: string, position: number): number {
254
254
  case '\r':
255
255
  case '\n':
256
256
  return i;
257
+ case '@':
258
+ case '#':
259
+ if (~state & State.autolink) return i;
260
+ continue;
257
261
  case '+':
258
262
  case '~':
259
263
  case '=':
@@ -8,7 +8,7 @@ import { html } from 'typed-dom/dom';
8
8
  export const delimiter = /(?=(?=[\x00-\x7F])[^0-9A-Za-z]|(?<=[\x00-\x7F])[^\x00-\x7F])/g;
9
9
 
10
10
  export const unescsource: UnescapableSourceParser = ({ context }) => {
11
- const { source, position } = context;
11
+ const { source, position, state } = context;
12
12
  if (position === source.length) return;
13
13
  const char = source[position];
14
14
  consume(1, context);
@@ -31,7 +31,7 @@ export const unescsource: UnescapableSourceParser = ({ context }) => {
31
31
  ? nonWhitespace.test(source)
32
32
  ? nonWhitespace.lastIndex - 1
33
33
  : source.length
34
- : next(source, position, delimiter);
34
+ : next(source, position, state, delimiter);
35
35
  assert(i > position);
36
36
  i -= position;
37
37
  consume(i - 1, context);
@@ -22,20 +22,24 @@ export function visualize<N extends HTMLElement | string>(parser: Parser<N>): Pa
22
22
  parser);
23
23
  }
24
24
 
25
- export function blankWith(delimiter: string | RegExp): RegExp;
26
- export function blankWith(starts: '' | '\n', delimiter: string | RegExp): RegExp;
27
- export function blankWith(starts: '' | '\n', delimiter?: string | RegExp): RegExp {
28
- if (delimiter === undefined) return blankWith('', starts);
29
- return new RegExp(String.raw
30
- `(?:(?=${starts})(?:\\?\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr ?>)${
31
- // 空行除去
32
- // 完全な空行はエスケープ済みなので再帰的バックトラックにはならない。
33
- starts && '+'
34
- })?${
35
- typeof delimiter === 'string'
36
- ? delimiter.replace(/[*+()\[\]]/g, '\\$&')
37
- : delimiter.source
38
- }`, 'y');
25
+ export const afterNonblank = nonblankWith('');
26
+ export function blankWith(starts: '\n', delimiter: string | RegExp): RegExp {
27
+ return new RegExp([
28
+ // 空行除去
29
+ // 完全な空行はエスケープ済みなので再帰的バックトラックにはならない。
30
+ String.raw`(?:${starts}(?:\\?\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr ?>)*)?`,
31
+ typeof delimiter === 'string'
32
+ ? delimiter.replace(/[*+()\[\]]/g, '\\$&')
33
+ : delimiter.source,
34
+ ].join(''), 'y');
35
+ }
36
+ function nonblankWith(delimiter: string | RegExp): RegExp {
37
+ return new RegExp([
38
+ String.raw`(?<!\s|&(?:${invisibleHTMLEntityNames.join('|')});|<wbr ?>)`,
39
+ typeof delimiter === 'string'
40
+ ? delimiter.replace(/[*+()\[\]]/g, '\\$&')
41
+ : delimiter.source,
42
+ ].join(''), 'y');
39
43
  }
40
44
 
41
45
  //export function looseStart<P extends Parser<HTMLElement | string>>(parser: P, except?: string): P;