@yozora/tokenizer-table 2.0.0-alpha.1 → 2.0.0-alpha.2
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 +27 -36
- package/lib/esm/index.js +28 -37
- package/lib/types/types.d.ts +2 -2
- package/package.json +5 -5
package/lib/cjs/index.js
CHANGED
|
@@ -158,9 +158,9 @@ const match = function (api) {
|
|
|
158
158
|
break;
|
|
159
159
|
}
|
|
160
160
|
const endPoint = coreTokenizer.calcEndYastNodePoint(nodePoints, i - 1);
|
|
161
|
-
const
|
|
162
|
-
?
|
|
163
|
-
:
|
|
161
|
+
const lines = cellFirstNonWhitespaceIndex >= cellEndIndex
|
|
162
|
+
? []
|
|
163
|
+
: [
|
|
164
164
|
{
|
|
165
165
|
nodePoints,
|
|
166
166
|
startIndex: cellStartIndex,
|
|
@@ -168,12 +168,12 @@ const match = function (api) {
|
|
|
168
168
|
firstNonWhitespaceIndex: cellFirstNonWhitespaceIndex,
|
|
169
169
|
countOfPrecedeSpaces: cellFirstNonWhitespaceIndex - cellStartIndex,
|
|
170
170
|
},
|
|
171
|
-
]
|
|
171
|
+
];
|
|
172
172
|
const cell = {
|
|
173
173
|
_tokenizer,
|
|
174
174
|
nodeType: ast.TableCellType,
|
|
175
175
|
position: { start: startPoint, end: endPoint },
|
|
176
|
-
|
|
176
|
+
lines: lines,
|
|
177
177
|
};
|
|
178
178
|
cells.push(cell);
|
|
179
179
|
if (cells.length >= columns.length)
|
|
@@ -186,7 +186,7 @@ const match = function (api) {
|
|
|
186
186
|
_tokenizer,
|
|
187
187
|
nodeType: ast.TableCellType,
|
|
188
188
|
position: { start: Object.assign({}, endPoint), end: Object.assign({}, endPoint) },
|
|
189
|
-
|
|
189
|
+
lines: [],
|
|
190
190
|
};
|
|
191
191
|
cells.push(cell);
|
|
192
192
|
}
|
|
@@ -204,46 +204,37 @@ const parse = api => ({
|
|
|
204
204
|
parse: tokens => tokens.map(token => {
|
|
205
205
|
const tableRows = token.rows.map((row) => {
|
|
206
206
|
const tableCells = row.cells.map((cell) => {
|
|
207
|
-
const contents =
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const endIndex = phrasingContent.contents.length;
|
|
213
|
-
for (let i = 0; i < endIndex; ++i) {
|
|
214
|
-
const p = phrasingContent.contents[i];
|
|
207
|
+
const contents = [];
|
|
208
|
+
{
|
|
209
|
+
const nodePoints = coreTokenizer.mergeAndStripContentLines(cell.lines);
|
|
210
|
+
for (let i = 0, endIndex = nodePoints.length; i < endIndex; ++i) {
|
|
211
|
+
const p = nodePoints[i];
|
|
215
212
|
if (p.codePoint === character.AsciiCodePoint.BACKSLASH && i + 1 < endIndex) {
|
|
216
|
-
const q =
|
|
213
|
+
const q = nodePoints[i + 1];
|
|
217
214
|
if (q.codePoint !== character.AsciiCodePoint.VERTICAL_SLASH)
|
|
218
|
-
|
|
219
|
-
|
|
215
|
+
contents.push(p);
|
|
216
|
+
contents.push(q);
|
|
220
217
|
i += 1;
|
|
221
|
-
continue;
|
|
222
218
|
}
|
|
223
|
-
|
|
219
|
+
else {
|
|
220
|
+
contents.push(p);
|
|
221
|
+
}
|
|
224
222
|
}
|
|
225
|
-
phrasingContent.contents = nextContents;
|
|
226
223
|
}
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
position: cell.position,
|
|
230
|
-
|
|
231
|
-
};
|
|
224
|
+
const children = api.processInlines(contents);
|
|
225
|
+
const tableCell = api.shouldReservePosition
|
|
226
|
+
? { type: ast.TableCellType, position: cell.position, children }
|
|
227
|
+
: { type: ast.TableCellType, children };
|
|
232
228
|
return tableCell;
|
|
233
229
|
});
|
|
234
|
-
const tableRow =
|
|
235
|
-
type: ast.TableRowType,
|
|
236
|
-
|
|
237
|
-
children: tableCells,
|
|
238
|
-
};
|
|
230
|
+
const tableRow = api.shouldReservePosition
|
|
231
|
+
? { type: ast.TableRowType, position: row.position, children: tableCells }
|
|
232
|
+
: { type: ast.TableRowType, children: tableCells };
|
|
239
233
|
return tableRow;
|
|
240
234
|
});
|
|
241
|
-
const table =
|
|
242
|
-
type: ast.TableType,
|
|
243
|
-
|
|
244
|
-
columns: token.columns,
|
|
245
|
-
children: tableRows,
|
|
246
|
-
};
|
|
235
|
+
const table = api.shouldReservePosition
|
|
236
|
+
? { type: ast.TableType, position: token.position, columns: token.columns, children: tableRows }
|
|
237
|
+
: { type: ast.TableType, columns: token.columns, children: tableRows };
|
|
247
238
|
return table;
|
|
248
239
|
}),
|
|
249
240
|
});
|
package/lib/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TableType, TableCellType, TableRowType } from '@yozora/ast';
|
|
2
2
|
import { AsciiCodePoint, isWhitespaceCharacter } from '@yozora/character';
|
|
3
|
-
import { calcStartYastNodePoint, calcEndYastNodePoint,
|
|
3
|
+
import { calcStartYastNodePoint, calcEndYastNodePoint, mergeAndStripContentLines, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
|
|
4
4
|
|
|
5
5
|
const match = function (api) {
|
|
6
6
|
const { name: _tokenizer } = this;
|
|
@@ -154,9 +154,9 @@ const match = function (api) {
|
|
|
154
154
|
break;
|
|
155
155
|
}
|
|
156
156
|
const endPoint = calcEndYastNodePoint(nodePoints, i - 1);
|
|
157
|
-
const
|
|
158
|
-
?
|
|
159
|
-
:
|
|
157
|
+
const lines = cellFirstNonWhitespaceIndex >= cellEndIndex
|
|
158
|
+
? []
|
|
159
|
+
: [
|
|
160
160
|
{
|
|
161
161
|
nodePoints,
|
|
162
162
|
startIndex: cellStartIndex,
|
|
@@ -164,12 +164,12 @@ const match = function (api) {
|
|
|
164
164
|
firstNonWhitespaceIndex: cellFirstNonWhitespaceIndex,
|
|
165
165
|
countOfPrecedeSpaces: cellFirstNonWhitespaceIndex - cellStartIndex,
|
|
166
166
|
},
|
|
167
|
-
]
|
|
167
|
+
];
|
|
168
168
|
const cell = {
|
|
169
169
|
_tokenizer,
|
|
170
170
|
nodeType: TableCellType,
|
|
171
171
|
position: { start: startPoint, end: endPoint },
|
|
172
|
-
|
|
172
|
+
lines: lines,
|
|
173
173
|
};
|
|
174
174
|
cells.push(cell);
|
|
175
175
|
if (cells.length >= columns.length)
|
|
@@ -182,7 +182,7 @@ const match = function (api) {
|
|
|
182
182
|
_tokenizer,
|
|
183
183
|
nodeType: TableCellType,
|
|
184
184
|
position: { start: Object.assign({}, endPoint), end: Object.assign({}, endPoint) },
|
|
185
|
-
|
|
185
|
+
lines: [],
|
|
186
186
|
};
|
|
187
187
|
cells.push(cell);
|
|
188
188
|
}
|
|
@@ -200,46 +200,37 @@ const parse = api => ({
|
|
|
200
200
|
parse: tokens => tokens.map(token => {
|
|
201
201
|
const tableRows = token.rows.map((row) => {
|
|
202
202
|
const tableCells = row.cells.map((cell) => {
|
|
203
|
-
const contents =
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const endIndex = phrasingContent.contents.length;
|
|
209
|
-
for (let i = 0; i < endIndex; ++i) {
|
|
210
|
-
const p = phrasingContent.contents[i];
|
|
203
|
+
const contents = [];
|
|
204
|
+
{
|
|
205
|
+
const nodePoints = mergeAndStripContentLines(cell.lines);
|
|
206
|
+
for (let i = 0, endIndex = nodePoints.length; i < endIndex; ++i) {
|
|
207
|
+
const p = nodePoints[i];
|
|
211
208
|
if (p.codePoint === AsciiCodePoint.BACKSLASH && i + 1 < endIndex) {
|
|
212
|
-
const q =
|
|
209
|
+
const q = nodePoints[i + 1];
|
|
213
210
|
if (q.codePoint !== AsciiCodePoint.VERTICAL_SLASH)
|
|
214
|
-
|
|
215
|
-
|
|
211
|
+
contents.push(p);
|
|
212
|
+
contents.push(q);
|
|
216
213
|
i += 1;
|
|
217
|
-
continue;
|
|
218
214
|
}
|
|
219
|
-
|
|
215
|
+
else {
|
|
216
|
+
contents.push(p);
|
|
217
|
+
}
|
|
220
218
|
}
|
|
221
|
-
phrasingContent.contents = nextContents;
|
|
222
219
|
}
|
|
223
|
-
const
|
|
224
|
-
|
|
225
|
-
position: cell.position,
|
|
226
|
-
|
|
227
|
-
};
|
|
220
|
+
const children = api.processInlines(contents);
|
|
221
|
+
const tableCell = api.shouldReservePosition
|
|
222
|
+
? { type: TableCellType, position: cell.position, children }
|
|
223
|
+
: { type: TableCellType, children };
|
|
228
224
|
return tableCell;
|
|
229
225
|
});
|
|
230
|
-
const tableRow =
|
|
231
|
-
type: TableRowType,
|
|
232
|
-
|
|
233
|
-
children: tableCells,
|
|
234
|
-
};
|
|
226
|
+
const tableRow = api.shouldReservePosition
|
|
227
|
+
? { type: TableRowType, position: row.position, children: tableCells }
|
|
228
|
+
: { type: TableRowType, children: tableCells };
|
|
235
229
|
return tableRow;
|
|
236
230
|
});
|
|
237
|
-
const table =
|
|
238
|
-
type: TableType,
|
|
239
|
-
|
|
240
|
-
columns: token.columns,
|
|
241
|
-
children: tableRows,
|
|
242
|
-
};
|
|
231
|
+
const table = api.shouldReservePosition
|
|
232
|
+
? { type: TableType, position: token.position, columns: token.columns, children: tableRows }
|
|
233
|
+
: { type: TableType, columns: token.columns, children: tableRows };
|
|
243
234
|
return table;
|
|
244
235
|
}),
|
|
245
236
|
});
|
package/lib/types/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ITable, ITableColumn, IYastNodePosition, TableCellType, TableRowType, TableType } from '@yozora/ast';
|
|
2
|
-
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken,
|
|
2
|
+
import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentLine, ITokenizer } from '@yozora/core-tokenizer';
|
|
3
3
|
export declare type T = TableType;
|
|
4
4
|
export declare type INode = ITable;
|
|
5
5
|
export declare const uniqueName = "@yozora/tokenizer-table";
|
|
@@ -20,5 +20,5 @@ export interface ITableRowToken extends IPartialYastBlockToken<TableRowType> {
|
|
|
20
20
|
}
|
|
21
21
|
export interface ITableCellToken extends IPartialYastBlockToken<TableCellType> {
|
|
22
22
|
position: IYastNodePosition;
|
|
23
|
-
|
|
23
|
+
lines: IPhrasingContentLine[];
|
|
24
24
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-table",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.2",
|
|
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-alpha.
|
|
39
|
-
"@yozora/character": "^2.0.0-alpha.
|
|
40
|
-
"@yozora/core-tokenizer": "^2.0.0-alpha.
|
|
38
|
+
"@yozora/ast": "^2.0.0-alpha.2",
|
|
39
|
+
"@yozora/character": "^2.0.0-alpha.2",
|
|
40
|
+
"@yozora/core-tokenizer": "^2.0.0-alpha.2"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "da59d85520455c59a117a35032ef1a035c10ea21"
|
|
43
43
|
}
|