securemark 0.295.5 → 0.295.7

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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.295.7
4
+
5
+ - Refactoring.
6
+
7
+ ## 0.295.6
8
+
9
+ - Refactoring.
10
+
3
11
  ## 0.295.5
4
12
 
5
13
  - 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.7 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;
@@ -8600,7 +8609,7 @@ exports.strs = strs;
8600
8609
  Object.defineProperty(exports, "__esModule", ({
8601
8610
  value: true
8602
8611
  }));
8603
- exports.isAlphanumeric = exports.backToEmailHead = exports.backToUrlHead = exports.backToWhitespace = exports.next = exports.canSkip = exports.txt = exports.text = exports.nonWhitespace = void 0;
8612
+ exports.isAlphanumeric = exports.next = exports.canSkip = exports.txt = exports.text = exports.nonWhitespace = void 0;
8604
8613
  const parser_1 = __webpack_require__(605);
8605
8614
  const combinator_1 = __webpack_require__(3484);
8606
8615
  const dom_1 = __webpack_require__(394);
@@ -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,47 +8682,34 @@ 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
- index = delimiter.lastIndex;
8690
+ index = delimiter.lastIndex || position;
8681
8691
  } else {
8682
- index = seek(source, position);
8692
+ index = seek(source, position, state);
8683
8693
  }
8684
- if (index === 0) return source.length;
8694
+ if (index === position || index === source.length) return source.length;
8685
8695
  const char = source[index];
8686
8696
  switch (char) {
8687
- case '$':
8688
- case '*':
8689
- case '+':
8690
- case '~':
8691
- case '=':
8692
- case '/':
8693
- index = backToWhitespace(source, position, index);
8694
- break;
8695
8697
  case '%':
8696
- index += index - 1 > position && source.startsWith(' %]', index - 1) ? -1 : 0;
8698
+ index += !delimiter && index - 1 > position ? -1 : 0;
8697
8699
  break;
8698
8700
  case '[':
8699
- index += index - 1 > position && source.startsWith(' [|', index - 1) ? -1 : 0;
8701
+ index += !delimiter && index - 1 > position && source.startsWith(' [|', index - 1) ? -1 : 0;
8700
8702
  break;
8701
8703
  case ':':
8702
8704
  index = source.startsWith('//', index + 1) ? backToUrlHead(source, position, index) : index;
8703
8705
  break;
8704
8706
  case '@':
8705
- index = backToEmailHead(source, position, index);
8707
+ index = ~state & 1 /* State.autolink */ ? backToEmailHead(source, position, index) : index;
8706
8708
  break;
8707
8709
  }
8708
8710
  return index;
8709
8711
  }
8710
8712
  exports.next = next;
8711
- function backToWhitespace(source, position, index) {
8712
- const prev = index - 1;
8713
- return prev > position && /\s/.test(source[prev]) ? prev : index;
8714
- }
8715
- exports.backToWhitespace = backToWhitespace;
8716
8713
  function backToUrlHead(source, position, index) {
8717
8714
  const delim = index;
8718
8715
  let state = false;
@@ -8734,7 +8731,6 @@ function backToUrlHead(source, position, index) {
8734
8731
  }
8735
8732
  return index === position || source[index] !== 'h' ? delim : index;
8736
8733
  }
8737
- exports.backToUrlHead = backToUrlHead;
8738
8734
  function backToEmailHead(source, position, index) {
8739
8735
  const delim = index;
8740
8736
  let state = false;
@@ -8757,7 +8753,6 @@ function backToEmailHead(source, position, index) {
8757
8753
  }
8758
8754
  return index === position ? delim : index;
8759
8755
  }
