@yozora/tokenizer-emphasis 1.3.0 → 2.0.0-alpha.0

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/lib/cjs/index.js CHANGED
@@ -15,145 +15,151 @@ class EmphasisTokenizer extends coreTokenizer.BaseInlineTokenizer {
15
15
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
16
16
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_INLINE,
17
17
  });
18
- }
19
- _findDelimiter(startIndex, endIndex, api) {
20
- const nodePoints = api.getNodePoints();
21
- const blockStartIndex = api.getBlockStartIndex();
22
- const blockEndIndex = api.getBlockEndIndex();
23
- const isOpenerDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
24
- if (delimiterEndIndex === blockEndIndex)
25
- return false;
26
- if (delimiterEndIndex === endIndex)
27
- return true;
28
- const nextCodePosition = nodePoints[delimiterEndIndex];
29
- if (character.isUnicodeWhitespaceCharacter(nextCodePosition.codePoint))
30
- return false;
31
- if (!character.isPunctuationCharacter(nextCodePosition.codePoint))
32
- return true;
33
- if (delimiterStartIndex <= startIndex)
34
- return true;
35
- const prevCodePosition = nodePoints[delimiterStartIndex - 1];
36
- return (character.isUnicodeWhitespaceCharacter(prevCodePosition.codePoint) ||
37
- character.isPunctuationCharacter(prevCodePosition.codePoint));
38
- };
39
- const isCloserDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
40
- if (delimiterStartIndex === blockStartIndex)
41
- return false;
42
- if (delimiterStartIndex === startIndex)
43
- return true;
44
- const prevCodePosition = nodePoints[delimiterStartIndex - 1];
45
- if (character.isUnicodeWhitespaceCharacter(prevCodePosition.codePoint))
46
- return false;
47
- if (!character.isPunctuationCharacter(prevCodePosition.codePoint))
48
- return true;
49
- if (delimiterEndIndex >= endIndex)
50
- return true;
51
- const nextCodePosition = nodePoints[delimiterEndIndex];
52
- return (character.isUnicodeWhitespaceCharacter(nextCodePosition.codePoint) ||
53
- character.isPunctuationCharacter(nextCodePosition.codePoint));
54
- };
55
- for (let i = startIndex; i < endIndex; ++i) {
56
- const c = nodePoints[i].codePoint;
57
- switch (c) {
58
- case character.AsciiCodePoint.BACKSLASH:
59
- i += 1;
60
- break;
61
- case character.AsciiCodePoint.ASTERISK:
62
- case character.AsciiCodePoint.UNDERSCORE: {
63
- const _startIndex = i;
64
- i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
65
- const _endIndex = i + 1;
66
- const isLeftFlankingDelimiterRun = isOpenerDelimiter(_startIndex, _endIndex);
67
- const isRightFlankingDelimiterRun = isCloserDelimiter(_startIndex, _endIndex);
68
- let isOpener = isLeftFlankingDelimiterRun;
69
- let isCloser = isRightFlankingDelimiterRun;
70
- if (c === character.AsciiCodePoint.UNDERSCORE) {
71
- if (isLeftFlankingDelimiterRun && isRightFlankingDelimiterRun) {
72
- if (_startIndex > startIndex &&
73
- !character.isPunctuationCharacter(nodePoints[_startIndex - 1].codePoint)) {
74
- isOpener = false;
75
- }
76
- const nextCodePosition = nodePoints[_endIndex];
77
- if (!character.isPunctuationCharacter(nextCodePosition.codePoint)) {
78
- isCloser = false;
18
+ this.match = api => {
19
+ return {
20
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
21
+ isDelimiterPair,
22
+ processDelimiterPair,
23
+ };
24
+ function _findDelimiter(startIndex, endIndex) {
25
+ const nodePoints = api.getNodePoints();
26
+ const blockStartIndex = api.getBlockStartIndex();
27
+ const blockEndIndex = api.getBlockEndIndex();
28
+ const isOpenerDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
29
+ if (delimiterEndIndex === blockEndIndex)
30
+ return false;
31
+ if (delimiterEndIndex === endIndex)
32
+ return true;
33
+ const nextCodePosition = nodePoints[delimiterEndIndex];
34
+ if (character.isUnicodeWhitespaceCharacter(nextCodePosition.codePoint))
35
+ return false;
36
+ if (!character.isPunctuationCharacter(nextCodePosition.codePoint))
37
+ return true;
38
+ if (delimiterStartIndex <= startIndex)
39
+ return true;
40
+ const prevCodePosition = nodePoints[delimiterStartIndex - 1];
41
+ return (character.isUnicodeWhitespaceCharacter(prevCodePosition.codePoint) ||
42
+ character.isPunctuationCharacter(prevCodePosition.codePoint));
43
+ };
44
+ const isCloserDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
45
+ if (delimiterStartIndex === blockStartIndex)
46
+ return false;
47
+ if (delimiterStartIndex === startIndex)
48
+ return true;
49
+ const prevCodePosition = nodePoints[delimiterStartIndex - 1];
50
+ if (character.isUnicodeWhitespaceCharacter(prevCodePosition.codePoint))
51
+ return false;
52
+ if (!character.isPunctuationCharacter(prevCodePosition.codePoint))
53
+ return true;
54
+ if (delimiterEndIndex >= endIndex)
55
+ return true;
56
+ const nextCodePosition = nodePoints[delimiterEndIndex];
57
+ return (character.isUnicodeWhitespaceCharacter(nextCodePosition.codePoint) ||
58
+ character.isPunctuationCharacter(nextCodePosition.codePoint));
59
+ };
60
+ for (let i = startIndex; i < endIndex; ++i) {
61
+ const c = nodePoints[i].codePoint;
62
+ switch (c) {
63
+ case character.AsciiCodePoint.BACKSLASH:
64
+ i += 1;
65
+ break;
66
+ case character.AsciiCodePoint.ASTERISK:
67
+ case character.AsciiCodePoint.UNDERSCORE: {
68
+ const _startIndex = i;
69
+ i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
70
+ const _endIndex = i + 1;
71
+ const isLeftFlankingDelimiterRun = isOpenerDelimiter(_startIndex, _endIndex);
72
+ const isRightFlankingDelimiterRun = isCloserDelimiter(_startIndex, _endIndex);
73
+ let isOpener = isLeftFlankingDelimiterRun;
74
+ let isCloser = isRightFlankingDelimiterRun;
75
+ if (c === character.AsciiCodePoint.UNDERSCORE) {
76
+ if (isLeftFlankingDelimiterRun && isRightFlankingDelimiterRun) {
77
+ if (_startIndex > startIndex &&
78
+ !character.isPunctuationCharacter(nodePoints[_startIndex - 1].codePoint)) {
79
+ isOpener = false;
80
+ }
81
+ const nextCodePosition = nodePoints[_endIndex];
82
+ if (!character.isPunctuationCharacter(nextCodePosition.codePoint)) {
83
+ isCloser = false;
84
+ }
85
+ }
79
86
  }
87
+ if (!isOpener && !isCloser)
88
+ break;
89
+ const thickness = _endIndex - _startIndex;
90
+ return {
91
+ type: isOpener ? (isCloser ? 'both' : 'opener') : 'closer',
92
+ startIndex: _startIndex,
93
+ endIndex: _endIndex,
94
+ thickness,
95
+ originalThickness: thickness,
96
+ };
80
97
  }
81
98
  }
82
- if (!isOpener && !isCloser)
83
- break;
84
- const thickness = _endIndex - _startIndex;
85
- return {
86
- type: isOpener ? (isCloser ? 'both' : 'opener') : 'closer',
87
- startIndex: _startIndex,
88
- endIndex: _endIndex,
89
- thickness,
90
- originalThickness: thickness,
91
- };
92
99
  }
100
+ return null;
93
101
  }
94
- }
95
- return null;
96
- }
97
- isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
98
- const nodePoints = api.getNodePoints();
99
- if (nodePoints[openerDelimiter.startIndex].codePoint !==
100
- nodePoints[closerDelimiter.startIndex].codePoint ||
101
- ((openerDelimiter.type === 'both' || closerDelimiter.type === 'both') &&
102
- (openerDelimiter.originalThickness +
103
- closerDelimiter.originalThickness) %
104
- 3 ===
105
- 0 &&
106
- openerDelimiter.originalThickness % 3 !== 0)) {
107
- return { paired: false, opener: true, closer: true };
108
- }
109
- return { paired: true };
110
- }
111
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
112
- let thickness = 1;
113
- if (openerDelimiter.thickness > 1 && closerDelimiter.thickness > 1) {
114
- thickness = 2;
115
- }
116
- internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
117
- const token = {
118
- nodeType: thickness === 1 ? ast.EmphasisType : ast.StrongType,
119
- startIndex: openerDelimiter.endIndex - thickness,
120
- endIndex: closerDelimiter.startIndex + thickness,
121
- thickness,
122
- children: internalTokens,
123
- };
124
- const remainOpenerDelimiter = openerDelimiter.thickness > thickness
125
- ? {
126
- type: openerDelimiter.type,
127
- startIndex: openerDelimiter.startIndex,
128
- endIndex: openerDelimiter.endIndex - thickness,
129
- thickness: openerDelimiter.thickness - thickness,
130
- originalThickness: openerDelimiter.originalThickness,
102
+ function isDelimiterPair(openerDelimiter, closerDelimiter) {
103
+ const nodePoints = api.getNodePoints();
104
+ if (nodePoints[openerDelimiter.startIndex].codePoint !==
105
+ nodePoints[closerDelimiter.startIndex].codePoint ||
106
+ ((openerDelimiter.type === 'both' || closerDelimiter.type === 'both') &&
107
+ (openerDelimiter.originalThickness + closerDelimiter.originalThickness) % 3 === 0 &&
108
+ openerDelimiter.originalThickness % 3 !== 0)) {
109
+ return { paired: false, opener: true, closer: true };
110
+ }
111
+ return { paired: true };
131
112
  }
132
- : undefined;
133
- const remainCloserDelimiter = closerDelimiter.thickness > thickness
134
- ? {
135
- type: closerDelimiter.type,
136
- startIndex: closerDelimiter.startIndex + thickness,
137
- endIndex: closerDelimiter.endIndex,
138
- thickness: closerDelimiter.thickness - thickness,
139
- originalThickness: closerDelimiter.originalThickness,
113
+ function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
114
+ let thickness = 1;
115
+ if (openerDelimiter.thickness > 1 && closerDelimiter.thickness > 1) {
116
+ thickness = 2;
117
+ }
118
+ internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
119
+ const token = {
120
+ nodeType: thickness === 1 ? ast.EmphasisType : ast.StrongType,
121
+ startIndex: openerDelimiter.endIndex - thickness,
122
+ endIndex: closerDelimiter.startIndex + thickness,
123
+ thickness,
124
+ children: internalTokens,
125
+ };
126
+ const remainOpenerDelimiter = openerDelimiter.thickness > thickness
127
+ ? {
128
+ type: openerDelimiter.type,
129
+ startIndex: openerDelimiter.startIndex,
130
+ endIndex: openerDelimiter.endIndex - thickness,
131
+ thickness: openerDelimiter.thickness - thickness,
132
+ originalThickness: openerDelimiter.originalThickness,
133
+ }
134
+ : undefined;
135
+ const remainCloserDelimiter = closerDelimiter.thickness > thickness
136
+ ? {
137
+ type: closerDelimiter.type,
138
+ startIndex: closerDelimiter.startIndex + thickness,
139
+ endIndex: closerDelimiter.endIndex,
140
+ thickness: closerDelimiter.thickness - thickness,
141
+ originalThickness: closerDelimiter.originalThickness,
142
+ }
143
+ : undefined;
144
+ return {
145
+ tokens: [token],
146
+ remainOpenerDelimiter,
147
+ remainCloserDelimiter,
148
+ };
140
149
  }
141
- : undefined;
142
- return {
143
- tokens: [token],
144
- remainOpenerDelimiter,
145
- remainCloserDelimiter,
146
150
  };
147
- }
148
- parseInline(token, children) {
149
- const result = {
150
- type: token.nodeType,
151
- children,
152
- };
153
- return result;
151
+ this.parse = () => ({
152
+ parse: (token, children) => {
153
+ const result = {
154
+ type: token.nodeType,
155
+ children,
156
+ };
157
+ return result;
158
+ },
159
+ });
154
160
  }
155
161
  }
156
162
 
157
163
  exports.EmphasisTokenizer = EmphasisTokenizer;
158
164
  exports.EmphasisTokenizerName = uniqueName;
159
- exports['default'] = EmphasisTokenizer;
165
+ exports["default"] = EmphasisTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { EmphasisType, StrongType } from '@yozora/ast';
2
2
  import { AsciiCodePoint, isPunctuationCharacter, isUnicodeWhitespaceCharacter } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority, eatOptionalCharacters } from '@yozora/core-tokenizer';
