@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 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 phrasingContent = cellFirstNonWhitespaceIndex >= cellEndIndex
162
- ? null
163
- : api.buildPhrasingContentToken([
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
- contents: phrasingContent == null ? [] : [phrasingContent],
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
- contents: [],
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 = cell.contents ? api.parseBlockTokens(cell.contents) : [];
208
- for (const phrasingContent of contents) {
209
- if (phrasingContent.type !== coreTokenizer.PhrasingContentType)
210
- continue;
211
- const nextContents = [];
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 = phrasingContent.contents[i + 1];
213
+ const q = nodePoints[i + 1];
217
214
  if (q.codePoint !== character.AsciiCodePoint.VERTICAL_SLASH)
218
- nextContents.push(p);
219
- nextContents.push(q);
215
+ contents.push(p);
216
+ contents.push(q);
220
217
  i += 1;
221
- continue;
222
218
  }
223
- nextContents.push(p);
219
+ else {
220
+ contents.push(p);
221
+ }
224
222
  }
225
- phrasingContent.contents = nextContents;
226
223
  }
227
- const tableCell = {
228
- type: ast.TableCellType,
229
- position: cell.position,
230
- children: contents,
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
- position: row.position,
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
- position: token.position,
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, PhrasingContentType, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
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 phrasingContent = cellFirstNonWhitespaceIndex >= cellEndIndex
158
- ? null
159
- : api.buildPhrasingContentToken([
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
- contents: phrasingContent == null ? [] : [phrasingContent],
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
- contents: [],
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 = cell.contents ? api.parseBlockTokens(cell.contents) : [];
204
- for (const phrasingContent of contents) {
205
- if (phrasingContent.type !== PhrasingContentType)
206
- continue;
207
- const nextContents = [];
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 = phrasingContent.contents[i + 1];
209
+ const q = nodePoints[i + 1];
213
210
  if (q.codePoint !== AsciiCodePoint.VERTICAL_SLASH)
214
- nextContents.push(p);
215
- nextContents.push(q);
211
+ contents.push(p);
212
+ contents.push(q);
216
213
  i += 1;
217
- continue;
218
214
  }
219
- nextContents.push(p);
215
+ else {
216
+ contents.push(p);
217
+ }
220
218
  }
221
- phrasingContent.contents = nextContents;
222
219
  }
223
- const tableCell = {
224
- type: TableCellType,
225
- position: cell.position,
226
- children: contents,
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
- position: row.position,
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
- position: token.position,
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
  });
@@ -1,5 +1,5 @@
1
1
  import type { ITable, ITableColumn, IYastNodePosition, TableCellType, TableRowType, TableType } from '@yozora/ast';
2
- import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentToken, ITokenizer } from '@yozora/core-tokenizer';
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
- contents: IPhrasingContentToken[];
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.1",
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.1",
39
- "@yozora/character": "^2.0.0-alpha.1",
40
- "@yozora/core-tokenizer": "^2.0.0-alpha.1"
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": "86202e1d2b03ccfc2ab030517d9d314f7aee7666"
42
+ "gitHead": "da59d85520455c59a117a35032ef1a035c10ea21"
43
43
  }