8760
- exports.backToEmailHead = backToEmailHead;
8761
8756
  function isAlphanumeric(char) {
8762
8757
  if (char < '0' || '\x7F' < char) return false;
8763
8758
  return '0' <= char && char <= '9' || 'A' <= char && char <= 'Z' || 'a' <= char && char <= 'z';
@@ -8797,15 +8792,13 @@ exports.isAlphanumeric = isAlphanumeric;
8797
8792
  // this[c.charCodeAt(0)] = undefined);
8798
8793
  // }
8799
8794
  //};
8800
- function seek(source, position) {
8795
+ function seek(source, position, state) {
8801
8796
  for (let i = position + 1; i < source.length; ++i) {
8802
8797
  const fst = source[i];
8803
8798
  //if (fst.charCodeAt(0) in dict) return i;
8804
8799
  switch (fst) {
8805
8800
  case '\\':
8806
8801
  case '!':
8807
- case '@':
8808
- case '#':
8809
8802
  case '$':
8810
8803
  case '"':
8811
8804
  case '`':
@@ -8828,6 +8821,10 @@ function seek(source, position) {
8828
8821
  case '\r':
8829
8822
  case '\n':
8830
8823
  return i;
8824
+ case '@':
8825
+ case '#':
8826
+ if (~state & 1 /* State.autolink */) return i;
8827
+ continue;
8831
8828
  case '+':
8832
8829
  case '~':
8833
8830
  case '=':
@@ -8837,7 +8834,7 @@ function seek(source, position) {
8837
8834
  if (source[i + 1] === fst && source[i + 2] === fst) return i;
8838
8835
  continue;
8839
8836
  case '%':
8840
- if (source[i + 1] === ']') return i;
8837
+ if (source[i + 1] === ']' && isWhitespace(source[i - 1], true)) return i;
8841
8838
  continue;
8842
8839
  case ':':
8843
8840
  if (source[i + 1] === '/' && source[i + 2] === '/') return i;
@@ -8897,7 +8894,8 @@ const unescsource = ({
8897
8894
  }) => {
8898
8895
  const {
8899
8896
  source,
8900
- position
8897
+ position,
8898
+ state
8901
8899
  } = context;
8902
8900
  if (position === source.length) return;
8903
8901
  const char = source[position];
@@ -8916,7 +8914,7 @@ const unescsource = ({
8916
8914
  default:
8917
8915
  if (context.sequential) return new parser_1.List([new parser_1.Node(char)]);
8918
8916
  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);
8917
+ 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
8918
  i -= position;
8921
8919
  (0, combinator_1.consume)(i - 1, context);
8922
8920
  context.position += i - 1;
@@ -9068,7 +9066,7 @@ exports.stringify = stringify;
9068
9066
  Object.defineProperty(exports, "__esModule", ({
9069
9067
  value: true
9070
9068
  }));
9071
- exports.trimBlankNodeEnd = exports.trimBlankEnd = exports.trimBlankStart = exports.trimBlank = exports.isTightNodeStart = exports.isLooseNodeStart = exports.tightStart = exports.blankWith = exports.visualize = void 0;
9069
+ exports.trimBlankNodeEnd = exports.trimBlankEnd = exports.trimBlankStart = exports.trimBlank = exports.isTightNodeStart = exports.isLooseNodeStart = exports.tightStart = exports.blankWith = exports.afterNonblank = exports.visualize = void 0;
9072
9070
  const parser_1 = __webpack_require__(605);
9073
9071
  const combinator_1 = __webpack_require__(3484);
9074
9072
  const htmlentity_1 = __webpack_require__(470);
@@ -9082,14 +9080,17 @@ function visualize(parser) {
9082
9080
  return (0, combinator_1.convert)(source => source.replace(blank.line, `$1${"\u001B" /* Command.Escape */}$2`), parser);
9083
9081
  }
9084
9082
  exports.visualize = visualize;
9083
+ exports.afterNonblank = nonblankWith('');
9085
9084
  function blankWith(starts, delimiter) {
9086
- if (delimiter === undefined) return blankWith('', starts);
9087
- return new RegExp(String.raw`(?:(?=${starts})(?:\\?\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)${
9085
+ return new RegExp([
9088
9086
  // 空行除去
9089
9087
  // 完全な空行はエスケープ済みなので再帰的バックトラックにはならない。
9090
- starts && '+'})?${typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source}`, 'y');
9088
+ String.raw`(?:${starts}(?:\\?\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)*)?`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9091
9089
  }
9092
9090
  exports.blankWith = blankWith;
9091
+ function nonblankWith(delimiter) {
9092
+ return new RegExp([String.raw`(?<!\s|&(?:${normalize_1.invisibleHTMLEntityNames.join('|')});|<wbr ?>)`, typeof delimiter === 'string' ? delimiter.replace(/[*+()\[\]]/g, '\\$&') : delimiter.source].join(''), 'y');
9093
+ }
9093
9094
  function tightStart(parser, except) {
9094
9095
  return input => isTightStart(input, except) ? parser(input) : undefined;
9095
9096
  }
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.7",
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([