@yozora/tokenizer-break 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 CHANGED
@@ -84,14 +84,14 @@ so you can use `YozoraParser` / `GfmExParser` / `GfmParser` directly.
84
84
  registered in *YastParser* as a plugin-in before it can be used.
85
85
 
86
86
  ```typescript {4,9}
87
- import { DefaultYastParser } from '@yozora/core-parser'
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 BreakTokenizer from '@yozora/tokenizer-break'
91
91
 
92
- const parser = new DefaultYastParser()
93
- .useBlockFallbackTokenizer(new ParagraphTokenizer())
94
- .useInlineFallbackTokenizer(new TextTokenizer())
92
+ const parser = new DefaultParser()
93
+ .useFallbackTokenizer(new ParagraphTokenizer())
94
+ .useFallbackTokenizer(new TextTokenizer())
95
95
  .useTokenizer(new BreakTokenizer())
96
96
 
97
97
  // parse source markdown content
@@ -250,7 +250,6 @@ Name | Type | Required | Default
250
250
  [@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
251
251
  [@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
252
252
  [@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
253
- [@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
254
253
  [@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
255
254
  [@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
256
255
  [@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
@@ -310,7 +309,6 @@ Name | Type | Required | Default
310
309
  [doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
311
310
  [doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
312
311
  [doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
313
- [doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
314
312
  [doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
315
313
  [doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
316
314
  [doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
package/lib/cjs/index.js CHANGED
@@ -13,78 +13,91 @@ var BreakTokenMarkerType;
13
13
  BreakTokenMarkerType["MORE_THAN_TWO_SPACES"] = "more-than-two-spaces";
14
14
  })(BreakTokenMarkerType || (BreakTokenMarkerType = {}));
15
15
 
16
- class BreakTokenizer extends coreTokenizer.BaseInlineTokenizer {
17
- constructor(props = {}) {
18
- var _a, _b;
19
- super({
20
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
21
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.SOFT_INLINE,
22
- });
23
- this.match = api => {
24
- return {
25
- findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
26
- processSingleDelimiter,
27
- };
28
- function _findDelimiter(startIndex, endIndex) {
29
- const nodePoints = api.getNodePoints();
30
- for (let i = startIndex + 1; i < endIndex; ++i) {
31
- if (nodePoints[i].codePoint !== character.VirtualCodePoint.LINE_END)
32
- continue;
33
- const c = nodePoints[i - 1].codePoint;
34
- let _start = null;
35
- let markerType = null;
36
- switch (c) {
37
- case character.AsciiCodePoint.BACKSLASH: {
38
- let x = i - 2;
39
- for (; x >= startIndex; x -= 1) {
40
- if (nodePoints[x].codePoint !== character.AsciiCodePoint.BACKSLASH)
41
- break;
42
- }
43
- if (((i - x) & 1) === 0) {
44
- _start = i - 1;
45
- markerType = BreakTokenMarkerType.BACKSLASH;
46
- }
16
+ const match = function (api) {
17
+ return {
18
+ findDelimiter: () => coreTokenizer.genFindDelimiter(_findDelimiter),
19
+ processSingleDelimiter,
20
+ };
21
+ function _findDelimiter(startIndex, endIndex) {
22
+ const nodePoints = api.getNodePoints();
23
+ for (let i = startIndex + 1; i < endIndex; ++i) {
24
+ if (nodePoints[i].codePoint !== character.VirtualCodePoint.LINE_END)
25
+ continue;
26
+ const c = nodePoints[i - 1].codePoint;
27
+ let _start = null;
28
+ let markerType = null;
29
+ switch (c) {
30
+ case character.AsciiCodePoint.BACKSLASH: {
31
+ let x = i - 2;
32
+ for (; x >= startIndex; x -= 1) {
33
+ if (nodePoints[x].codePoint !== character.AsciiCodePoint.BACKSLASH)
47
34
  break;
48
- }
49
- case character.AsciiCodePoint.SPACE: {
50
- let x = i - 2;
51
- for (; x >= startIndex; x -= 1) {
52
- if (nodePoints[x].codePoint !== character.AsciiCodePoint.SPACE)
53
- break;
54
- }
55
- if (i - x > 2) {
56
- _start = x + 1;
57
- markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
58
- }
35
+ }
36
+ if (((i - x) & 1) === 0) {
37
+ _start = i - 1;
38
+ markerType = BreakTokenMarkerType.BACKSLASH;
39
+ }
40
+ break;
41
+ }
42
+ case character.AsciiCodePoint.SPACE: {
43
+ let x = i - 2;
44
+ for (; x >= startIndex; x -= 1) {
45
+ if (nodePoints[x].codePoint !== character.AsciiCodePoint.SPACE)
59
46
  break;
60
- }
61
47
  }
62
- if (_start == null || markerType == null)
63
- continue;
64
- return {
65
- type: 'full',
66
- markerType,
67
- startIndex: _start,
68
- endIndex: i,
69
- };
48
+ if (i - x > 2) {
49
+ _start = x + 1;
50
+ markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
51
+ }
52
+ break;
70
53
  }
71
- return null;
72
- }
73
- function processSingleDelimiter(delimiter) {
74
- const token = {
75
- nodeType: ast.BreakType,
76
- startIndex: delimiter.startIndex,
77
- endIndex: delimiter.endIndex,
78
- };
79
- return [token];
80
54
  }
55
+ if (_start == null || markerType == null)
56
+ continue;
57
+ return {
58
+ type: 'full',
59
+ markerType,
60
+ startIndex: _start,
61
+ endIndex: i,
62
+ };
63
+ }
64
+ return null;
65
+ }
66
+ function processSingleDelimiter(delimiter) {
67
+ const token = {
68
+ nodeType: ast.BreakType,
69
+ startIndex: delimiter.startIndex,
70
+ endIndex: delimiter.endIndex,
81
71
  };
82
- this.parse = () => ({
83
- parse: () => ({ type: ast.BreakType }),
72
+ return [token];
73
+ }
74
+ };
75
+
76
+ const parse = function (api) {
77
+ return {
78
+ parse: tokens => tokens.map(token => {
79
+ const node = api.shouldReservePosition
80
+ ? { type: ast.BreakType, position: api.calcPosition(token) }
81
+ : { type: ast.BreakType };
82
+ return node;
83
+ }),
84
+ };
85
+ };
86
+
87
+ class BreakTokenizer extends coreTokenizer.BaseInlineTokenizer {
88
+ constructor(props = {}) {
89
+ var _a, _b;
90
+ super({
91
+ name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
92
+ priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.SOFT_INLINE,
84
93
  });
94
+ this.match = match;
95
+ this.parse = parse;
85
96
  }
86
97
  }
87
98
 
88
99
  exports.BreakTokenizer = BreakTokenizer;
89
100
  exports.BreakTokenizerName = uniqueName;
101
+ exports.breakMatch = match;
102
+ exports.breakParse = parse;
90
103
  exports["default"] = BreakTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { BreakType } from '@yozora/ast';
2
2
  import { VirtualCodePoint, AsciiCodePoint } from '@yozora/character';
3
- import { BaseInlineTokenizer, TokenizerPriority, genFindDelimiter } from '@yozora/core-tokenizer';
3
+ import { genFindDelimiter, BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
4
4
 
5
5
  const uniqueName = '@yozora/tokenizer-break';
6
6
  var BreakTokenMarkerType;
@@ -9,76 +9,87 @@ var BreakTokenMarkerType;
9
9
  BreakTokenMarkerType["MORE_THAN_TWO_SPACES"] = "more-than-two-spaces";
10
10
  })(BreakTokenMarkerType || (BreakTokenMarkerType = {}));
11
11
 
12
- class BreakTokenizer extends BaseInlineTokenizer {
13
- constructor(props = {}) {
14
- var _a, _b;
15
- super({
16
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
17
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.SOFT_INLINE,
18
- });
19
- this.match = api => {
20
- return {
21
- findDelimiter: () => genFindDelimiter(_findDelimiter),
22
- processSingleDelimiter,
23
- };
24
- function _findDelimiter(startIndex, endIndex) {
25
- const nodePoints = api.getNodePoints();
26
- for (let i = startIndex + 1; i < endIndex; ++i) {
27
- if (nodePoints[i].codePoint !== VirtualCodePoint.LINE_END)
28
- continue;
29
- const c = nodePoints[i - 1].codePoint;
30
- let _start = null;
31
- let markerType = null;
32
- switch (c) {
33
- case AsciiCodePoint.BACKSLASH: {
34
- let x = i - 2;
35
- for (; x >= startIndex; x -= 1) {
36
- if (nodePoints[x].codePoint !== AsciiCodePoint.BACKSLASH)
37
- break;
38
- }
39
- if (((i - x) & 1) === 0) {
40
- _start = i - 1;
41
- markerType = BreakTokenMarkerType.BACKSLASH;
42
- }
12
+ const match = function (api) {
13
+ return {
14
+ findDelimiter: () => genFindDelimiter(_findDelimiter),
15
+ processSingleDelimiter,
16
+ };
17
+ function _findDelimiter(startIndex, endIndex) {
18
+ const nodePoints = api.getNodePoints();
19
+ for (let i = startIndex + 1; i < endIndex; ++i) {
20
+ if (nodePoints[i].codePoint !== VirtualCodePoint.LINE_END)
21
+ continue;
22
+ const c = nodePoints[i - 1].codePoint;
23
+ let _start = null;
24
+ let markerType = null;
25
+ switch (c) {
26
+ case AsciiCodePoint.BACKSLASH: {
27
+ let x = i - 2;
28
+ for (; x >= startIndex; x -= 1) {
29
+ if (nodePoints[x].codePoint !== AsciiCodePoint.BACKSLASH)
43
30
  break;
44
- }
45
- case AsciiCodePoint.SPACE: {
46
- let x = i - 2;
47
- for (; x >= startIndex; x -= 1) {
48
- if (nodePoints[x].codePoint !== AsciiCodePoint.SPACE)
49
- break;
50
- }
51
- if (i - x > 2) {
52
- _start = x + 1;
53
- markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
54
- }
31
+ }
32
+ if (((i - x) & 1) === 0) {
33
+ _start = i - 1;
34
+ markerType = BreakTokenMarkerType.BACKSLASH;
35
+ }
36
+ break;
37
+ }
38
+ case AsciiCodePoint.SPACE: {
39
+ let x = i - 2;
40
+ for (; x >= startIndex; x -= 1) {
41
+ if (nodePoints[x].codePoint !== AsciiCodePoint.SPACE)
55
42
  break;
56
- }
57
43
  }
58
- if (_start == null || markerType == null)
59
- continue;
60
- return {
61
- type: 'full',
62
- markerType,
63
- startIndex: _start,
64
- endIndex: i,
65
- };
44
+ if (i - x > 2) {
45
+ _start = x + 1;
46
+ markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES;
47
+ }
48
+ break;
66
49
  }
67
- return null;
68
- }
69
- function processSingleDelimiter(delimiter) {
70
- const token = {
71
- nodeType: BreakType,
72
- startIndex: delimiter.startIndex,
73
- endIndex: delimiter.endIndex,
74
- };
75
- return [token];
76
50
  }
51
+ if (_start == null || markerType == null)
52
+ continue;
53
+ return {
54
+ type: 'full',
55
+ markerType,
56
+ startIndex: _start,
57
+ endIndex: i,
58
+ };
59
+ }
60
+ return null;
61
+ }
62
+ function processSingleDelimiter(delimiter) {
63
+ const token = {
64
+ nodeType: BreakType,
65
+ startIndex: delimiter.startIndex,
66
+ endIndex: delimiter.endIndex,
77
67
  };
78
- this.parse = () => ({
79
- parse: () => ({ type: BreakType }),
68
+ return [token];
69
+ }
70
+ };
71
+
72
+ const parse = function (api) {
73
+ return {
74
+ parse: tokens => tokens.map(token => {
75
+ const node = api.shouldReservePosition
76
+ ? { type: BreakType, position: api.calcPosition(token) }
77
+ : { type: BreakType };
78
+ return node;
79
+ }),
80
+ };
81
+ };
82
+
83
+ class BreakTokenizer extends BaseInlineTokenizer {
84
+ constructor(props = {}) {
85
+ var _a, _b;
86
+ super({
87
+ name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
88
+ priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.SOFT_INLINE,
80
89
  });
90
+ this.match = match;
91
+ this.parse = parse;
81
92
  }
82
93
  }
83
94
 
84
- export { BreakTokenizer, uniqueName as BreakTokenizerName, BreakTokenizer as default };
95
+ export { BreakTokenizer, uniqueName as BreakTokenizerName, match as breakMatch, parse as breakParse, BreakTokenizer as default };
@@ -1,3 +1,5 @@
1
+ export { match as breakMatch } from './match';
2
+ export { parse as breakParse } from './parse';
1
3
  export { BreakTokenizer, BreakTokenizer as default } from './tokenizer';
2
4
  export { uniqueName as BreakTokenizerName } from './types';
3
- export type { IToken as IBreakToken, ITokenizerProps as IBreakTokenizerProps } from './types';
5
+ export type { IThis as IBreakHookContext, IToken as IBreakToken, ITokenizerProps as IBreakTokenizerProps, } from './types';
@@ -0,0 +1,17 @@
1
+ import type { IMatchInlineHookCreator } from '@yozora/core-tokenizer';
2
+ import type { IDelimiter, IThis, IToken, T } from './types';
3
+ /**
4
+ * A line break (not in a code span or HTML tag) that is preceded by two or more
5
+ * spaces and does not occur at the end of a block is parsed as a hard line
6
+ * break (rendered in HTML as a <br /> tag)
7
+ * @see https://github.github.com/gfm/#hard-line-breaks
8
+ *
9
+ * A regular line break (not in a code span or HTML tag) that is not preceded
10
+ * by two or more spaces or a backslash is parsed as a softbreak. (A softbreak
11
+ * may be rendered in HTML either as a line ending or as a space. The result
12
+ * will be the same in browsers.
13
+ * @see https://github.github.com/gfm/#soft-line-breaks
14
+ *
15
+ * @see https://github.com/syntax-tree/mdast#break
16
+ */
17
+ export declare const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
@@ -0,0 +1,3 @@
1
+ import type { IParseInlineHookCreator } from '@yozora/core-tokenizer';
2
+ import type { INode, IThis, IToken, T } from './types';
3
+ export declare const parse: IParseInlineHookCreator<T, IToken, INode, IThis>;
@@ -1,24 +1,14 @@
1
1
  import type { IInlineTokenizer, IMatchInlineHookCreator, IParseInlineHookCreator } from '@yozora/core-tokenizer';
2
2
  import { BaseInlineTokenizer } from '@yozora/core-tokenizer';
3
- import type { IDelimiter, INode, IToken, ITokenizerProps, T } from './types';
3
+ import type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types';
4
4
  /**
5
5
  * Lexical Analyzer for a line break.
6
- *
7
- * A line break (not in a code span or HTML tag) that is preceded by two or more
8
- * spaces and does not occur at the end of a block is parsed as a hard line
9
- * break (rendered in HTML as a <br /> tag)
10
6
  * @see https://github.github.com/gfm/#hard-line-breaks
11
- *
12
- * A regular line break (not in a code span or HTML tag) that is not preceded
13
- * by two or more spaces or a backslash is parsed as a softbreak. (A softbreak
14
- * may be rendered in HTML either as a line ending or as a space. The result
15
- * will be the same in browsers.
16
7
  * @see https://github.github.com/gfm/#soft-line-breaks
17
- *
18
8
  * @see https://github.com/syntax-tree/mdast#break
19
9
  */
20
- export declare class BreakTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode> implements IInlineTokenizer<T, IDelimiter, IToken, INode> {
10
+ export declare class BreakTokenizer extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis> implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis> {
21
11
  constructor(props?: ITokenizerProps);
22
- readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken>;
23
- readonly parse: IParseInlineHookCreator<T, IToken, INode>;
12
+ readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis>;
13
+ readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis>;
24
14
  }
@@ -1,7 +1,7 @@
1
- import type { BreakType, IBreak } from '@yozora/ast';
2
- import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, IYastTokenDelimiter } from '@yozora/core-tokenizer';
1
+ import type { Break, BreakType } from '@yozora/ast';
2
+ import type { IBaseInlineTokenizerProps, IPartialYastInlineToken, ITokenizer, IYastTokenDelimiter } from '@yozora/core-tokenizer';
3
3
  export declare type T = BreakType;
4
- export declare type INode = IBreak;
4
+ export declare type INode = Break;
5
5
  export declare const uniqueName = "@yozora/tokenizer-break";
6
6
  export declare type IToken = IPartialYastInlineToken<T>;
7
7
  export interface IDelimiter extends IYastTokenDelimiter {
@@ -11,6 +11,7 @@ export interface IDelimiter extends IYastTokenDelimiter {
11
11
  */
12
12
  markerType: BreakTokenMarkerType;
13
13
  }
14
+ export declare type IThis = ITokenizer;
14
15
  export declare type ITokenizerProps = Partial<IBaseInlineTokenizerProps>;
15
16
  /**
16
17
  * Line break marker type.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-break",
3
- "version": "2.0.0-alpha.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-alpha.0",
39
- "@yozora/character": "^2.0.0-alpha.0",
40
- "@yozora/core-tokenizer": "^2.0.0-alpha.0"
38
+ "@yozora/ast": "^2.0.0",
39
+ "@yozora/character": "^2.0.0",
40
+ "@yozora/core-tokenizer": "^2.0.0"
41
41
  },
42
- "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
42
+ "gitHead": "65e99d1709fdd1c918465dce6b1e91de96bdab5e"
43
43
  }