@yozora/tokenizer-inline-math 1.2.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 +127 -124
- package/lib/esm/index.js +126 -123
- package/lib/types/index.d.ts +2 -4
- package/lib/types/tokenizer.d.ts +6 -26
- package/lib/types/types.d.ts +7 -7
- package/package.json +6 -6
package/lib/cjs/index.js
CHANGED
|
@@ -15,144 +15,147 @@ class InlineMathTokenizer 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.ATOMIC,
|
|
17
17
|
});
|
|
18
|
-
this.
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
18
|
+
this.match = api => {
|
|
19
|
+
const { backtickRequired } = this;
|
|
20
|
+
return { findDelimiter, processSingleDelimiter };
|
|
21
|
+
function* findDelimiter() {
|
|
22
|
+
const nodePoints = api.getNodePoints();
|
|
23
|
+
const blockStartIndex = api.getBlockStartIndex();
|
|
24
|
+
const blockEndIndex = api.getBlockEndIndex();
|
|
25
|
+
const potentialDelimiters = [];
|
|
26
|
+
for (let i = blockStartIndex; i < blockEndIndex; ++i) {
|
|
27
|
+
const c = nodePoints[i].codePoint;
|
|
28
|
+
switch (c) {
|
|
29
|
+
case character.AsciiCodePoint.BACKSLASH:
|
|
30
|
+
i += 1;
|
|
31
|
+
break;
|
|
32
|
+
case character.AsciiCodePoint.BACKTICK: {
|
|
33
|
+
const _startIndex = i;
|
|
34
|
+
i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, blockEndIndex, character.AsciiCodePoint.BACKTICK);
|
|
35
|
+
if (i >= blockEndIndex || nodePoints[i].codePoint !== character.AsciiCodePoint.DOLLAR_SIGN) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const delimiter = {
|
|
39
|
+
type: 'opener',
|
|
40
|
+
startIndex: _startIndex,
|
|
41
|
+
endIndex: i + 1,
|
|
42
|
+
};
|
|
43
|
+
potentialDelimiters.push(delimiter);
|
|
44
|
+
break;
|
|
45
|
+
}
|
|
46
|
+
case character.AsciiCodePoint.DOLLAR_SIGN: {
|
|
47
|
+
const _startIndex = i;
|
|
48
|
+
i = coreTokenizer.eatOptionalCharacters(nodePoints, i + 1, blockEndIndex, character.AsciiCodePoint.BACKTICK);
|
|
49
|
+
if (i < blockEndIndex && nodePoints[i].codePoint === character.AsciiCodePoint.DOLLAR_SIGN) {
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
const thickness = i - _startIndex;
|
|
53
|
+
if (thickness <= 1) {
|
|
54
|
+
if (backtickRequired)
|
|
55
|
+
break;
|
|
56
|
+
const delimiter = {
|
|
57
|
+
type: 'both',
|
|
58
|
+
startIndex: _startIndex,
|
|
59
|
+
endIndex: i,
|
|
60
|
+
};
|
|
61
|
+
potentialDelimiters.push(delimiter);
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
const delimiter = {
|
|
65
|
+
type: 'closer',
|
|
66
|
+
startIndex: _startIndex,
|
|
67
|
+
endIndex: i,
|
|
68
|
+
};
|
|
69
|
+
potentialDelimiters.push(delimiter);
|
|
70
|
+
i -= 1;
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
36
73
|
}
|
|
37
|
-
const delimiter = {
|
|
38
|
-
type: 'opener',
|
|
39
|
-
startIndex: _startIndex,
|
|
40
|
-
endIndex: i + 1,
|
|
41
|
-
};
|
|
42
|
-
potentialDelimiters.push(delimiter);
|
|
43
|
-
break;
|
|
44
74
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
75
|
+
let pIndex = 0;
|
|
76
|
+
let lastEndIndex = -1;
|
|
77
|
+
let delimiter = null;
|
|
78
|
+
while (pIndex < potentialDelimiters.length) {
|
|
79
|
+
const [startIndex, endIndex] = yield delimiter;
|
|
80
|
+
if (lastEndIndex === endIndex) {
|
|
81
|
+
if (delimiter == null || delimiter.startIndex >= startIndex)
|
|
82
|
+
continue;
|
|
51
83
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
84
|
+
lastEndIndex = endIndex;
|
|
85
|
+
let openerDelimiter = null;
|
|
86
|
+
let closerDelimiter = null;
|
|
87
|
+
for (; pIndex < potentialDelimiters.length; ++pIndex) {
|
|
88
|
+
for (; pIndex < potentialDelimiters.length; ++pIndex) {
|
|
89
|
+
const delimiter = potentialDelimiters[pIndex];
|
|
90
|
+
if (delimiter.startIndex >= startIndex && delimiter.type !== 'closer')
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (pIndex + 1 >= potentialDelimiters.length)
|
|
94
|
+
break;
|
|
95
|
+
openerDelimiter = potentialDelimiters[pIndex];
|
|
96
|
+
const thickness = openerDelimiter.endIndex - openerDelimiter.startIndex;
|
|
97
|
+
for (let i = pIndex + 1; i < potentialDelimiters.length; ++i) {
|
|
98
|
+
const delimiter = potentialDelimiters[i];
|
|
99
|
+
if (delimiter.type !== 'opener' &&
|
|
100
|
+
delimiter.endIndex - delimiter.startIndex === thickness) {
|
|
101
|
+
closerDelimiter = delimiter;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (closerDelimiter != null)
|
|
55
106
|
break;
|
|
56
|
-
const delimiter = {
|
|
57
|
-
type: 'both',
|
|
58
|
-
startIndex: _startIndex,
|
|
59
|
-
endIndex: i,
|
|
60
|
-
};
|
|
61
|
-
potentialDelimiters.push(delimiter);
|
|
62
|
-
break;
|
|
63
107
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
108
|
+
if (closerDelimiter == null)
|
|
109
|
+
return;
|
|
110
|
+
delimiter = {
|
|
111
|
+
type: 'full',
|
|
112
|
+
startIndex: openerDelimiter.startIndex,
|
|
113
|
+
endIndex: closerDelimiter.endIndex,
|
|
114
|
+
thickness: closerDelimiter.endIndex - closerDelimiter.startIndex,
|
|
68
115
|
};
|
|
69
|
-
potentialDelimiters.push(delimiter);
|
|
70
|
-
i -= 1;
|
|
71
|
-
break;
|
|
72
116
|
}
|
|
73
117
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
continue;
|
|
118
|
+
function processSingleDelimiter(delimiter) {
|
|
119
|
+
const token = {
|
|
120
|
+
nodeType: ast.InlineMathType,
|
|
121
|
+
startIndex: delimiter.startIndex,
|
|
122
|
+
endIndex: delimiter.endIndex,
|
|
123
|
+
thickness: delimiter.thickness,
|
|
124
|
+
};
|
|
125
|
+
return [token];
|
|
83
126
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
127
|
+
};
|
|
128
|
+
this.parse = api => ({
|
|
129
|
+
parse: token => {
|
|
130
|
+
const nodePoints = api.getNodePoints();
|
|
131
|
+
let startIndex = token.startIndex + token.thickness;
|
|
132
|
+
let endIndex = token.endIndex - token.thickness;
|
|
133
|
+
let isAllSpace = true;
|
|
134
|
+
for (let i = startIndex; i < endIndex; ++i) {
|
|
135
|
+
if (character.isSpaceLike(nodePoints[i].codePoint))
|
|
136
|
+
continue;
|
|
137
|
+
isAllSpace = false;
|
|
94
138
|
break;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
break;
|
|
139
|
+
}
|
|
140
|
+
if (!isAllSpace && startIndex + 2 < endIndex) {
|
|
141
|
+
const firstCharacter = nodePoints[startIndex].codePoint;
|
|
142
|
+
const lastCharacter = nodePoints[endIndex - 1].codePoint;
|
|
143
|
+
if (character.isSpaceLike(firstCharacter) && character.isSpaceLike(lastCharacter)) {
|
|
144
|
+
startIndex += 1;
|
|
145
|
+
endIndex -= 1;
|
|
103
146
|
}
|
|
104
147
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
endIndex: closerDelimiter.endIndex,
|
|
114
|
-
thickness: closerDelimiter.endIndex - closerDelimiter.startIndex,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
_findDelimiter() {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
processSingleDelimiter(delimiter) {
|
|
122
|
-
const token = {
|
|
123
|
-
nodeType: ast.InlineMathType,
|
|
124
|
-
startIndex: delimiter.startIndex,
|
|
125
|
-
endIndex: delimiter.endIndex,
|
|
126
|
-
thickness: delimiter.thickness,
|
|
127
|
-
};
|
|
128
|
-
return [token];
|
|
129
|
-
}
|
|
130
|
-
processToken(token, children, nodePoints) {
|
|
131
|
-
let startIndex = token.startIndex + token.thickness;
|
|
132
|
-
let endIndex = token.endIndex - token.thickness;
|
|
133
|
-
let isAllSpace = true;
|
|
134
|
-
for (let i = startIndex; i < endIndex; ++i) {
|
|
135
|
-
if (character.isSpaceLike(nodePoints[i].codePoint))
|
|
136
|
-
continue;
|
|
137
|
-
isAllSpace = false;
|
|
138
|
-
break;
|
|
139
|
-
}
|
|
140
|
-
if (!isAllSpace && startIndex + 2 < endIndex) {
|
|
141
|
-
const firstCharacter = nodePoints[startIndex].codePoint;
|
|
142
|
-
const lastCharacter = nodePoints[endIndex - 1].codePoint;
|
|
143
|
-
if (character.isSpaceLike(firstCharacter) && character.isSpaceLike(lastCharacter)) {
|
|
144
|
-
startIndex += 1;
|
|
145
|
-
endIndex -= 1;
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
const result = {
|
|
149
|
-
type: ast.InlineMathType,
|
|
150
|
-
value: character.calcStringFromNodePoints(nodePoints, startIndex, endIndex).replace(/\n/, ' '),
|
|
151
|
-
};
|
|
152
|
-
return result;
|
|
148
|
+
const result = {
|
|
149
|
+
type: ast.InlineMathType,
|
|
150
|
+
value: character.calcStringFromNodePoints(nodePoints, startIndex, endIndex).replace(/\n/, ' '),
|
|
151
|
+
};
|
|
152
|
+
return result;
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
this.backtickRequired = (_c = props.backtickRequired) !== null && _c !== void 0 ? _c : true;
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
158
|
|
|
156
159
|
exports.InlineMathTokenizer = InlineMathTokenizer;
|
|
157
160
|
exports.InlineMathTokenizerName = uniqueName;
|
|
158
|
-
exports[
|
|
161
|
+
exports["default"] = InlineMathTokenizer;
|
package/lib/esm/index.js
CHANGED
|
@@ -11,141 +11,144 @@ class InlineMathTokenizer 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.ATOMIC,
|
|
13
13
|
});
|
|
14
|
-
this.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
14
|
+
this.match = api => {
|
|
15
|
+
const { backtickRequired } = this;
|
|
16
|
+
return { findDelimiter, processSingleDelimiter };
|
|
17
|
+
function* findDelimiter() {
|
|
18
|
+
const nodePoints = api.getNodePoints();
|
|
19
|
+
const blockStartIndex = api.getBlockStartIndex();
|
|
20
|
+
const blockEndIndex = api.getBlockEndIndex();
|
|
21
|
+
const potentialDelimiters = [];
|
|
22
|
+
for (let i = blockStartIndex; i < blockEndIndex; ++i) {
|
|
23
|
+
const c = nodePoints[i].codePoint;
|
|
24
|
+
switch (c) {
|
|
25
|
+
case AsciiCodePoint.BACKSLASH:
|
|
26
|
+
i += 1;
|
|
27
|
+
break;
|
|
28
|
+
case AsciiCodePoint.BACKTICK: {
|
|
29
|
+
const _startIndex = i;
|
|
30
|
+
i = eatOptionalCharacters(nodePoints, i + 1, blockEndIndex, AsciiCodePoint.BACKTICK);
|
|
31
|
+
if (i >= blockEndIndex || nodePoints[i].codePoint !== AsciiCodePoint.DOLLAR_SIGN) {
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
const delimiter = {
|
|
35
|
+
type: 'opener',
|
|
36
|
+
startIndex: _startIndex,
|
|
37
|
+
endIndex: i + 1,
|
|
38
|
+
};
|
|
39
|
+
potentialDelimiters.push(delimiter);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
case AsciiCodePoint.DOLLAR_SIGN: {
|
|
43
|
+
const _startIndex = i;
|
|
44
|
+
i = eatOptionalCharacters(nodePoints, i + 1, blockEndIndex, AsciiCodePoint.BACKTICK);
|
|
45
|
+
if (i < blockEndIndex && nodePoints[i].codePoint === AsciiCodePoint.DOLLAR_SIGN) {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const thickness = i - _startIndex;
|
|
49
|
+
if (thickness <= 1) {
|
|
50
|
+
if (backtickRequired)
|
|
51
|
+
break;
|
|
52
|
+
const delimiter = {
|
|
53
|
+
type: 'both',
|
|
54
|
+
startIndex: _startIndex,
|
|
55
|
+
endIndex: i,
|
|
56
|
+
};
|
|
57
|
+
potentialDelimiters.push(delimiter);
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
const delimiter = {
|
|
61
|
+
type: 'closer',
|
|
62
|
+
startIndex: _startIndex,
|
|
63
|
+
endIndex: i,
|
|
64
|
+
};
|
|
65
|
+
potentialDelimiters.push(delimiter);
|
|
66
|
+
i -= 1;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
32
69
|
}
|
|
33
|
-
const delimiter = {
|
|
34
|
-
type: 'opener',
|
|
35
|
-
startIndex: _startIndex,
|
|
36
|
-
endIndex: i + 1,
|
|
37
|
-
};
|
|
38
|
-
potentialDelimiters.push(delimiter);
|
|
39
|
-
break;
|
|
40
70
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
71
|
+
let pIndex = 0;
|
|
72
|
+
let lastEndIndex = -1;
|
|
73
|
+
let delimiter = null;
|
|
74
|
+
while (pIndex < potentialDelimiters.length) {
|
|
75
|
+
const [startIndex, endIndex] = yield delimiter;
|
|
76
|
+
if (lastEndIndex === endIndex) {
|
|
77
|
+
if (delimiter == null || delimiter.startIndex >= startIndex)
|
|
78
|
+
continue;
|
|
47
79
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
lastEndIndex = endIndex;
|
|
81
|
+
let openerDelimiter = null;
|
|
82
|
+
let closerDelimiter = null;
|
|
83
|
+
for (; pIndex < potentialDelimiters.length; ++pIndex) {
|
|
84
|
+
for (; pIndex < potentialDelimiters.length; ++pIndex) {
|
|
85
|
+
const delimiter = potentialDelimiters[pIndex];
|
|
86
|
+
if (delimiter.startIndex >= startIndex && delimiter.type !== 'closer')
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (pIndex + 1 >= potentialDelimiters.length)
|
|
90
|
+
break;
|
|
91
|
+
openerDelimiter = potentialDelimiters[pIndex];
|
|
92
|
+
const thickness = openerDelimiter.endIndex - openerDelimiter.startIndex;
|
|
93
|
+
for (let i = pIndex + 1; i < potentialDelimiters.length; ++i) {
|
|
94
|
+
const delimiter = potentialDelimiters[i];
|
|
95
|
+
if (delimiter.type !== 'opener' &&
|
|
96
|
+
delimiter.endIndex - delimiter.startIndex === thickness) {
|
|
97
|
+
closerDelimiter = delimiter;
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
if (closerDelimiter != null)
|
|
51
102
|
break;
|
|
52
|
-
const delimiter = {
|
|
53
|
-
type: 'both',
|
|
54
|
-
startIndex: _startIndex,
|
|
55
|
-
endIndex: i,
|
|
56
|
-
};
|
|
57
|
-
potentialDelimiters.push(delimiter);
|
|
58
|
-
break;
|
|
59
103
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
104
|
+
if (closerDelimiter == null)
|
|
105
|
+
return;
|
|
106
|
+
delimiter = {
|
|
107
|
+
type: 'full',
|
|
108
|
+
startIndex: openerDelimiter.startIndex,
|
|
109
|
+
endIndex: closerDelimiter.endIndex,
|
|
110
|
+
thickness: closerDelimiter.endIndex - closerDelimiter.startIndex,
|
|
64
111
|
};
|
|
65
|
-
potentialDelimiters.push(delimiter);
|
|
66
|
-
i -= 1;
|
|
67
|
-
break;
|
|
68
112
|
}
|
|
69
113
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
continue;
|
|
114
|
+
function processSingleDelimiter(delimiter) {
|
|
115
|
+
const token = {
|
|
116
|
+
nodeType: InlineMathType,
|
|
117
|
+
startIndex: delimiter.startIndex,
|
|
118
|
+
endIndex: delimiter.endIndex,
|
|
119
|
+
thickness: delimiter.thickness,
|
|
120
|
+
};
|
|
121
|
+
return [token];
|
|
79
122
|
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
123
|
+
};
|
|
124
|
+
this.parse = api => ({
|
|
125
|
+
parse: token => {
|
|
126
|
+
const nodePoints = api.getNodePoints();
|
|
127
|
+
let startIndex = token.startIndex + token.thickness;
|
|
128
|
+
let endIndex = token.endIndex - token.thickness;
|
|
129
|
+
let isAllSpace = true;
|
|
130
|
+
for (let i = startIndex; i < endIndex; ++i) {
|
|
131
|
+
if (isSpaceLike(nodePoints[i].codePoint))
|
|
132
|
+
continue;
|
|
133
|
+
isAllSpace = false;
|
|
90
134
|
break;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
break;
|
|
135
|
+
}
|
|
136
|
+
if (!isAllSpace && startIndex + 2 < endIndex) {
|
|
137
|
+
const firstCharacter = nodePoints[startIndex].codePoint;
|
|
138
|
+
const lastCharacter = nodePoints[endIndex - 1].codePoint;
|
|
139
|
+
if (isSpaceLike(firstCharacter) && isSpaceLike(lastCharacter)) {
|
|
140
|
+
startIndex += 1;
|
|
141
|
+
endIndex -= 1;
|
|
99
142
|
}
|
|
100
143
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
return;
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
endIndex: closerDelimiter.endIndex,
|
|
110
|
-
thickness: closerDelimiter.endIndex - closerDelimiter.startIndex,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
_findDelimiter() {
|
|
115
|
-
return null;
|
|
116
|
-
}
|
|
117
|
-
processSingleDelimiter(delimiter) {
|
|
118
|
-
const token = {
|
|
119
|
-
nodeType: InlineMathType,
|
|
120
|
-
startIndex: delimiter.startIndex,
|
|
121
|
-
endIndex: delimiter.endIndex,
|
|
122
|
-
thickness: delimiter.thickness,
|
|
123
|
-
};
|
|
124
|
-
return [token];
|
|
125
|
-
}
|
|
126
|
-
processToken(token, children, nodePoints) {
|
|
127
|
-
let startIndex = token.startIndex + token.thickness;
|
|
128
|
-
let endIndex = token.endIndex - token.thickness;
|
|
129
|
-
let isAllSpace = true;
|
|
130
|
-
for (let i = startIndex; i < endIndex; ++i) {
|
|
131
|
-
if (isSpaceLike(nodePoints[i].codePoint))
|
|
132
|
-
continue;
|
|
133
|
-
isAllSpace = false;
|
|
134
|
-
break;
|
|
135
|
-
}
|
|
136
|
-
if (!isAllSpace && startIndex + 2 < endIndex) {
|
|
137
|
-
const firstCharacter = nodePoints[startIndex].codePoint;
|
|
138
|
-
const lastCharacter = nodePoints[endIndex - 1].codePoint;
|
|
139
|
-
if (isSpaceLike(firstCharacter) && isSpaceLike(lastCharacter)) {
|
|
140
|
-
startIndex += 1;
|
|
141
|
-
endIndex -= 1;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
const result = {
|
|
145
|
-
type: InlineMathType,
|
|
146
|
-
value: calcStringFromNodePoints(nodePoints, startIndex, endIndex).replace(/\n/, ' '),
|
|
147
|
-
};
|
|
148
|
-
return result;
|
|
144
|
+
const result = {
|
|
145
|
+
type: InlineMathType,
|
|
146
|
+
value: calcStringFromNodePoints(nodePoints, startIndex, endIndex).replace(/\n/, ' '),
|
|
147
|
+
};
|
|
148
|
+
return result;
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
this.backtickRequired = (_c = props.backtickRequired) !== null && _c !== void 0 ? _c : true;
|
|
149
152
|
}
|
|
150
153
|
}
|
|
151
154
|
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { InlineMathTokenizer } from './tokenizer';
|
|
1
|
+
export { InlineMathTokenizer, InlineMathTokenizer as default } from './tokenizer';
|
|
3
2
|
export { uniqueName as InlineMathTokenizerName } from './types';
|
|
4
|
-
export type {
|
|
5
|
-
export default InlineMathTokenizer;
|
|
3
|
+
export type { IToken as IInlineMathToken, ITokenizerProps as IInlineMathTokenizerProps, } from './types';
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,32 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { NodePoint } from '@yozora/character';
|
|
3
|
-
import type { MatchInlinePhaseApi, ResultOfFindDelimiters, ResultOfProcessSingleDelimiter, Tokenizer, TokenizerMatchInlineHook, TokenizerParseInlineHook } from '@yozora/core-tokenizer';
|
|
1
|
+
import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
|
|
4
2
|
import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
|
|
5
|
-
import type {
|
|
3
|
+
import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
|
|
6
4
|
/**
|
|
7
5
|
* Lexical Analyzer for inlineMath.
|
|
8
6
|
*/
|
|
9
|
-
export declare class InlineMathTokenizer extends BaseInlineTokenizer<
|
|
7
|
+
export declare class InlineMathTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
|
|
10
8
|
readonly backtickRequired: boolean;
|
|
11
|
-
constructor(props?:
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
* @see BaseInlineTokenizer
|
|
15
|
-
*/
|
|
16
|
-
findDelimiter(nodePoints: ReadonlyArray<NodePoint>, api: Readonly<MatchInlinePhaseApi>): ResultOfFindDelimiters<Delimiter>;
|
|
17
|
-
/**
|
|
18
|
-
* @override
|
|
19
|
-
* @see BaseInlineTokenizer
|
|
20
|
-
*/
|
|
21
|
-
protected _findDelimiter(): null;
|
|
22
|
-
/**
|
|
23
|
-
* @override
|
|
24
|
-
* @see TokenizerMatchInlineHook
|
|
25
|
-
*/
|
|
26
|
-
processSingleDelimiter(delimiter: Delimiter): ResultOfProcessSingleDelimiter<T, Token>;
|
|
27
|
-
/**
|
|
28
|
-
* @override
|
|
29
|
-
* @see TokenizerParseInlineHook
|
|
30
|
-
*/
|
|
31
|
-
processToken(token: Token, children: YastNode[] | undefined, nodePoints: ReadonlyArray<NodePoint>): Node;
|
|
9
|
+
constructor(props?: ITokenizerProps);
|
|
10
|
+
readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
|
|
11
|
+
readonly parse: IParseInlineHookCreator<T, IToken, INode>;
|
|
32
12
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { IInlineMath, InlineMathType } from '@yozora/ast';
|
|
2
|
+
import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = InlineMathType;
|
|
4
|
-
export declare type
|
|
4
|
+
export declare type INode = IInlineMath;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-inline-math";
|
|
6
|
-
export interface
|
|
6
|
+
export interface IToken extends IPartialYastInlineToken<T> {
|
|
7
7
|
/**
|
|
8
8
|
* Thickness of the InlineMathDelimiter
|
|
9
9
|
*/
|
|
10
10
|
thickness: number;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* IDelimiter of InlineMathToken.
|
|
14
14
|
*/
|
|
15
|
-
export interface
|
|
15
|
+
export interface IDelimiter extends IYastTokenDelimiter {
|
|
16
16
|
type: 'full';
|
|
17
17
|
/**
|
|
18
18
|
* Thickness of the InlineMathDelimiter
|
|
19
19
|
*/
|
|
20
20
|
thickness: number;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface ITokenizerProps extends Partial<IBaseInlineTokenizerProps> {
|
|
23
23
|
/**
|
|
24
24
|
* Whether if the backtick mark wrapping necessary.
|
|
25
25
|
* @default true
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-inline-math",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0-alpha.0",
|
|
4
4
|
"description": "Tokenizer for processing inline math (formulas)",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "guanghechen",
|
|
@@ -45,12 +45,12 @@
|
|
|
45
45
|
"test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@yozora/ast": "^
|
|
49
|
-
"@yozora/character": "^
|
|
50
|
-
"@yozora/core-tokenizer": "^
|
|
48
|
+
"@yozora/ast": "^2.0.0-alpha.0",
|
|
49
|
+
"@yozora/character": "^2.0.0-alpha.0",
|
|
50
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@yozora/tokenizer-inline-code": "^
|
|
53
|
+
"@yozora/tokenizer-inline-code": "^2.0.0-alpha.0"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
|
|
56
56
|
}
|