3
+ import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter, eatOptionalCharacters } from '@yozora/core-tokenizer';
4
4
 
5
5
  const uniqueName = '@yozora/tokenizer-emphasis';
6
6
 
@@ -11,142 +11,148 @@ class EmphasisTokenizer extends BaseInlineTokenizer {
11
11
  name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
12
12
  priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_INLINE,
13
13
  });
14
- }
15
- _findDelimiter(startIndex, endIndex, api) {
16
- const nodePoints = api.getNodePoints();
17
- const blockStartIndex = api.getBlockStartIndex();
18
- const blockEndIndex = api.getBlockEndIndex();
19
- const isOpenerDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
20
- if (delimiterEndIndex === blockEndIndex)
21
- return false;
22
- if (delimiterEndIndex === endIndex)
23
- return true;
24
- const nextCodePosition = nodePoints[delimiterEndIndex];
25
- if (isUnicodeWhitespaceCharacter(nextCodePosition.codePoint))
26
- return false;
27
- if (!isPunctuationCharacter(nextCodePosition.codePoint))
28
- return true;
29
- if (delimiterStartIndex <= startIndex)
30
- return true;
31
- const prevCodePosition = nodePoints[delimiterStartIndex - 1];
32
- return (isUnicodeWhitespaceCharacter(prevCodePosition.codePoint) ||
33
- isPunctuationCharacter(prevCodePosition.codePoint));
34
- };
35
- const isCloserDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
36
- if (delimiterStartIndex === blockStartIndex)
37
- return false;
38
- if (delimiterStartIndex === startIndex)
39
- return true;
40
- const prevCodePosition = nodePoints[delimiterStartIndex - 1];
41
- if (isUnicodeWhitespaceCharacter(prevCodePosition.codePoint))
42
- return false;
43
- if (!isPunctuationCharacter(prevCodePosition.codePoint))
44
- return true;
45
- if (delimiterEndIndex >= endIndex)
46
- return true;
47
- const nextCodePosition = nodePoints[delimiterEndIndex];
48
- return (isUnicodeWhitespaceCharacter(nextCodePosition.codePoint) ||
49
- isPunctuationCharacter(nextCodePosition.codePoint));
50
- };
51
- for (let i = startIndex; i < endIndex; ++i) {
52
- const c = nodePoints[i].codePoint;
53
- switch (c) {
54
- case AsciiCodePoint.BACKSLASH:
55
- i += 1;
56
- break;
57
- case AsciiCodePoint.ASTERISK:
58
- case AsciiCodePoint.UNDERSCORE: {
59
- const _startIndex = i;
60
- i = eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
61
- const _endIndex = i + 1;
62
- const isLeftFlankingDelimiterRun = isOpenerDelimiter(_startIndex, _endIndex);
63
- const isRightFlankingDelimiterRun = isCloserDelimiter(_startIndex, _endIndex);
64
- let isOpener = isLeftFlankingDelimiterRun;
65
- let isCloser = isRightFlankingDelimiterRun;
66
- if (c === AsciiCodePoint.UNDERSCORE) {
67
- if (isLeftFlankingDelimiterRun && isRightFlankingDelimiterRun) {
68
- if (_startIndex > startIndex &&
69
- !isPunctuationCharacter(nodePoints[_startIndex - 1].codePoint)) {
70
- isOpener = false;
71
- }
72
- const nextCodePosition = nodePoints[_endIndex];
73
- if (!isPunctuationCharacter(nextCodePosition.codePoint)) {
74
- isCloser = false;
14
+ this.match = api => {
15
+ return {
16
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
17
+ isDelimiterPair,
18
+ processDelimiterPair,
19
+ };
20
+ function _findDelimiter(startIndex, endIndex) {
21
+ const nodePoints = api.getNodePoints();
22
+ const blockStartIndex = api.getBlockStartIndex();
23
+ const blockEndIndex = api.getBlockEndIndex();
24
+ const isOpenerDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
25
+ if (delimiterEndIndex === blockEndIndex)
26
+ return false;
27
+ if (delimiterEndIndex === endIndex)
28
+ return true;
29
+ const nextCodePosition = nodePoints[delimiterEndIndex];
30
+ if (isUnicodeWhitespaceCharacter(nextCodePosition.codePoint))
31
+ return false;
32
+ if (!isPunctuationCharacter(nextCodePosition.codePoint))
33
+ return true;
34
+ if (delimiterStartIndex <= startIndex)
35
+ return true;
36
+ const prevCodePosition = nodePoints[delimiterStartIndex - 1];
37
+ return (isUnicodeWhitespaceCharacter(prevCodePosition.codePoint) ||
38
+ isPunctuationCharacter(prevCodePosition.codePoint));
39
+ };
40
+ const isCloserDelimiter = (delimiterStartIndex, delimiterEndIndex) => {
41
+ if (delimiterStartIndex === blockStartIndex)
42
+ return false;
43
+ if (delimiterStartIndex === startIndex)
44
+ return true;
45
+ const prevCodePosition = nodePoints[delimiterStartIndex - 1];
46
+ if (isUnicodeWhitespaceCharacter(prevCodePosition.codePoint))
47
+ return false;
48
+ if (!isPunctuationCharacter(prevCodePosition.codePoint))
49
+ return true;
50
+ if (delimiterEndIndex >= endIndex)
51
+ return true;
52
+ const nextCodePosition = nodePoints[delimiterEndIndex];
53
+ return (isUnicodeWhitespaceCharacter(nextCodePosition.codePoint) ||
54
+ isPunctuationCharacter(nextCodePosition.codePoint));
55
+ };
56
+ for (let i = startIndex; i < endIndex; ++i) {
57
+ const c = nodePoints[i].codePoint;
58
+ switch (c) {
59
+ case AsciiCodePoint.BACKSLASH:
60
+ i += 1;
61
+ break;
62
+ case AsciiCodePoint.ASTERISK:
63
+ case AsciiCodePoint.UNDERSCORE: {
64
+ const _startIndex = i;
65
+ i = eatOptionalCharacters(nodePoints, i + 1, endIndex, c) - 1;
66
+ const _endIndex = i + 1;
67
+ const isLeftFlankingDelimiterRun = isOpenerDelimiter(_startIndex, _endIndex);
68
+ const isRightFlankingDelimiterRun = isCloserDelimiter(_startIndex, _endIndex);
69
+ let isOpener = isLeftFlankingDelimiterRun;
70
+ let isCloser = isRightFlankingDelimiterRun;
71
+ if (c === AsciiCodePoint.UNDERSCORE) {
72
+ if (isLeftFlankingDelimiterRun && isRightFlankingDelimiterRun) {
73
+ if (_startIndex > startIndex &&
74
+ !isPunctuationCharacter(nodePoints[_startIndex - 1].codePoint)) {
75
+ isOpener = false;
76
+ }
77
+ const nextCodePosition = nodePoints[_endIndex];
78
+ if (!isPunctuationCharacter(nextCodePosition.codePoint)) {
79
+ isCloser = false;
80
+ }
81
+ }
75
82
  }
83
+ if (!isOpener && !isCloser)
84
+ break;
85
+ const thickness = _endIndex - _startIndex;
86
+ return {
87
+ type: isOpener ? (isCloser ? 'both' : 'opener') : 'closer',
88
+ startIndex: _startIndex,
89
+ endIndex: _endIndex,
90
+ thickness,
91
+ originalThickness: thickness,
92
+ };
76
93
  }
77
94
  }
78
- if (!isOpener && !isCloser)
79
- break;
80
- const thickness = _endIndex - _startIndex;
81
- return {
82
- type: isOpener ? (isCloser ? 'both' : 'opener') : 'closer',
83
- startIndex: _startIndex,
84
- endIndex: _endIndex,
85
- thickness,
86
- originalThickness: thickness,
87
- };
88
95
  }
96
+ return null;
89
97
  }
90
- }
91
- return null;
92
- }
93
- isDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
94
- const nodePoints = api.getNodePoints();
95
- if (nodePoints[openerDelimiter.startIndex].codePoint !==
96
- nodePoints[closerDelimiter.startIndex].codePoint ||
97
- ((openerDelimiter.type === 'both' || closerDelimiter.type === 'both') &&
98
- (openerDelimiter.originalThickness +
99
- closerDelimiter.originalThickness) %
100
- 3 ===
101
- 0 &&
102
- openerDelimiter.originalThickness % 3 !== 0)) {
103
- return { paired: false, opener: true, closer: true };
104
- }
105
- return { paired: true };
106
- }
107
- processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens, api) {
108
- let thickness = 1;
109
- if (openerDelimiter.thickness > 1 && closerDelimiter.thickness > 1) {
110
- thickness = 2;
111
- }
112
- internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
113
- const token = {
114
- nodeType: thickness === 1 ? EmphasisType : StrongType,
115
- startIndex: openerDelimiter.endIndex - thickness,
116
- endIndex: closerDelimiter.startIndex + thickness,
117
- thickness,
118
- children: internalTokens,
119
- };
120
- const remainOpenerDelimiter = openerDelimiter.thickness > thickness
121
- ? {
122
- type: openerDelimiter.type,
123
- startIndex: openerDelimiter.startIndex,
124
- endIndex: openerDelimiter.endIndex - thickness,
125
- thickness: openerDelimiter.thickness - thickness,
126
- originalThickness: openerDelimiter.originalThickness,
98
+ function isDelimiterPair(openerDelimiter, closerDelimiter) {
99
+ const nodePoints = api.getNodePoints();
100
+ if (nodePoints[openerDelimiter.startIndex].codePoint !==
101
+ nodePoints[closerDelimiter.startIndex].codePoint ||
102
+ ((openerDelimiter.type === 'both' || closerDelimiter.type === 'both') &&
103
+ (openerDelimiter.originalThickness + closerDelimiter.originalThickness) % 3 === 0 &&
104
+ openerDelimiter.originalThickness % 3 !== 0)) {
105
+ return { paired: false, opener: true, closer: true };
106
+ }
107
+ return { paired: true };
127
108
  }
128
- : undefined;
129
- const remainCloserDelimiter = closerDelimiter.thickness > thickness
130
- ? {
131
- type: closerDelimiter.type,
132
- startIndex: closerDelimiter.startIndex + thickness,
133
- endIndex: closerDelimiter.endIndex,
134
- thickness: closerDelimiter.thickness - thickness,
135
- originalThickness: closerDelimiter.originalThickness,
109
+ function processDelimiterPair(openerDelimiter, closerDelimiter, internalTokens) {
110
+ let thickness = 1;
111
+ if (openerDelimiter.thickness > 1 && closerDelimiter.thickness > 1) {
112
+ thickness = 2;
113
+ }
114
+ internalTokens = api.resolveInternalTokens(internalTokens, openerDelimiter.endIndex, closerDelimiter.startIndex);
115
+ const token = {
116
+ nodeType: thickness === 1 ? EmphasisType : StrongType,
117
+ startIndex: openerDelimiter.endIndex - thickness,
118
+ endIndex: closerDelimiter.startIndex + thickness,
119
+ thickness,
120
+ children: internalTokens,
121
+ };
122
+ const remainOpenerDelimiter = openerDelimiter.thickness > thickness
123
+ ? {
124
+ type: openerDelimiter.type,
125
+ startIndex: openerDelimiter.startIndex,
126
+ endIndex: openerDelimiter.endIndex - thickness,
127
+ thickness: openerDelimiter.thickness - thickness,
128
+ originalThickness: openerDelimiter.originalThickness,
129
+ }
130
+ : undefined;
131
+ const remainCloserDelimiter = closerDelimiter.thickness > thickness
132
+ ? {
133
+ type: closerDelimiter.type,
134
+ startIndex: closerDelimiter.startIndex + thickness,
135
+ endIndex: closerDelimiter.endIndex,
136
+ thickness: closerDelimiter.thickness - thickness,
137
+ originalThickness: closerDelimiter.originalThickness,
138
+ }
139
+ : undefined;
140
+ return {
141
+ tokens: [token],
142
+ remainOpenerDelimiter,
143
+ remainCloserDelimiter,
144
+ };
136
145
  }
137
- : undefined;
138
- return {
139
- tokens: [token],
140
- remainOpenerDelimiter,
141
- remainCloserDelimiter,
142
146
  };
143
- }
144
- parseInline(token, children) {
145
- const result = {
146
- type: token.nodeType,
147
- children,
148
- };
149
- return result;
147
+ this.parse = () => ({
148
+ parse: (token, children) => {
149
+ const result = {
150
+ type: token.nodeType,
151
+ children,
152
+ };
153
+ return result;
154
+ },
155
+ });
150
156
  }
151
157
  }
152
158
 
@@ -1,5 +1,3 @@
1
- import { EmphasisTokenizer } from './tokenizer';
2
- export { EmphasisTokenizer } from './tokenizer';
1
+ export { EmphasisTokenizer, EmphasisTokenizer as default } from './tokenizer';
3
2
  export { uniqueName as EmphasisTokenizerName } from './types';
4
- export type { Token as EmphasisToken, TokenizerProps as EmphasisTokenizerProps, } from './types';
5
- export default EmphasisTokenizer;
3
+ export type { IToken as IEmphasisToken, ITokenizerProps as IEmphasisTokenizerProps } from './types';
@@ -1,33 +1,14 @@
1
- import type { YastNode } from '@yozora/ast';
2
- import type { MatchInlinePhaseApi, ResultOfIsDelimiterPair, ResultOfProcessDelimiterPair, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook, YastInlineToken } from '@yozora/core-tokenizer';
1
+ import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
3
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
4
- import type { Delimiter, Node, T, Token, TokenizerProps } from './types';
3
+ import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
5
4
  /**
6
5
  * Lexical Analyzer for Emphasis and Strong Emphasis.
7
6
  *
8
7
  * @see https://github.com/syntax-tree/mdast#strong
9
8
  * @see https://github.github.com/gfm/#emphasis-and-strong-emphasis
10
9
  */
11
- export declare class EmphasisTokenizer extends BaseInlineTokenizer<Delimiter> implements Tokenizer, TokenizerMatchInlineHook<T, Delimiter, Token>, TokenizerParseInlineHook<T, Token, Node> {
12
- constructor(props?: TokenizerProps);
13
- /**
14
- * @override
15
- * @see BaseInlineTokenizer
16
- */
17
- protected _findDelimiter(startIndex: number, endIndex: number, api: Readonly<MatchInlinePhaseApi>): Delimiter | null;
18
- /**
19
- * @override
20
- * @see TokenizerMatchInlineHook
21
- */
22
- isDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, api: Readonly<MatchInlinePhaseApi>): ResultOfIsDelimiterPair;
23
- /**
24
- * @override
25
- * @see TokenizerMatchInlineHook
26
- */
27
- processDelimiterPair(openerDelimiter: Delimiter, closerDelimiter: Delimiter, internalTokens: ReadonlyArray<YastInlineToken>, api: Readonly<MatchInlinePhaseApi>): ResultOfProcessDelimiterPair<T, Token, Delimiter>;
28
- /**
29
- * @override
30
- * @see TokenizerParseInlineHook
31
- */
32
- parseInline(token: Token, children: YastNode[]): Node;
10
+ export declare class EmphasisTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
11
+ constructor(props?: ITokenizerProps);
12
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
13
+ readonly parse: IParseInlineHookCreator<T, IToken, INode>;
33
14
  }
@@ -1,15 +1,15 @@
1
- import type { Emphasis, EmphasisType, Strong, StrongType } from '@yozora/ast';
2
- import type { BaseInlineTokenizerProps, PartialYastInlineToken, YastTokenDelimiter } from '@yozora/core-tokenizer';
1
+ import type { EmphasisType, IEmphasis, IStrong, StrongType } from '@yozora/ast';
2
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
3
3
  export declare type T = EmphasisType | StrongType;
4
- export declare type Node = Emphasis | Strong;
4
+ export declare type INode = IEmphasis | IStrong;
5
5
  export declare const uniqueName = "@yozora/tokenizer-emphasis";
6
- export interface Token extends PartialYastInlineToken<T> {
6
+ export interface IToken extends IPartialYastInlineToken<T> {
7
7
  /**
8
- * Delimiter thickness.
8
+ * IDelimiter thickness.
9
9
  */
10
10
  thickness: number;
11
11
  }
12
- export interface Delimiter extends YastTokenDelimiter {
12
+ export interface IDelimiter extends IYastTokenDelimiter {
13
13
  /**
14
14
  * Thickness of the delimiter.
15
15
  */
@@ -19,4 +19,4 @@ export interface Delimiter extends YastTokenDelimiter {
19
19
  */
20
20
  originalThickness: number;
21
21
  }
22
- export declare type TokenizerProps = Partial<BaseInlineTokenizerProps>;
22
+ export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-emphasis",
3
- "version": "1.3.0",
3
+ "version": "2.0.0-alpha.0",
4
4
  "author": {
5
5
  "name": "guanghechen",
6
6
  "url": "https://github.com/guanghechen/"
@@ -35,9 +35,9 @@
35
35
  "test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
36
36
  },
37
37
  "dependencies": {
38
- "@yozora/ast": "^1.3.0",
39
- "@yozora/character": "^1.3.0",
40
- "@yozora/core-tokenizer": "^1.3.0"
38
+ "@yozora/ast": "^2.0.0-alpha.0",
39
+ "@yozora/character": "^2.0.0-alpha.0",
40
+ "@yozora/core-tokenizer": "^2.0.0-alpha.0"
41
41
  },
42
- "gitHead": "18c9b167004ad97718b2f94f25139f80598cbf7a"
42
+ "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
43
43
  }