securemark 0.280.3 → 0.280.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.280.4
4
+
5
+ - Refactoring.
6
+
3
7
  ## 0.280.3
4
8
 
5
9
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.280.3 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
1
+ /*! securemark v0.280.4 https://github.com/falsandtru/securemark | (c) 2017, falsandtru | UNLICENSED License */
2
2
  (function webpackUniversalModuleDefinition(root, factory) {
3
3
  if(typeof exports === 'object' && typeof module === 'object')
4
4
  module.exports = factory(require("Prism"), require("DOMPurify"));
@@ -2814,6 +2814,7 @@ Object.defineProperty(exports, "__esModule", ({
2814
2814
  }));
2815
2815
  exports.convert = void 0;
2816
2816
  const parser_1 = __webpack_require__(6728);
2817
+ const alias_1 = __webpack_require__(5406);
2817
2818
  function convert(conv, parser, empty = false) {
2818
2819
  return ({
2819
2820
  source,
@@ -2822,13 +2823,14 @@ function convert(conv, parser, empty = false) {
2822
2823
  if (source === '') return;
2823
2824
  const src = conv(source, context);
2824
2825
  if (src === '') return empty ? [[], ''] : undefined;
2826
+ const offset = (0, alias_1.max)(source.length - src.length, 0);
2825
2827
  context.offset ??= 0;
2826
- context.offset += source.length - src.length;
2828
+ context.offset += offset;
2827
2829
  const result = parser({
2828
2830
  source: src,
2829
2831
  context
2830
2832
  });
2831
- context.offset -= source.length - src.length;
2833
+ context.offset -= offset;
2832
2834
  return result;
2833
2835
  };
2834
2836
  }
@@ -2953,13 +2955,14 @@ function indent(opener, parser, separation = false) {
2953
2955
  return (0, bind_1.bind)((0, block_1.block)((0, match_1.match)(opener, (0, memoize_1.memoize)(([indent]) => (0, some_1.some)((0, line_1.line)((0, surround_1.open)(indent, ({
2954
2956
  source
2955
2957
  }) => [[source], '']))), ([indent]) => indent.length * 2 + +(indent[0] === ' '), {})), separation), (lines, rest, context) => {
2958
+ const offset = rest.length;
2956
2959
  context.offset ??= 0;
2957
- context.offset += rest.length;
2960
+ context.offset += offset;
2958
2961
  const result = parser({
2959
2962
  source: trimBlockEnd(lines.join('')),
2960
2963
  context
2961
2964
  });
2962
- context.offset -= rest.length;
2965
+ context.offset -= offset;
2963
2966
  return result && (0, parser_1.exec)(result) === '' ? [(0, parser_1.eval)(result), rest] : undefined;
2964
2967
  });
2965
2968
  }
@@ -3080,13 +3083,14 @@ function focus(scope, parser) {
3080
3083
  if (source === '') return;
3081
3084
  const src = match(source);
3082
3085
  if (src === '') return;
3086
+ const offset = source.length - src.length;
3083
3087
  context.offset ??= 0;
3084
- context.offset += source.length - src.length;
3088
+ context.offset += offset;
3085
3089
  const result = parser({
3086
3090
  source: src,
3087
3091
  context
3088
3092
  });
3089
- context.offset -= source.length - src.length;
3093
+ context.offset -= offset;
3090
3094
  if (result === undefined) return;
3091
3095
  return (0, parser_1.exec)(result).length < src.length ? [(0, parser_1.eval)(result), (0, parser_1.exec)(result) + source.slice(src.length)] : undefined;
3092
3096
  };
@@ -3107,13 +3111,14 @@ function rewrite(scope, parser) {
3107
3111
  context.memo = memo;
3108
3112
  if (res1 === undefined || (0, parser_1.exec)(res1).length >= source.length) return;
3109
3113
  const src = source.slice(0, source.length - (0, parser_1.exec)(res1).length);
3114
+ const offset = source.length - src.length;
3110
3115
  context.offset ??= 0;
3111
- context.offset += source.length - src.length;
3116
+ context.offset += offset;
3112
3117
  const res2 = parser({
3113
3118
  source: src,
3114
3119
  context
3115
3120
  });
3116
- context.offset -= source.length - src.length;
3121
+ context.offset -= offset;
3117
3122
  if (res2 === undefined) return;
3118
3123
  return (0, parser_1.exec)(res2).length < src.length ? [(0, parser_1.eval)(res2), (0, parser_1.exec)(res2) + (0, parser_1.exec)(res1)] : undefined;
3119
3124
  };
@@ -3645,10 +3650,10 @@ class Memo {
3645
3650
 
3646
3651
  resize(position) {
3647
3652
  const memory = this.memory;
3648
- for (let len = memory.length, i = position; i < len; ++i) {
3653
+ for (let i = memory.length; i > position; --i) {
3649
3654
  this.count -= +memory.pop();
3650
3655
  }
3651
- //console.log('resize', position);
3656
+ //console.log('resize', position + 1);
3652
3657
  }
3653
3658
 
3654
3659
  clear() {
@@ -5874,7 +5879,7 @@ exports.autolink = (0, combinator_1.lazy)(() => (0, combinator_1.validate)(/^(?:
5874
5879
  // Escape unmatched hashtag-like strings.
5875
5880
  (0, source_1.str)(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])*/u.source.replace('emoji', hashtag_1.emoji), 'u')),
5876
5881
  // Escape invalid leading characters.
5877
- (0, source_1.str)(/^[0-9\p{Sc}](?=>)/u), anchor_1.anchor])), ns => ns.length === 1 ? ns : [(0, util_1.stringify)(ns)])])))));
5882
+ (0, source_1.str)(/^[0-9a-z](?=>)/iu), anchor_1.anchor])), ns => ns.length === 1 ? ns : [(0, util_1.stringify)(ns)])])))));
5878
5883
 
