securemark 0.295.6 → 0.295.8

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.8
4
+
5
+ - Refactoring.
6
+
7
+ ## 0.295.7
8
+
9
+ - Refactoring.
10
+
3
11
  ## 0.295.6
4
12
 
5
13
  - 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.8 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"));
@@ -7559,7 +7559,7 @@ const source_1 = __webpack_require__(8745);
7559
7559
  const util_1 = __webpack_require__(4992);
7560
7560
  const dom_1 = __webpack_require__(394);
7561
7561
  const forbiddenCommand = /\\(?:begin|tiny|huge|large)(?![a-z])|:\/\//i;
7562
- exports.math = (0, combinator_1.lazy)(() => (0, combinator_1.rewrite)((0, combinator_1.union)([(0, combinator_1.surround)(/\$(?={)/y, (0, combinator_1.precedence)(4, bracket), '$', false, [3 | 16 /* Backtrack.escapable */]), (0, combinator_1.surround)(/\$(?![\s{}])/y, (0, combinator_1.precedence)(2, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(source_1.escsource, /\s?\$|[`"{}\n]/y), (0, combinator_1.precedence)(4, bracket)]))), /\$(?![-0-9A-Za-z])/y, false, [3 | 16 /* Backtrack.escapable */])]), ({
7562
+ exports.math = (0, combinator_1.lazy)(() => (0, combinator_1.rewrite)((0, combinator_1.union)([(0, combinator_1.surround)(/\$(?={)/y, (0, combinator_1.precedence)(4, bracket), '$', false, [3 | 16 /* Backtrack.escapable */]), (0, combinator_1.surround)(/\$(?![\s{}])/y, (0, combinator_1.precedence)(2, (0, combinator_1.some)((0, combinator_1.union)([(0, combinator_1.some)(source_1.escsource, /\$|[`"{}\n]/y), (0, combinator_1.precedence)(4, bracket)]))), /(?<!\s)\$(?![-0-9A-Za-z])/y, false, [3 | 16 /* Backtrack.escapable */])]), ({
7563
7563
  context: {
7564
7564
  source,
7565
7565
  caches: {
@@ -8609,11 +8609,10 @@ 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);
8616
- //const delimiter = /(?=[\\!@#$&"`\[\](){}<>()[]{}*%|\r\n]|([+~=])\1|\/{3}|\s(?:\\?(?:$|\s)|[$%])|:\/\/)/g;
8617
8616
  exports.nonWhitespace = /[^ \t ]/g;
8618
8617
  const text = input => {
8619
8618
  const {
@@ -8687,26 +8686,18 @@ function next(source, position, state, delimiter) {
8687
8686
  if (delimiter) {
8688
8687
  delimiter.lastIndex = position + 1;
8689
8688
  delimiter.test(source);
8690
- index = delimiter.lastIndex;
8689
+ index = delimiter.lastIndex || position;
8691
8690
  } else {
8692
8691
  index = seek(source, position, state);
8693
8692
  }
8694
- if (index === 0) return source.length;
8693
+ if (index === position || index === source.length) return source.length;
8695
8694
  const char = source[index];
8696
8695
  switch (char) {
8697
- case '$':
8698
- case '*':
8699
- case '+':
8700
- case '~':
8701
- case '=':
8702
- case '/':
8703
- index = backToWhitespace(source, position, index);
8704
- break;
8705
8696
  case '%':
8706
- index += index - 1 > position && source.startsWith(' %]', index - 1) ? -1 : 0;
8697
+ index += !delimiter && index - 1 > position ? -1 : 0;
8707
8698
  break;
8708
8699
  case '[':
8709
- index += index - 1 > position && source.startsWith(' [|', index - 1) ? -1 : 0;
8700
+ index += !delimiter && index - 1 > position && source.startsWith(' [|', index - 1) ? -1 : 0;
8710
8701
  break;
8711
8702
  case ':':
8712
8703
  index = source.startsWith('//', index + 1) ? backToUrlHead(source, position, index) : index;
@@ -8718,11 +8709,6 @@ function next(source, position, state, delimiter) {
8718
8709
  return index;
8719
8710
  }
8720
8711
  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
8712
  function backToUrlHead(source, position, index) {
8727
8713
  const delim = index;
8728
8714
  let state = false;
@@ -8744,7 +8730,6 @@ function backToUrlHead(source, position, index) {
8744
8730
  }
8745
8731
  return index === position || source[index] !== 'h' ? delim : index;
8746
8732
  }
8747
- exports.backToUrlHead = backToUrlHead;
8748
8733
  function backToEmailHead(source, position, index) {
8749
8734
  const delim = index;
8750
8735
  let state = false;
@@ -8767,50 +8752,14 @@ function backToEmailHead(source, position, index) {
8767
8752
  }
8768
8753
  return index === position ? delim : index;
8769
8754
  }
8770
- exports.backToEmailHead = backToEmailHead;
8771
8755
  function isAlphanumeric(char) {
8772
8756
  if (char < '0' || '\x7F' < char) return false;
8773
8757
  return '0' <= char && char <= '9' || 'A' <= char && char <= 'Z' || 'a' <= char && char <= 'z';
8774
8758
  }
8775
8759
  exports.isAlphanumeric = isAlphanumeric;
8776
- //const dict = new class {
8777
- // constructor() {
8778
- // [
8779
- // '\\',
8780
- // '!',
8781
- // '@',
8782
- // '#',
8783
- // '$',
8784
- // '&',
8785
- // '"',
8786
- // '`',
8787
- // '[',
8788
- // ']',
8789
- // '(',
8790
- // ')',
8791
- // '{',
8792
- // '}',
8793
- // '<',
8794
- // '>',
8795
- // '(',
8796
- // ')',
8797
- // '[',
8798
- // ']',
8799
- // '{',
8800
- // '}',
8801
- // '*',
8802
- // '%',
8803
- // '|',
8804
- // '\r',
8805
- // '\n',
8806
- // ].forEach(c =>
8807
- // this[c.charCodeAt(0)] = undefined);
8808
- // }
8809
- //};
8810
8760
  function seek(source, position, state) {
8811
8761
  for (let i = position + 1; i < source.length; ++i) {
8812
8762
  const fst = source[i];
8813
- //if (fst.charCodeAt(0) in dict) return i;
8814
8763
  switch (fst) {
8815
8764
  case '\\':
8816
8765
  case '!':
@@ -8849,7 +8798,7 @@ function seek(source, position, state) {
8849
8798
  if (source[i + 1] === fst && source[i + 2] === fst) return i;
8850
8799
  continue;
8851
8800
  case '%':
8852
- if (source[i + 1] === ']') return i;
8801
+ if (source[i + 1] === ']' && isWhitespace(source[i - 1], true)) return i;
8853
8802
  continue;
8854
8803
  case ':':
8855
8804
  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.8",
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', ' ', '=='], '']);
@@ -14,6 +14,8 @@ describe('Unit: parser/inline/math', () => {
14
14
  assert.deepStrictEqual(inspect(parser, input('$$', new Context())), undefined);
15
15
  assert.deepStrictEqual(inspect(parser, input('$$$', new Context())), undefined);
16
16
  assert.deepStrictEqual(inspect(parser, input('$0 $', new Context())), undefined);
17
+ assert.deepStrictEqual(inspect(parser, input('$0\\ $', new Context())), undefined);
18
+ assert.deepStrictEqual(inspect(parser, input('$0\\\n$', new Context())), undefined);
17
19
  assert.deepStrictEqual(inspect(parser, input('$-0, $-1', new Context())), undefined);
18
20
  assert.deepStrictEqual(inspect(parser, input('$-0 and $-1', new Context())), undefined);
19
21
  assert.deepStrictEqual(inspect(parser, input('$-0と$-1', new Context())), undefined);
@@ -38,9 +40,13 @@ describe('Unit: parser/inline/math', () => {
38
40
  assert.deepStrictEqual(inspect(parser, input('$a$b', new Context())), undefined);
39
41
  assert.deepStrictEqual(inspect(parser, input('$a$b$', new Context())), undefined);
40
42
  assert.deepStrictEqual(inspect(parser, input('$ $', new Context())), undefined);
43
+ assert.deepStrictEqual(inspect(parser, input('$\\ $', new Context())), undefined);
41
44
  assert.deepStrictEqual(inspect(parser, input('$ a$', new Context())), undefined);
42
45
  assert.deepStrictEqual(inspect(parser, input('$ a $', new Context())), undefined);
43
46
  assert.deepStrictEqual(inspect(parser, input('$\n$', new Context())), undefined);
47
+ assert.deepStrictEqual(inspect(parser, input('$\\\n$', new Context())), undefined);
48
+ assert.deepStrictEqual(inspect(parser, input('$a\nb$', new Context())), undefined);
49
+ assert.deepStrictEqual(inspect(parser, input('$a\\\nb$', new Context())), undefined);
44
50
  assert.deepStrictEqual(inspect(parser, input('$a\\$\nb$', new Context())), undefined);
45
51
  assert.deepStrictEqual(inspect(parser, input('$a\\$\\\nb$', new Context())), undefined);
46
52
  assert.deepStrictEqual(inspect(parser, input('$`$', new Context())), undefined);
@@ -74,9 +80,12 @@ describe('Unit: parser/inline/math', () => {
74
80
  assert.deepStrictEqual(inspect(parser, input('${a}b$', new Context())), undefined);
75
81
  assert.deepStrictEqual(inspect(parser, input('${a}b{c}$', new Context())), undefined);
76
82
  assert.deepStrictEqual(inspect(parser, input('${a}{b}$', new Context())), undefined);
77
- assert.deepStrictEqual(inspect(parser, input('${$}$', new Context())), undefined);
78
83
  assert.deepStrictEqual(inspect(parser, input('${\\}$', new Context())), undefined);
79
84
  assert.deepStrictEqual(inspect(parser, input('${\n}$', new Context())), undefined);
85
+ assert.deepStrictEqual(inspect(parser, input('${\\\n}$', new Context())), undefined);
86
+ assert.deepStrictEqual(inspect(parser, input('${a\nb}$', new Context())), undefined);
87
+ assert.deepStrictEqual(inspect(parser, input('${a\\\nb}$', new Context())), undefined);
88
+ assert.deepStrictEqual(inspect(parser, input('${$}$', new Context())), undefined);
80
89
  assert.deepStrictEqual(inspect(parser, input('${a\\$\nb}$', new Context())), undefined);
81
90
  assert.deepStrictEqual(inspect(parser, input('${a\\$\\\nb}$', new Context())), undefined);
82
91
  assert.deepStrictEqual(inspect(parser, input('$\\begin$', new Context())), [['<span class="invalid" translate="no">$\\begin$</span>'], '']);
@@ -19,10 +19,10 @@ export const math: MathParser = lazy(() => rewrite(
19
19
  surround(
20
20
  /\$(?![\s{}])/y,
21
21
  precedence(2, some(union([
22
- some(escsource, /\s?\$|[`"{}\n]/y),
22
+ some(escsource, /\$|[`"{}\n]/y),
23
23
  precedence(4, bracket),
24
24
  ]))),
25
- /\$(?![-0-9A-Za-z])/y,
25
+ /(?<!\s)\$(?![-0-9A-Za-z])/y,
26
26
  false,
27
27
  [3 | Backtrack.escapable]),
28
28
  ]),
@@ -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>'], '']);
@@ -4,7 +4,6 @@ import { List, Node } from '../../combinator/data/parser';
4
4
  import { union, consume } from '../../combinator';
5
5
  import { html } from 'typed-dom/dom';
6
6
 
7
- //const delimiter = /(?=[\\!@#$&"`\[\](){}<>()[]{}*%|\r\n]|([+~=])\1|\/{3}|\s(?:\\?(?:$|\s)|[$%])|:\/\/)/g;
8
7
  export const nonWhitespace = /[^ \t ]/g;
9
8
 
10
9
  export const text: TextParser = input => {
@@ -88,30 +87,23 @@ export function next(source: string, position: number, state: number, delimiter?
88
87
  if (delimiter) {
89
88
  delimiter.lastIndex = position + 1;
90
89
  delimiter.test(source);
91
- index = delimiter.lastIndex;
90
+ index = delimiter.lastIndex || position;
92
91
  }
93
92
  else {
94
93
  index = seek(source, position, state);
95
94
  }
96
- if (index === 0) return source.length;
95
+ if (index === position || index === source.length) return source.length;
97
96
  assert(index > position);
98
97
  const char = source[index];
99
98
  switch (char) {
100
- case '$':
101
- case '*':
102
- case '+':
103
- case '~':
104
- case '=':
105
- case '/':
106
- index = backToWhitespace(source, position, index);
107
- break;
108
99
  case '%':
109
- index += index - 1 > position && source.startsWith(' %]', index - 1)
100
+ assert(source.startsWith('%]', index) && isWhitespace(source[index - 1], true) || delimiter);
101
+ index += !delimiter && index - 1 > position
110
102
  ? -1
111
103
  : 0;
112
104
  break;
113
105
  case '[':
114
- index += index - 1 > position && source.startsWith(' [|', index - 1)
106
+ index += !delimiter && index - 1 > position && source.startsWith(' [|', index - 1)
115
107
  ? -1
116
108
  : 0;
117
109
  break;
@@ -129,13 +121,7 @@ export function next(source: string, position: number, state: number, delimiter?
129
121
  assert(index > position);
130
122
  return index;
131
123
  }
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 {
124
+ function backToUrlHead(source: string, position: number, index: number): number {
139
125
  const delim = index;
140
126
  let state = false;
141
127
  for (let i = index - 1; i >= position; --i) {
@@ -158,7 +144,7 @@ export function backToUrlHead(source: string, position: number, index: number):
158
144
  ? delim
159
145
  : index;
160
146
  }
161
- export function backToEmailHead(source: string, position: number, index: number): number {
147
+ function backToEmailHead(source: string, position: number, index: number): number {
162
148
  const delim = index;
163
149
  let state = false;
164
150
  for (let i = index - 1; i >= position; --i) {
@@ -190,45 +176,9 @@ export function isAlphanumeric(char: string): boolean {
190
176
  || 'a' <= char && char <= 'z';
191
177
  }
192
178
 
193
- //const dict = new class {
194
- // constructor() {
195
- // [
196
- // '\\',
197
- // '!',
198
- // '@',
199
- // '#',
200
- // '$',
201
- // '&',
202
- // '"',
203
- // '`',
204
- // '[',
205
- // ']',
206
- // '(',
207
- // ')',
208
- // '{',
209
- // '}',
210
- // '<',
211
- // '>',
212
- // '(',
213
- // ')',
214
- // '[',
215
- // ']',
216
- // '{',
217
- // '}',
218
- // '*',
219
- // '%',
220
- // '|',
221
- // '\r',
222
- // '\n',
223
- // ].forEach(c =>
224
- // this[c.charCodeAt(0)] = undefined);
225
- // }
226
- //};
227
-
228
179
  function seek(source: string, position: number, state: number): number {
229
180
  for (let i = position + 1; i < source.length; ++i) {
230
181
  const fst = source[i];
231
- //if (fst.charCodeAt(0) in dict) return i;
232
182
  switch (fst) {
233
183
  case '\\':
234
184
  case '!':
@@ -267,7 +217,7 @@ function seek(source: string, position: number, state: number): number {
267
217
  if (source[i + 1] === fst && source[i + 2] === fst) return i;
268
218
  continue;
269
219
  case '%':
270
- if (source[i + 1] === ']') return i;
220
+ if (source[i + 1] === ']' && isWhitespace(source[i - 1], true)) return i;
271
221
  continue;
272
222
  case ':':
273
223
  if (source[i + 1] === '/' && source[i + 2] === '/') return i;