@yozora/tokenizer-table 2.0.0-alpha.0 → 2.0.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/README.md +4 -6
- package/lib/cjs/index.js +47 -67
- package/lib/esm/index.js +48 -68
- package/lib/types/index.d.ts +1 -1
- package/lib/types/match.d.ts +2 -2
- package/lib/types/parse.d.ts +2 -2
- package/lib/types/tokenizer.d.ts +4 -4
- package/lib/types/types.d.ts +14 -20
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -84,14 +84,14 @@ so you can use `YozoraParser` / `GfmExParser` directly.
|
|
|
84
84
|
registered in *YastParser* as a plugin-in before it can be used.
|
|
85
85
|
|
|
86
86
|
```typescript {4,9}
|
|
87
|
-
import {
|
|
87
|
+
import { DefaultParser } from '@yozora/core-parser'
|
|
88
88
|
import ParagraphTokenizer from '@yozora/tokenizer-paragraph'
|
|
89
89
|
import TextTokenizer from '@yozora/tokenizer-text'
|
|
90
90
|
import TableTokenizer from '@yozora/tokenizer-table'
|
|
91
91
|
|
|
92
|
-
const parser = new
|
|
93
|
-
.
|
|
94
|
-
.
|
|
92
|
+
const parser = new DefaultParser()
|
|
93
|
+
.useFallbackTokenizer(new ParagraphTokenizer())
|
|
94
|
+
.useFallbackTokenizer(new TextTokenizer())
|
|
95
95
|
.useTokenizer(new TableTokenizer())
|
|
96
96
|
|
|
97
97
|
// parse source markdown content
|
|
@@ -227,7 +227,6 @@ Name | Type | Required | Default
|
|
|
227
227
|
[@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
|
|
228
228
|
[@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
|
|
229
229
|
[@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
|
|
230
|
-
[@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
|
|
231
230
|
[@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
|
|
232
231
|
[@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
|
|
233
232
|
[@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
|
|
@@ -287,7 +286,6 @@ Name | Type | Required | Default
|
|
|
287
286
|
[doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
|
|
288
287
|
[doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
|
|
289
288
|
[doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
|
|
290
|
-
[doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
|
|
291
289
|
[doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
|
|
292
290
|
[doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
|
|
293
291
|
[doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
|
package/lib/cjs/index.js
CHANGED
|
@@ -7,7 +7,6 @@ var character = require('@yozora/character');
|
|
|
7
7
|
var coreTokenizer = require('@yozora/core-tokenizer');
|
|
8
8
|
|
|
9
9
|
const match = function (api) {
|
|
10
|
-
const { name: _tokenizer } = this;
|
|
11
10
|
return {
|
|
12
11
|
isContainingBlock: false,
|
|
13
12
|
eatOpener,
|
|
@@ -103,11 +102,11 @@ const match = function (api) {
|
|
|
103
102
|
const token = {
|
|
104
103
|
nodeType: ast.TableType,
|
|
105
104
|
position: {
|
|
106
|
-
start: coreTokenizer.
|
|
107
|
-
end: coreTokenizer.
|
|
105
|
+
start: coreTokenizer.calcStartPoint(previousLine.nodePoints, previousLine.startIndex),
|
|
106
|
+
end: coreTokenizer.calcEndPoint(nodePoints, nextIndex - 1),
|
|
108
107
|
},
|
|
109
108
|
columns,
|
|
110
|
-
|
|
109
|
+
rows: [row],
|
|
111
110
|
};
|
|
112
111
|
return {
|
|
113
112
|
token,
|
|
@@ -119,11 +118,10 @@ const match = function (api) {
|
|
|
119
118
|
if (line.firstNonWhitespaceIndex >= line.endIndex) {
|
|
120
119
|
return { status: 'notMatched' };
|
|
121
120
|
}
|
|
122
|
-
const
|
|
123
|
-
const row = calcTableRow(line, tableToken.columns);
|
|
121
|
+
const row = calcTableRow(line, token.columns);
|
|
124
122
|
if (row == null)
|
|
125
123
|
return { status: 'notMatched' };
|
|
126
|
-
|
|
124
|
+
token.rows.push(row);
|
|
127
125
|
return { status: 'opening', nextIndex: line.endIndex };
|
|
128
126
|
}
|
|
129
127
|
function calcTableRow(line, columns) {
|
|
@@ -139,9 +137,7 @@ const match = function (api) {
|
|
|
139
137
|
if (!character.isWhitespaceCharacter(p.codePoint))
|
|
140
138
|
break;
|
|
141
139
|
}
|
|
142
|
-
const startPoint = i < endIndex
|
|
143
|
-
? coreTokenizer.calcStartYastNodePoint(nodePoints, i)
|
|
144
|
-
: coreTokenizer.calcEndYastNodePoint(nodePoints, endIndex - 1);
|
|
140
|
+
const startPoint = i < endIndex ? coreTokenizer.calcStartPoint(nodePoints, i) : coreTokenizer.calcEndPoint(nodePoints, endIndex - 1);
|
|
145
141
|
const cellStartIndex = i, cellFirstNonWhitespaceIndex = i;
|
|
146
142
|
for (; i < endIndex; ++i) {
|
|
147
143
|
p = nodePoints[i];
|
|
@@ -158,10 +154,10 @@ const match = function (api) {
|
|
|
158
154
|
if (!character.isWhitespaceCharacter(p.codePoint))
|
|
159
155
|
break;
|
|
160
156
|
}
|
|
161
|
-
const endPoint = coreTokenizer.
|
|
162
|
-
const
|
|
163
|
-
?
|
|
164
|
-
:
|
|
157
|
+
const endPoint = coreTokenizer.calcEndPoint(nodePoints, i - 1);
|
|
158
|
+
const lines = cellFirstNonWhitespaceIndex >= cellEndIndex
|
|
159
|
+
? []
|
|
160
|
+
: [
|
|
165
161
|
{
|
|
166
162
|
nodePoints,
|
|
167
163
|
startIndex: cellStartIndex,
|
|
@@ -169,88 +165,72 @@ const match = function (api) {
|
|
|
169
165
|
firstNonWhitespaceIndex: cellFirstNonWhitespaceIndex,
|
|
170
166
|
countOfPrecedeSpaces: cellFirstNonWhitespaceIndex - cellStartIndex,
|
|
171
167
|
},
|
|
172
|
-
]
|
|
168
|
+
];
|
|
173
169
|
const cell = {
|
|
174
|
-
_tokenizer,
|
|
175
170
|
nodeType: ast.TableCellType,
|
|
176
171
|
position: { start: startPoint, end: endPoint },
|
|
177
|
-
|
|
172
|
+
lines: lines,
|
|
178
173
|
};
|
|
179
174
|
cells.push(cell);
|
|
180
175
|
if (cells.length >= columns.length)
|
|
181
176
|
break;
|
|
182
177
|
}
|
|
183
|
-
const startPoint = coreTokenizer.
|
|
184
|
-
const endPoint = coreTokenizer.
|
|
178
|
+
const startPoint = coreTokenizer.calcStartPoint(nodePoints, startIndex);
|
|
179
|
+
const endPoint = coreTokenizer.calcEndPoint(nodePoints, endIndex - 1);
|
|
185
180
|
for (let c = cells.length; c < columns.length; ++c) {
|
|
186
181
|
const cell = {
|
|
187
|
-
_tokenizer,
|
|
188
182
|
nodeType: ast.TableCellType,
|
|
189
183
|
position: { start: Object.assign({}, endPoint), end: Object.assign({}, endPoint) },
|
|
190
|
-
|
|
184
|
+
lines: [],
|
|
191
185
|
};
|
|
192
186
|
cells.push(cell);
|
|
193
187
|
}
|
|
194
188
|
const row = {
|
|
195
|
-
_tokenizer,
|
|
196
189
|
nodeType: ast.TableRowType,
|
|
197
190
|
position: { start: startPoint, end: endPoint },
|
|
198
|
-
|
|
191
|
+
cells,
|
|
199
192
|
};
|
|
200
193
|
return row;
|
|
201
194
|
}
|
|
202
195
|
};
|
|
203
196
|
|
|
204
|
-
const parse =
|
|
205
|
-
parse: (token
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
};
|
|
214
|
-
break;
|
|
215
|
-
}
|
|
216
|
-
case ast.TableRowType: {
|
|
217
|
-
node = {
|
|
218
|
-
type: ast.TableRowType,
|
|
219
|
-
children: children,
|
|
220
|
-
};
|
|
221
|
-
break;
|
|
222
|
-
}
|
|
223
|
-
case ast.TableCellType: {
|
|
224
|
-
node = {
|
|
225
|
-
type: ast.TableCellType,
|
|
226
|
-
children: children,
|
|
227
|
-
};
|
|
228
|
-
for (const phrasingContent of node.children) {
|
|
229
|
-
if (phrasingContent.type !== coreTokenizer.PhrasingContentType)
|
|
230
|
-
continue;
|
|
231
|
-
const nextContents = [];
|
|
232
|
-
const endIndex = phrasingContent.contents.length;
|
|
233
|
-
for (let i = 0; i < endIndex; ++i) {
|
|
234
|
-
const p = phrasingContent.contents[i];
|
|
197
|
+
const parse = api => ({
|
|
198
|
+
parse: tokens => tokens.map(token => {
|
|
199
|
+
const tableRows = token.rows.map((row) => {
|
|
200
|
+
const tableCells = row.cells.map((cell) => {
|
|
201
|
+
const contents = [];
|
|
202
|
+
{
|
|
203
|
+
const nodePoints = coreTokenizer.mergeAndStripContentLines(cell.lines);
|
|
204
|
+
for (let i = 0, endIndex = nodePoints.length; i < endIndex; ++i) {
|
|
205
|
+
const p = nodePoints[i];
|
|
235
206
|
if (p.codePoint === character.AsciiCodePoint.BACKSLASH && i + 1 < endIndex) {
|
|
236
|
-
const q =
|
|
207
|
+
const q = nodePoints[i + 1];
|
|
237
208
|
if (q.codePoint !== character.AsciiCodePoint.VERTICAL_SLASH)
|
|
238
|
-
|
|
239
|
-
|
|
209
|
+
contents.push(p);
|
|
210
|
+
contents.push(q);
|
|
240
211
|
i += 1;
|
|
241
|
-
continue;
|
|
242
212
|
}
|
|
243
|
-
|
|
213
|
+
else {
|
|
214
|
+
contents.push(p);
|
|
215
|
+
}
|
|
244
216
|
}
|
|
245
|
-
phrasingContent.contents = nextContents;
|
|
246
217
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
218
|
+
const children = api.processInlines(contents);
|
|
219
|
+
const tableCell = api.shouldReservePosition
|
|
220
|
+
? { type: ast.TableCellType, position: cell.position, children }
|
|
221
|
+
: { type: ast.TableCellType, children };
|
|
222
|
+
return tableCell;
|
|
223
|
+
});
|
|
224
|
+
const tableRow = api.shouldReservePosition
|
|
225
|
+
? { type: ast.TableRowType, position: row.position, children: tableCells }
|
|
226
|
+
: { type: ast.TableRowType, children: tableCells };
|
|
227
|
+
return tableRow;
|
|
228
|
+
});
|
|
229
|
+
const table = api.shouldReservePosition
|
|
230
|
+
? { type: ast.TableType, position: token.position, columns: token.columns, children: tableRows }
|
|
231
|
+
: { type: ast.TableType, columns: token.columns, children: tableRows };
|
|
232
|
+
return table;
|
|
233
|
+
}),
|
|
254
234
|
});
|
|
255
235
|
|
|
256
236
|
const uniqueName = '@yozora/tokenizer-table';
|
package/lib/esm/index.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { TableType, TableCellType, TableRowType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, isWhitespaceCharacter } from '@yozora/character';
|
|
3
|
-
import {
|
|
3
|
+
import { calcStartPoint, calcEndPoint, mergeAndStripContentLines, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
4
4
|
|
|
5
5
|
const match = function (api) {
|
|
6
|
-
const { name: _tokenizer } = this;
|
|
7
6
|
return {
|
|
8
7
|
isContainingBlock: false,
|
|
9
8
|
eatOpener,
|
|
@@ -99,11 +98,11 @@ const match = function (api) {
|
|
|
99
98
|
const token = {
|
|
100
99
|
nodeType: TableType,
|
|
101
100
|
position: {
|
|
102
|
-
start:
|
|
103
|
-
end:
|
|
101
|
+
start: calcStartPoint(previousLine.nodePoints, previousLine.startIndex),
|
|
102
|
+
end: calcEndPoint(nodePoints, nextIndex - 1),
|
|
104
103
|
},
|
|
105
104
|
columns,
|
|
106
|
-
|
|
105
|
+
rows: [row],
|
|
107
106
|
};
|
|
108
107
|
return {
|
|
109
108
|
token,
|
|
@@ -115,11 +114,10 @@ const match = function (api) {
|
|
|
115
114
|
if (line.firstNonWhitespaceIndex >= line.endIndex) {
|
|
116
115
|
return { status: 'notMatched' };
|
|
117
116
|
}
|
|
118
|
-
const
|
|
119
|
-
const row = calcTableRow(line, tableToken.columns);
|
|
117
|
+
const row = calcTableRow(line, token.columns);
|
|
120
118
|
if (row == null)
|
|
121
119
|
return { status: 'notMatched' };
|
|
122
|
-
|
|
120
|
+
token.rows.push(row);
|
|
123
121
|
return { status: 'opening', nextIndex: line.endIndex };
|
|
124
122
|
}
|
|
125
123
|
function calcTableRow(line, columns) {
|
|
@@ -135,9 +133,7 @@ const match = function (api) {
|
|
|
135
133
|
if (!isWhitespaceCharacter(p.codePoint))
|
|
136
134
|
break;
|
|
137
135
|
}
|
|
138
|
-
const startPoint = i < endIndex
|
|
139
|
-
? calcStartYastNodePoint(nodePoints, i)
|
|
140
|
-
: calcEndYastNodePoint(nodePoints, endIndex - 1);
|
|
136
|
+
const startPoint = i < endIndex ? calcStartPoint(nodePoints, i) : calcEndPoint(nodePoints, endIndex - 1);
|
|
141
137
|
const cellStartIndex = i, cellFirstNonWhitespaceIndex = i;
|
|
142
138
|
for (; i < endIndex; ++i) {
|
|
143
139
|
p = nodePoints[i];
|
|
@@ -154,10 +150,10 @@ const match = function (api) {
|
|
|
154
150
|
if (!isWhitespaceCharacter(p.codePoint))
|
|
155
151
|
break;
|
|
156
152
|
}
|
|
157
|
-
const endPoint =
|
|
158
|
-
const
|
|
159
|
-
?
|
|
160
|
-
:
|
|
153
|
+
const endPoint = calcEndPoint(nodePoints, i - 1);
|
|
154
|
+
const lines = cellFirstNonWhitespaceIndex >= cellEndIndex
|
|
155
|
+
? []
|
|
156
|
+
: [
|
|
161
157
|
{
|
|
162
158
|
nodePoints,
|
|
163
159
|
startIndex: cellStartIndex,
|
|
@@ -165,88 +161,72 @@ const match = function (api) {
|
|
|
165
161
|
firstNonWhitespaceIndex: cellFirstNonWhitespaceIndex,
|
|
166
162
|
countOfPrecedeSpaces: cellFirstNonWhitespaceIndex - cellStartIndex,
|
|
167
163
|
},
|
|
168
|
-
]
|
|
164
|
+
];
|
|
169
165
|
const cell = {
|
|
170
|
-
_tokenizer,
|
|
171
166
|
nodeType: TableCellType,
|
|
172
167
|
position: { start: startPoint, end: endPoint },
|
|
173
|
-
|
|
168
|
+
lines: lines,
|
|
174
169
|
};
|
|
175
170
|
cells.push(cell);
|
|
176
171
|
if (cells.length >= columns.length)
|
|
177
172
|
break;
|
|
178
173
|
}
|
|
179
|
-
const startPoint =
|
|
180
|
-
const endPoint =
|
|
174
|
+
const startPoint = calcStartPoint(nodePoints, startIndex);
|
|
175
|
+
const endPoint = calcEndPoint(nodePoints, endIndex - 1);
|
|
181
176
|
for (let c = cells.length; c < columns.length; ++c) {
|
|
182
177
|
const cell = {
|
|
183
|
-
_tokenizer,
|
|
184
178
|
nodeType: TableCellType,
|
|
185
179
|
position: { start: Object.assign({}, endPoint), end: Object.assign({}, endPoint) },
|
|
186
|
-
|
|
180
|
+
lines: [],
|
|
187
181
|
};
|
|
188
182
|
cells.push(cell);
|
|
189
183
|
}
|
|
190
184
|
const row = {
|
|
191
|
-
_tokenizer,
|
|
192
185
|
nodeType: TableRowType,
|
|
193
186
|
position: { start: startPoint, end: endPoint },
|
|
194
|
-
|
|
187
|
+
cells,
|
|
195
188
|
};
|
|
196
189
|
return row;
|
|
197
190
|
}
|
|
198
191
|
};
|
|
199
192
|
|
|
200
|
-
const parse =
|
|
201
|
-
parse: (token
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
};
|
|
210
|
-
break;
|
|
211
|
-
}
|
|
212
|
-
case TableRowType: {
|
|
213
|
-
node = {
|
|
214
|
-
type: TableRowType,
|
|
215
|
-
children: children,
|
|
216
|
-
};
|
|
217
|
-
break;
|
|
218
|
-
}
|
|
219
|
-
case TableCellType: {
|
|
220
|
-
node = {
|
|
221
|
-
type: TableCellType,
|
|
222
|
-
children: children,
|
|
223
|
-
};
|
|
224
|
-
for (const phrasingContent of node.children) {
|
|
225
|
-
if (phrasingContent.type !== PhrasingContentType)
|
|
226
|
-
continue;
|
|
227
|
-
const nextContents = [];
|
|
228
|
-
const endIndex = phrasingContent.contents.length;
|
|
229
|
-
for (let i = 0; i < endIndex; ++i) {
|
|
230
|
-
const p = phrasingContent.contents[i];
|
|
193
|
+
const parse = api => ({
|
|
194
|
+
parse: tokens => tokens.map(token => {
|
|
195
|
+
const tableRows = token.rows.map((row) => {
|
|
196
|
+
const tableCells = row.cells.map((cell) => {
|
|
197
|
+
const contents = [];
|
|
198
|
+
{
|
|
199
|
+
const nodePoints = mergeAndStripContentLines(cell.lines);
|
|
200
|
+
for (let i = 0, endIndex = nodePoints.length; i < endIndex; ++i) {
|
|
201
|
+
const p = nodePoints[i];
|
|
231
202
|
if (p.codePoint === AsciiCodePoint.BACKSLASH && i + 1 < endIndex) {
|
|
232
|
-
const q =
|
|
203
|
+
const q = nodePoints[i + 1];
|
|
233
204
|
if (q.codePoint !== AsciiCodePoint.VERTICAL_SLASH)
|
|
234
|
-
|
|
235
|
-
|
|
205
|
+
contents.push(p);
|
|
206
|
+
contents.push(q);
|
|
236
207
|
i += 1;
|
|
237
|
-
continue;
|
|
238
208
|
}
|
|
239
|
-
|
|
209
|
+
else {
|
|
210
|
+
contents.push(p);
|
|
211
|
+
}
|
|
240
212
|
}
|
|
241
|
-
phrasingContent.contents = nextContents;
|
|
242
213
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
214
|
+
const children = api.processInlines(contents);
|
|
215
|
+
const tableCell = api.shouldReservePosition
|
|
216
|
+
? { type: TableCellType, position: cell.position, children }
|
|
217
|
+
: { type: TableCellType, children };
|
|
218
|
+
return tableCell;
|
|
219
|
+
});
|
|
220
|
+
const tableRow = api.shouldReservePosition
|
|
221
|
+
? { type: TableRowType, position: row.position, children: tableCells }
|
|
222
|
+
: { type: TableRowType, children: tableCells };
|
|
223
|
+
return tableRow;
|
|
224
|
+
});
|
|
225
|
+
const table = api.shouldReservePosition
|
|
226
|
+
? { type: TableType, position: token.position, columns: token.columns, children: tableRows }
|
|
227
|
+
: { type: TableType, columns: token.columns, children: tableRows };
|
|
228
|
+
return table;
|
|
229
|
+
}),
|
|
250
230
|
});
|
|
251
231
|
|
|
252
232
|
const uniqueName = '@yozora/tokenizer-table';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { match as tableMatch } from './match';
|
|
|
2
2
|
export { parse as tableParse } from './parse';
|
|
3
3
|
export { TableTokenizer, TableTokenizer as default } from './tokenizer';
|
|
4
4
|
export { uniqueName as TableTokenizerName } from './types';
|
|
5
|
-
export type {
|
|
5
|
+
export type { IThis as ITableHookContext, ITableCellToken, ITableRowToken, IToken as ITableToken, ITokenizerProps as ITableTokenizerProps, } from './types';
|
package/lib/types/match.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
-
import type {
|
|
2
|
+
import type { IThis, IToken, T } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* A table is an arrangement of data with rows and columns, consisting of
|
|
5
5
|
* a single header row, a delimiter row separating the header from the data,
|
|
@@ -15,7 +15,7 @@ import type { IHookContext, IToken, T } from './types';
|
|
|
15
15
|
* @see https://github.com/syntax-tree/mdast#tablerow
|
|
16
16
|
* @see https://github.com/syntax-tree/mdast#tablecell
|
|
17
17
|
*/
|
|
18
|
-
export declare const match: IMatchBlockHookCreator<T, IToken,
|
|
18
|
+
export declare const match: IMatchBlockHookCreator<T, IToken, IThis>;
|
|
19
19
|
/**
|
|
20
20
|
* Find delimiter row
|
|
21
21
|
*
|
package/lib/types/parse.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const parse: IParseBlockHookCreator<T, IToken, INode,
|
|
2
|
+
import type { INode, IThis, IToken, T } from './types';
|
|
3
|
+
export declare const parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
package/lib/types/tokenizer.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
|
|
2
2
|
import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
|
|
3
|
-
import type {
|
|
3
|
+
import type { INode, IThis, IToken, ITokenizerProps, T } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Lexical Analyzer for Table, table-row and table-cell.
|
|
6
6
|
* @see https://github.github.com/gfm/#table
|
|
7
7
|
* @see https://github.com/syntax-tree/mdast#tablerow
|
|
8
8
|
* @see https://github.com/syntax-tree/mdast#tablecell
|
|
9
9
|
*/
|
|
10
|
-
export declare class TableTokenizer extends BaseBlockTokenizer<T, IToken, INode,
|
|
10
|
+
export declare class TableTokenizer extends BaseBlockTokenizer<T, IToken, INode, IThis> implements IBlockTokenizer<T, IToken, INode, IThis> {
|
|
11
11
|
constructor(props?: ITokenizerProps);
|
|
12
|
-
readonly match: IMatchBlockHookCreator<T, IToken,
|
|
13
|
-
readonly parse: IParseBlockHookCreator<T, IToken, INode,
|
|
12
|
+
readonly match: IMatchBlockHookCreator<T, IToken, IThis>;
|
|
13
|
+
readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
|
|
14
14
|
}
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken,
|
|
3
|
-
export declare type T = TableType
|
|
4
|
-
export declare type INode =
|
|
5
|
-
export declare type IToken = ITableToken | ITableRowToken | ITableCellToken;
|
|
1
|
+
import type { Position, Table, TableCellType, TableColumn, TableRowType, TableType } from '@yozora/ast';
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentLine, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
|
+
export declare type T = TableType;
|
|
4
|
+
export declare type INode = Table;
|
|
6
5
|
export declare const uniqueName = "@yozora/tokenizer-table";
|
|
7
|
-
export interface
|
|
6
|
+
export interface IToken extends IPartialYastBlockToken<TableType> {
|
|
8
7
|
/**
|
|
9
8
|
* Table column configuration items
|
|
10
9
|
*/
|
|
11
|
-
columns:
|
|
10
|
+
columns: TableColumn[];
|
|
12
11
|
/**
|
|
13
12
|
* Table rows
|
|
14
13
|
*/
|
|
15
|
-
|
|
14
|
+
rows: ITableRowToken[];
|
|
16
15
|
}
|
|
17
|
-
export
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
children: ITableCellToken[];
|
|
16
|
+
export declare type IThis = ITokenizer;
|
|
17
|
+
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
|
18
|
+
export interface ITableRowToken extends IPartialYastBlockToken<TableRowType> {
|
|
19
|
+
cells: ITableCellToken[];
|
|
22
20
|
}
|
|
23
|
-
export interface ITableCellToken extends
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
*/
|
|
27
|
-
children: IPhrasingContentToken[];
|
|
21
|
+
export interface ITableCellToken extends IPartialYastBlockToken<TableCellType> {
|
|
22
|
+
position: Position;
|
|
23
|
+
lines: IPhrasingContentLine[];
|
|
28
24
|
}
|
|
29
|
-
export declare type IHookContext = ITokenizer;
|
|
30
|
-
export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-table",
|
|
3
|
-
"version": "2.0.0
|
|
3
|
+
"version": "2.0.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": "^2.0.0
|
|
39
|
-
"@yozora/character": "^2.0.0
|
|
40
|
-
"@yozora/core-tokenizer": "^2.0.0
|
|
38
|
+
"@yozora/ast": "^2.0.0",
|
|
39
|
+
"@yozora/character": "^2.0.0",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "65e99d1709fdd1c918465dce6b1e91de96bdab5e"
|
|
43
43
|
}
|