5879
5884
  /***/ }),
5880
5885
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.280.3",
3
+ "version": "0.280.4",
4
4
  "description": "Secure markdown renderer working on browsers for user input data.",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/falsandtru/securemark",
@@ -1,5 +1,8 @@
1
1
  import { Parser, Ctx, Context, check } from '../../data/parser';
2
+ import { max } from 'spica/alias';
2
3
 
4
+ // 設計上キャッシュが汚染されるが運用で回避可能
5
+ // 変換の前または後のみキャッシュされるなら問題ない
3
6
  export function convert<P extends Parser<unknown>>(conv: (source: string, context: Context<P>) => string, parser: P, empty?: boolean): P;
4
7
  export function convert<T>(conv: (source: string, context: Ctx) => string, parser: Parser<T>, empty = false): Parser<T> {
5
8
  assert(parser);
@@ -7,11 +10,13 @@ export function convert<T>(conv: (source: string, context: Ctx) => string, parse
7
10
  if (source === '') return;
8
11
  const src = conv(source, context);
9
12
  if (src === '') return empty ? [[], ''] : undefined;
13
+ const offset = max(source.length - src.length, 0);
14
+ assert(offset >= 0);
10
15
  context.offset ??= 0;
11
- context.offset += source.length - src.length;
16
+ context.offset += offset;
12
17
  const result = parser({ source: src, context });
13
18
  assert(check(src, result));
14
- context.offset -= source.length - src.length;
19
+ context.offset -= offset;
15
20
  return result;
16
21
  };
17
22
  }
@@ -20,10 +20,12 @@ export function indent<T>(opener: RegExp | Parser<T>, parser?: Parser<T> | boole
20
20
  ([indent]) => indent.length * 2 + +(indent[0] === ' '), {})), separation),
21
21
  (lines, rest, context) => {
22
22
  assert(parser = parser as Parser<T>);
23
+ const offset = rest.length;
24
+ assert(offset >= 0);
23
25
  context.offset ??= 0;
24
- context.offset += rest.length;
26
+ context.offset += offset;
25
27
  const result = parser({ source: trimBlockEnd(lines.join('')), context });
26
- context.offset -= rest.length;
28
+ context.offset -= offset;
27
29
  return result && exec(result) === ''
28
30
  ? [eval(result), rest]
29
31
  : undefined;
@@ -12,11 +12,13 @@ export function focus<T>(scope: string | RegExp, parser: Parser<T>): Parser<T> {
12
12
  const src = match(source);
13
13
  assert(source.startsWith(src));
14
14
  if (src === '') return;
15
+ const offset = source.length - src.length;
16
+ assert(offset >= 0);
15
17
  context.offset ??= 0;
16
- context.offset += source.length - src.length;
18
+ context.offset += offset;
17
19
  const result = parser({ source: src, context });
18
20
  assert(check(src, result));
19
- context.offset -= source.length - src.length;
21
+ context.offset -= offset;
20
22
  if (result === undefined) return;
21
23
  assert(exec(result).length < src.length);
22
24
  return exec(result).length < src.length
@@ -41,11 +43,13 @@ export function rewrite<T>(scope: Parser<unknown>, parser: Parser<T>): Parser<T>
41
43
  const src = source.slice(0, source.length - exec(res1).length);
42
44
  assert(src !== '');
43
45
  assert(source.startsWith(src));
46
+ const offset = source.length - src.length;
47
+ assert(offset >= 0);
44
48
  context.offset ??= 0;
45
- context.offset += source.length - src.length;
49
+ context.offset += offset;
46
50
  const res2 = parser({ source: src, context });
47
51
  assert(check(src, res2));
48
- context.offset -= source.length - src.length;
52
+ context.offset -= offset;
49
53
  if (res2 === undefined) return;
50
54
  assert(exec(res2) === '');
51
55
  return exec(res2).length < src.length
@@ -38,10 +38,10 @@ export class Memo {
38
38
  }
39
39
  public resize(position: number): void {
40
40
  const memory = this.memory;
41
- for (let len = memory.length, i = position; i < len; ++i) {
41
+ for (let i = memory.length; i > position; --i) {
42
42
  this.count -= +memory.pop()!;
43
43
  }
44
- //console.log('resize', position);
44
+ //console.log('resize', position + 1);
45
45
  }
46
46
  public clear(): void {
47
47
  this.memory = [];
@@ -33,7 +33,7 @@ export const autolink: AutolinkParser = lazy(() =>
33
33
  // Escape unmatched hashtag-like strings.
34
34
  str(new RegExp(/^#+(?:[^\p{C}\p{S}\p{P}\s]|emoji|['_])*/u.source.replace('emoji', emoji), 'u')),
35
35
  // Escape invalid leading characters.
36
- str(/^[0-9\p{Sc}](?=>)/u),
36
+ str(/^[0-9a-z](?=>)/iu),
37
37
  anchor,
38
38
  ])),
39
39
  ns => ns.length === 1 ? ns : [stringify(ns)]),