securemark 0.295.6 → 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,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.295.7
4
+
5
+ - Refactoring.
6
+
3
7
  ## 0.295.6
4
8
 
5
9
  - Refactoring.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! securemark v0.295.6 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"));
@@ -8609,7 +8609,7 @@ exports.strs = strs;
8609
8609
  Object.defineProperty(exports, "__esModule", ({
8610
8610
  value: true
8611
8611
  }));
8612
- 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;
8613
8613
  const parser_1 = __webpack_require__(605);
8614
8614
  const combinator_1 = __webpack_require__(3484);
8615
8615
  const dom_1 = __webpack_require__(394);
@@ -8687,26 +8687,18 @@ function next(source, position, state, delimiter) {
8687
8687
  if (delimiter) {
8688
8688
  delimiter.lastIndex = position + 1;
8689
8689
  delimiter.test(source);
8690
- index = delimiter.lastIndex;
8690
+ index = delimiter.lastIndex || position;
8691
8691
  } else {
8692
8692
  index = seek(source, position, state);
8693
8693
  }
8694
- if (index === 0) return source.length;
8694
+ if (index === position || index === source.length) return source.length;
8695
8695
  const char = source[index];
8696
8696
  switch (char) {
8697
- case '$':
8698
- case '*':
8699
- case '+':
8700
- case '~':
8701
- case '=':
8702
- case '/':
8703
- index = backToWhitespace(source, position, index);
8704
- break;
8705
8697
  case '%':
8706
- index += index - 1 > position && source.startsWith(' %]', index - 1) ? -1 : 0;
8698
+ index += !delimiter && index - 1 > position ? -1 : 0;
8707
8699
  break;
8708
8700
  case '[':
8709
- index += index - 1 > position && source.startsWith(' [|', index - 1) ? -1 : 0;
8701
+ index += !delimiter && index - 1 > position && source.startsWith(' [|', index - 1) ? -1 : 0;
8710
8702
  break;
8711
8703
  case ':':
8712
8704
  index = source.startsWith('//', index + 1) ? backToUrlHead(source, position, index) : index;
@@ -8718,11 +8710,6 @@ function next(source, position, state, delimiter) {
8718
8710
  return index;
8719
8711
  }
8720
8712
  exports.next = next;
8721
- function backToWhitespace(source, position, index) {
8722
- const prev = index - 1;
8723
- return prev > position && /\s/.test(source[prev]) ? prev : index;
8724
- }
8725
- exports.backToWhitespace = backToWhitespace;
8726
8713
  function backToUrlHead(source, position, index) {
8727
8714
  const delim = index;
8728
8715
  let state = false;
@@ -8744,7 +8731,6 @@ function backToUrlHead(source, position, index) {
8744
8731
  }
8745
8732
  return index === position || source[index] !== 'h' ? delim : index;
8746
8733
  }
8747
- exports.backToUrlHead = backToUrlHead;
8748
8734
  function backToEmailHead(source, position, index) {
8749
8735
  const delim = index;
8750
8736
  let state = false;
@@ -8767,7 +8753,6 @@ function backToEmailHead(source, position, index) {
8767
8753
  }
8768
8754
  return index === position ? delim : index;
8769
8755
  }
8770
- exports.backToEmailHead = backToEmailHead;
8771
8756
  function isAlphanumeric(char) {
8772
8757
  if (char < '0' || '\x7F' < char) return false;
8773
8758
  return '0' <= char && char <= '9' || 'A' <= char && char <= 'Z' || 'a' <= char && char <= 'z';
@@ -8849,7 +8834,7 @@ function seek(source, position, state) {
8849
8834
  if (source[i + 1] === fst && source[i + 2] === fst) return i;
8850
8835
  continue;
8851
8836
  case '%':
8852
- if (source[i + 1] === ']') return i;
8837
+ if (source[i + 1] === ']' && isWhitespace(source[i - 1], true)) return i;
8853
8838
  continue;
8854
8839
  case ':':
8855
8840
  if (source[i + 1] === '/' && source[i + 2] === '/') return i;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securemark",
3
- "version": "0.295.6",
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",
@@ -11,7 +11,7 @@ describe('Unit: parser/inline/emphasis', () => {
11
11
  it('invalid', () => {
12
12
  assert.deepStrictEqual(inspect(parser, input('*', new Context())), undefined);
13
13
  assert.deepStrictEqual(inspect(parser, input('*a', new Context())), [['*', 'a'], '']);
14
- assert.deepStrictEqual(inspect(parser, input('*a *', new Context())), [['*', 'a', ' ', '*'], '']);
14
+ assert.deepStrictEqual(inspect(parser, input('*a *', new Context())), [['*', 'a ', '*'], '']);
15
15
  assert.deepStrictEqual(inspect(parser, input('*a *', new Context())), [['*', 'a', ' ', '*'], '']);
16
16
  assert.deepStrictEqual(inspect(parser, input('*a\n*', new Context())), [['*', 'a', '<br>', '*'], '']);
17
17
  assert.deepStrictEqual(inspect(parser, input('*a\\ *', new Context())), [['*', 'a', ' ', '*'], '']);
@@ -11,7 +11,7 @@ describe('Unit: parser/inline/emstrong', () => {
11
11
  it('invalid', () => {
12
12
  assert.deepStrictEqual(inspect(parser, input('***', new Context())), undefined);
13
13
  assert.deepStrictEqual(inspect(parser, input('***a', new Context())), [['***a'], '']);
14
- assert.deepStrictEqual(inspect(parser, input('***a ***', new Context())), [['***a', ' ', '***'], '']);
14
+ assert.deepStrictEqual(inspect(parser, input('***a ***', new Context())), [['***a ', '***'], '']);
15
15
  assert.deepStrictEqual(inspect(parser, input('***a ***', new Context())), [['***a', ' ', '***'], '']);
16
16
  assert.deepStrictEqual(inspect(parser, input('***a\n***', new Context())), [['***a', '<br>', '***'], '']);
17
17
  assert.deepStrictEqual(inspect(parser, input('***a\\ ***', new Context())), [['***a', ' ', '***'], '']);
@@ -66,7 +66,7 @@ describe('Unit: parser/inline/emstrong', () => {
66
66
  assert.deepStrictEqual(inspect(parser, input('***a*\\ **b****', new Context())), [['<strong><em>a</em> <strong>b</strong></strong>'], '']);
67
67
  assert.deepStrictEqual(inspect(parser, input('***a*&Tab;**b****', new Context())), [['<strong><em>a</em>\t<strong>b</strong></strong>'], '']);
68
68
  assert.deepStrictEqual(inspect(parser, input('***a*<wbr>**b****', new Context())), [['<strong><em>a</em><wbr><strong>b</strong></strong>'], '']);
69
- assert.deepStrictEqual(inspect(parser, input('***a*b **', new Context())), [['**', '<em>a</em>', 'b', ' ', '**'], '']);
69
+ assert.deepStrictEqual(inspect(parser, input('***a*b **', new Context())), [['**', '<em>a</em>', 'b ', '**'], '']);
70
70
  assert.deepStrictEqual(inspect(parser, input('***a*b\\ **', new Context())), [['**', '<em>a</em>', 'b', ' ', '**'], '']);
71
71
  assert.deepStrictEqual(inspect(parser, input('***a**b*', new Context())), [['<em><strong>a</strong>b</em>'], '']);
72
72
  assert.deepStrictEqual(inspect(parser, input('***a**b*c', new Context())), [['<em><strong>a</strong>b</em>'], 'c']);
@@ -77,7 +77,7 @@ describe('Unit: parser/inline/emstrong', () => {
77
77
  assert.deepStrictEqual(inspect(parser, input('***a**\\ *b**', new Context())), [['<em><strong>a</strong> <em>b</em></em>'], '']);
78
78
  assert.deepStrictEqual(inspect(parser, input('***a**&Tab;*b**', new Context())), [['<em><strong>a</strong>\t<em>b</em></em>'], '']);
79
79
  assert.deepStrictEqual(inspect(parser, input('***a**<wbr>*b**', new Context())), [['<em><strong>a</strong><wbr><em>b</em></em>'], '']);
80
- assert.deepStrictEqual(inspect(parser, input('***a**b *', new Context())), [['*', '<strong>a</strong>', 'b', ' ', '*'], '']);
80
+ assert.deepStrictEqual(inspect(parser, input('***a**b *', new Context())), [['*', '<strong>a</strong>', 'b ', '*'], '']);
81
81
  assert.deepStrictEqual(inspect(parser, input('***a**b\\ *', new Context())), [['*', '<strong>a</strong>', 'b', ' ', '*'], '']);
82
82
  assert.deepStrictEqual(inspect(parser, input('***a*', new Context())), [['**', '<em>a</em>'], '']);
83
83
  assert.deepStrictEqual(inspect(parser, input('***a**', new Context())), [['*', '<strong>a</strong>'], '']);
@@ -109,11 +109,11 @@ describe('Unit: parser/inline/emstrong', () => {
109
109
  assert.deepStrictEqual(inspect(parser, input('******a******', new Context())), [['<em><strong><em><strong>a</strong></em></strong></em>'], '']);
110
110
  assert.deepStrictEqual(inspect(parser, input('******a******b', new Context())), [['<em><strong><em><strong>a</strong></em></strong></em>'], 'b']);
111
111
  assert.deepStrictEqual(inspect(parser, input('******a*b', new Context())), [['*****', '<em>a</em>', 'b'], '']);
112
- assert.deepStrictEqual(inspect(parser, input('******a*b *', new Context())), [['*****', '<em>a</em>', 'b', ' ', '*'], '']);
113
- assert.deepStrictEqual(inspect(parser, input('******a*b **', new Context())), [['*****', '<em>a</em>', 'b', ' ', '**'], '']);
114
- assert.deepStrictEqual(inspect(parser, input('******a*b ***', new Context())), [['*****', '<em>a</em>', 'b', ' ', '***'], '']);
115
- assert.deepStrictEqual(inspect(parser, input('******a*b ****', new Context())), [['*****', '<em>a</em>', 'b', ' ', '****'], '']);
116
- assert.deepStrictEqual(inspect(parser, input('******a*b *****', new Context())), [['*****', '<em>a</em>', 'b', ' ', '*****'], '']);
112
+ assert.deepStrictEqual(inspect(parser, input('******a*b *', new Context())), [['*****', '<em>a</em>', 'b ', '*'], '']);
113
+ assert.deepStrictEqual(inspect(parser, input('******a*b **', new Context())), [['*****', '<em>a</em>', 'b ', '**'], '']);
114
+ assert.deepStrictEqual(inspect(parser, input('******a*b ***', new Context())), [['*****', '<em>a</em>', 'b ', '***'], '']);
115
+ assert.deepStrictEqual(inspect(parser, input('******a*b ****', new Context())), [['*****', '<em>a</em>', 'b ', '****'], '']);
116
+ assert.deepStrictEqual(inspect(parser, input('******a*b *****', new Context())), [['*****', '<em>a</em>', 'b ', '*****'], '']);
117
117
  });
118
118
 
119
119
  });
@@ -11,7 +11,7 @@ describe('Unit: parser/inline/italic', () => {
11
11
  it('invalid', () => {
12
12
  assert.deepStrictEqual(inspect(parser, input('///', new Context())), undefined);
13
13
  assert.deepStrictEqual(inspect(parser, input('///a', new Context())), [['///', 'a'], '']);
14
- assert.deepStrictEqual(inspect(parser, input('///a ///', new Context())), [['///', 'a', ' ', '///'], '']);
14
+ assert.deepStrictEqual(inspect(parser, input('///a ///', new Context())), [['///', 'a ', '///'], '']);
15
15
  assert.deepStrictEqual(inspect(parser, input('///a ///', new Context())), [['///', 'a', ' ', '///'], '']);
16
16
  assert.deepStrictEqual(inspect(parser, input('///a\n///', new Context())), [['///', 'a', '<br>', '///'], '']);
17
17
  assert.deepStrictEqual(inspect(parser, input('///a\\ ///', new Context())), [['///', 'a', ' ', '///'], '']);
@@ -14,7 +14,7 @@ describe('Unit: parser/inline/mark', () => {
14
14
  assert.deepStrictEqual(inspect(parser, input('==', new Context())), undefined);
15
15
  assert.deepStrictEqual(inspect(parser, input('==a', new Context())), [['==', 'a'], '']);
16
16
  assert.deepStrictEqual(inspect(parser, input('==a=', new Context())), [['==', 'a='], '']);
17
- assert.deepStrictEqual(inspect(parser, input('==a ==', new Context())), [['==', 'a', ' ', '=='], '']);
17
+ assert.deepStrictEqual(inspect(parser, input('==a ==', new Context())), [['==', 'a ', '=='], '']);
18
18
  assert.deepStrictEqual(inspect(parser, input('==a ==', new Context())), [['==', 'a', ' ', '=='], '']);
19
19
  assert.deepStrictEqual(inspect(parser, input('==a\n==', new Context())), [['==', 'a', '<br>', '=='], '']);
20
20
  assert.deepStrictEqual(inspect(parser, input('==a\\ ==', new Context())), [['==', 'a', ' ', '=='], '']);
@@ -109,6 +109,7 @@ describe('Unit: parser/inline/math', () => {
109
109
  assert.deepStrictEqual(inspect(parser, input('$a$[A](a)', new Context())), [['<span class="math" translate="no" data-src="$a$">$a$</span>'], '[A](a)']);
110
110
  assert.deepStrictEqual(inspect(parser, input('$A$', new Context())), [['<span class="math" translate="no" data-src="$A$">$A$</span>'], '']);
111
111
  assert.deepStrictEqual(inspect(parser, input('$-a$', new Context())), [['<span class="math" translate="no" data-src="$-a$">$-a$</span>'], '']);
112
+ assert.deepStrictEqual(inspect(parser, input('$\\ $', new Context())), [['<span class="math" translate="no" data-src="$\\ $">$\\ $</span>'], '']);
112
113
  assert.deepStrictEqual(inspect(parser, input('$\\$$', new Context())), [['<span class="math" translate="no" data-src="$\\$$">$\\$$</span>'], '']);
113
114
  assert.deepStrictEqual(inspect(parser, input('$\\Pi$', new Context())), [['<span class="math" translate="no" data-src="$\\Pi$">$\\Pi$</span>'], '']);
114
115
  assert.deepStrictEqual(inspect(parser, input('$\\ 0$', new Context())), [['<span class="math" translate="no" data-src="$\\ 0$">$\\ 0$</span>'], '']);
@@ -30,8 +30,8 @@ describe('Unit: parser/inline/remark', () => {
30
30
  assert.deepStrictEqual(inspect(parser, input('[%% a [% b', new Context())), [['<span class="invalid">[%%</span>'], ' a [% b']);
31
31
  assert.deepStrictEqual(inspect(parser, input('[%\\ a %]', new Context())), undefined);
32
32
  assert.deepStrictEqual(inspect(parser, input('[% a\\ %]', new Context())), [['[%', ' a', ' ', '%', ']'], '']);
33
- assert.deepStrictEqual(inspect(parser, input('[% a%]', new Context())), [['[%', ' a', '%', ']'], '']);
34
- assert.deepStrictEqual(inspect(parser, input('[% a %%]', new Context())), [['[%', ' a %', '%', ']'], '']);
33
+ assert.deepStrictEqual(inspect(parser, input('[% a%]', new Context())), [['[%', ' a%', ']'], '']);
34
+ assert.deepStrictEqual(inspect(parser, input('[% a %%]', new Context())), [['[%', ' a %%', ']'], '']);
35
35
  assert.deepStrictEqual(inspect(parser, input('[% [%% %]', new Context())), [['<span class="remark"><input type="checkbox"><span>[% <span class="invalid">[%%</span> %]</span></span>'], '']);
36
36
  assert.deepStrictEqual(inspect(parser, input('[%% [% %%]', new Context())), [['<span class="invalid">[%%</span>'], ' [% %%]']);
37
37
  assert.deepStrictEqual(inspect(parser, input('[%% a %]', new Context())), [['<span class="invalid">[%%</span>'], ' a %]']);
@@ -11,7 +11,7 @@ describe('Unit: parser/inline/strong', () => {
11
11
  it('invalid', () => {
12
12
  assert.deepStrictEqual(inspect(parser, input('**', new Context())), undefined);
13
13
  assert.deepStrictEqual(inspect(parser, input('**a', new Context())), [['**', 'a'], '']);
14
- assert.deepStrictEqual(inspect(parser, input('**a **', new Context())), [['**', 'a', ' ', '**'], '']);
14
+ assert.deepStrictEqual(inspect(parser, input('**a **', new Context())), [['**', 'a ', '**'], '']);
15
15
  assert.deepStrictEqual(inspect(parser, input('**a **', new Context())), [['**', 'a', ' ', '**'], '']);
16
16
  assert.deepStrictEqual(inspect(parser, input('**a\n**', new Context())), [['**', 'a', '<br>', '**'], '']);
17
17
  assert.deepStrictEqual(inspect(parser, input('**a\\ **', new Context())), [['**', 'a', ' ', '**'], '']);
@@ -40,7 +40,7 @@ describe('Unit: parser/inline', () => {
40
40
  assert.deepStrictEqual(inspect(parser, input('*a***b****', new Context())), [['<em>a</em>', '<strong>b</strong>', '**'], '']);
41
41
  assert.deepStrictEqual(inspect(parser, input('*a***b****c', new Context())), [['<em>a</em>', '<strong>b</strong>', '**', 'c'], '']);
42
42
  assert.deepStrictEqual(inspect(parser, input('*a *b**', new Context())), [['<em>a <em>b</em></em>'], '']);
43
- assert.deepStrictEqual(inspect(parser, input('*a *b**c', new Context())), [['*', 'a', ' ', '*', 'b', '**', 'c'], '']);
43
+ assert.deepStrictEqual(inspect(parser, input('*a *b**c', new Context())), [['*', 'a ', '*', 'b', '**', 'c'], '']);
44
44
  assert.deepStrictEqual(inspect(parser, input('*a **b***', new Context())), [['<em>a <strong>b</strong></em>'], '']);
45
45
  assert.deepStrictEqual(inspect(parser, input('*a **b***c', new Context())), [['<em>a <strong>b</strong></em>', 'c'], '']);
46
46
  assert.deepStrictEqual(inspect(parser, input('*a ***b****', new Context())), [['<em>a <em><strong>b</strong></em></em>'], '']);
@@ -101,8 +101,8 @@ describe('Unit: parser/inline', () => {
101
101
  assert.deepStrictEqual(inspect(parser, input('[$1]', new Context())), [['[', '$1', ']'], '']);
102
102
  assert.deepStrictEqual(inspect(parser, input('[$1-2]', new Context())), [['[', '$1-2', ']'], '']);
103
103
  assert.deepStrictEqual(inspect(parser, input('[$-1][$-2]', new Context())), [['<a class="label" data-label="$-1">$-1</a>', '<a class="label" data-label="$-2">$-2</a>'], '']);
104
- assert.deepStrictEqual(inspect(parser, input('$-1, $-2', new Context())), [['<a class="label" data-label="$-1">$-1</a>', ',', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
105
- assert.deepStrictEqual(inspect(parser, input('$-1 and $-2', new Context())), [['<a class="label" data-label="$-1">$-1</a>', ' and', ' ', '<a class="label" data-label="$-2">$-2</a>'], '']);
104
+ assert.deepStrictEqual(inspect(parser, input('$-1, $-2', new Context())), [['<a class="label" data-label="$-1">$-1</a>', ', ', '<a class="label" data-label="$-2">$-2</a>'], '']);
105
+ assert.deepStrictEqual(inspect(parser, input('$-1 and $-2', new Context())), [['<a class="label" data-label="$-1">$-1</a>', ' and ', '<a class="label" data-label="$-2">$-2</a>'], '']);
106
106
  assert.deepStrictEqual(inspect(parser, input('$$-1', new Context())), [['$', '<a class="label" data-label="$-1">$-1</a>'], '']);
107
107
  assert.deepStrictEqual(inspect(parser, input('[[#a]]', new Context())), [['<sup class="reference"><span><a class="hashtag" href="/hashtags/a">#a</a></span></sup>'], '']);
108
108
  assert.deepStrictEqual(inspect(parser, input('[[$-1]]', new Context())), [['<sup class="reference"><span><a class="label" data-label="$-1">$-1</a></span></sup>'], '']);
@@ -88,30 +88,23 @@ export function next(source: string, position: number, state: number, delimiter?
88
88
  if (delimiter) {
89
89
  delimiter.lastIndex = position + 1;
90
90
  delimiter.test(source);
91
- index = delimiter.lastIndex;
91
+ index = delimiter.lastIndex || position;
92
92
  }
93
93
  else {
94
94
  index = seek(source, position, state);
95
95
  }
96
- if (index === 0) return source.length;
96
+ if (index === position || index === source.length) return source.length;
97
97
  assert(index > position);
98
98
  const char = source[index];
99
99
  switch (char) {
100
- case '$':
101
- case '*':
102
- case '+':
103
- case '~':
104
- case '=':
105
- case '/':
106
- index = backToWhitespace(source, position, index);
107
- break;
108
100
  case '%':
109
- index += index - 1 > position && source.startsWith(' %]', index - 1)
101
+ assert(source.startsWith('%]', index) && isWhitespace(source[index - 1], true) || delimiter);
102
+ index += !delimiter && index - 1 > position
110
103
  ? -1
111
104
  : 0;
112
105
  break;
113
106
  case '[':
114
- index += index - 1 > position && source.startsWith(' [|', index - 1)
107
+ index += !delimiter && index - 1 > position && source.startsWith(' [|', index - 1)
115
108
  ? -1
116
109
  : 0;
117
110
  break;
@@ -129,13 +122,7 @@ export function next(source: string, position: number, state: number, delimiter?
129
122
  assert(index > position);
130
123
  return index;
131
124
  }
132
- export function backToWhitespace(source: string, position: number, index: number): number {
133
- const prev = index - 1;
134
- return prev > position && /\s/.test(source[prev])
135
- ? prev
136
- : index;
137
- }
138
- export function backToUrlHead(source: string, position: number, index: number): number {
125
+ function backToUrlHead(source: string, position: number, index: number): number {
139
126
  const delim = index;
140
127
  let state = false;
141
128
  for (let i = index - 1; i >= position; --i) {
@@ -158,7 +145,7 @@ export function backToUrlHead(source: string, position: number, index: number):
158
145
  ? delim
159
146
  : index;
160
147
  }
161
- export function backToEmailHead(source: string, position: number, index: number): number {
148
+ function backToEmailHead(source: string, position: number, index: number): number {
162
149
  const delim = index;
163
150
  let state = false;
164
151
  for (let i = index - 1; i >= position; --i) {
@@ -267,7 +254,7 @@ function seek(source: string, position: number, state: number): number {
267
254
  if (source[i + 1] === fst && source[i + 2] === fst) return i;
268
255
  continue;
269
256
  case '%':
270
- if (source[i + 1] === ']') return i;
257
+ if (source[i + 1] === ']' && isWhitespace(source[i - 1], true)) return i;
271
258
  continue;
272
259
  case ':':
273
260
  if (source[i + 1] === '/' && source[i + 2] === '/') return i;