@yozora/tokenizer-blockquote 1.2.1 → 2.0.0-alpha.1

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 BlockquoteTokenizer from '@yozora/tokenizer-blockquote'
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 BlockquoteTokenizer())
96
96
 
97
97
  // parse source markdown content
@@ -233,7 +233,6 @@ Name | Type | Required | Default
233
233
  [@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
234
234
  [@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
235
235
  [@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
236
- [@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
237
236
  [@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
238
237
  [@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
239
238
  [@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
@@ -293,7 +292,6 @@ Name | Type | Required | Default
293
292
  [doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
294
293
  [doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
295
294
  [doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
296
- [doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
297
295
  [doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
298
296
  [doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
299
297
  [doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
package/lib/cjs/index.js CHANGED
@@ -6,31 +6,24 @@ var ast = require('@yozora/ast');
6
6
  var character = require('@yozora/character');
7
7
  var coreTokenizer = require('@yozora/core-tokenizer');
8
8
 
9
- const uniqueName = '@yozora/tokenizer-blockquote';
10
-
11
- class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
12
- constructor(props = {}) {
13
- var _a, _b;
14
- super({
15
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
16
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_BLOCK,
17
- });
18
- this.isContainingBlock = true;
19
- }
20
- eatOpener(line) {
9
+ const match = function () {
10
+ return {
11
+ isContainingBlock: true,
12
+ eatOpener,
13
+ eatAndInterruptPreviousSibling,
14
+ eatContinuationText,
15
+ };
16
+ function eatOpener(line) {
21
17
  if (line.countOfPrecedeSpaces >= 4)
22
18
  return null;
23
19
  const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
24
20
  if (firstNonWhitespaceIndex >= endIndex ||
25
- nodePoints[firstNonWhitespaceIndex].codePoint !==
26
- character.AsciiCodePoint.CLOSE_ANGLE)
21
+ nodePoints[firstNonWhitespaceIndex].codePoint !== character.AsciiCodePoint.CLOSE_ANGLE)
27
22
  return null;
28
23
  let nextIndex = firstNonWhitespaceIndex + 1;
29
- if (nextIndex < endIndex &&
30
- character.isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
24
+ if (nextIndex < endIndex && character.isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
31
25
  nextIndex += 1;
32
- if (nextIndex < endIndex &&
33
- nodePoints[nextIndex].codePoint === character.VirtualCodePoint.SPACE) {
26
+ if (nextIndex < endIndex && nodePoints[nextIndex].codePoint === character.VirtualCodePoint.SPACE) {
34
27
  nextIndex += 1;
35
28
  }
36
29
  }
@@ -44,8 +37,8 @@ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
44
37
  };
45
38
  return { token, nextIndex };
46
39
  }
47
- eatAndInterruptPreviousSibling(line, prevSiblingToken) {
48
- const result = this.eatOpener(line);
40
+ function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
41
+ const result = eatOpener(line);
49
42
  if (result == null)
50
43
  return null;
51
44
  return {
@@ -54,12 +47,11 @@ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
54
47
  remainingSibling: prevSiblingToken,
55
48
  };
56
49
  }
57
- eatContinuationText(line, token, parentToken) {
58
- const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces, } = line;
50
+ function eatContinuationText(line, token, parentToken) {
51
+ const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
59
52
  if (countOfPrecedeSpaces >= 4 ||
60
53
  firstNonWhitespaceIndex >= endIndex ||
61
- nodePoints[firstNonWhitespaceIndex].codePoint !==
62
- character.AsciiCodePoint.CLOSE_ANGLE) {
54
+ nodePoints[firstNonWhitespaceIndex].codePoint !== character.AsciiCodePoint.CLOSE_ANGLE) {
63
55
  if (parentToken.nodeType === ast.BlockquoteType) {
64
56
  return { status: 'opening', nextIndex: startIndex };
65
57
  }
@@ -71,15 +63,38 @@ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
71
63
  : firstNonWhitespaceIndex + 1;
72
64
  return { status: 'opening', nextIndex };
73
65
  }
74
- parseBlock(token, children) {
75
- const node = {
76
- type: ast.BlockquoteType,
77
- children: (children || []),
78
- };
79
- return node;
66
+ };
67
+
68
+ const parse = function (api) {
69
+ return {
70
+ parse: tokens => tokens.map(token => {
71
+ const children = token.children ? api.parseBlockTokens(token.children) : [];
72
+ const node = {
73
+ type: ast.BlockquoteType,
74
+ position: token.position,
75
+ children,
76
+ };
77
+ return node;
78
+ }),
79
+ };
80
+ };
81
+
82
+ const uniqueName = '@yozora/tokenizer-blockquote';
83
+
84
+ class BlockquoteTokenizer extends coreTokenizer.BaseBlockTokenizer {
85
+ constructor(props = {}) {
86
+ var _a, _b;
87
+ super({
88
+ name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
89
+ priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.CONTAINING_BLOCK,
90
+ });
91
+ this.match = match;
92
+ this.parse = parse;
80
93
  }
81
94
  }
82
95
 
83
96
  exports.BlockquoteTokenizer = BlockquoteTokenizer;
84
97
  exports.BlockquoteTokenizerName = uniqueName;
85
- exports['default'] = BlockquoteTokenizer;
98
+ exports.blockquoteMatch = match;
99
+ exports.blockquoteParse = parse;
100
+ exports["default"] = BlockquoteTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,32 +1,25 @@
1
1
  import { BlockquoteType } from '@yozora/ast';
2
2
  import { AsciiCodePoint, isSpaceCharacter, VirtualCodePoint } from '@yozora/character';
3
- import { BaseBlockTokenizer, TokenizerPriority, calcStartYastNodePoint, calcEndYastNodePoint } from '@yozora/core-tokenizer';
3
+ import { calcStartYastNodePoint, calcEndYastNodePoint, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
4
4
 
5
- const uniqueName = '@yozora/tokenizer-blockquote';
6
-
7
- class BlockquoteTokenizer extends BaseBlockTokenizer {
8
- constructor(props = {}) {
9
- var _a, _b;
10
- super({
11
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
12
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_BLOCK,
13
- });
14
- this.isContainingBlock = true;
15
- }
16
- eatOpener(line) {
5
+ const match = function () {
6
+ return {
7
+ isContainingBlock: true,
8
+ eatOpener,
9
+ eatAndInterruptPreviousSibling,
10
+ eatContinuationText,
11
+ };
12
+ function eatOpener(line) {
17
13
  if (line.countOfPrecedeSpaces >= 4)
18
14
  return null;
19
15
  const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex } = line;
20
16
  if (firstNonWhitespaceIndex >= endIndex ||
21
- nodePoints[firstNonWhitespaceIndex].codePoint !==
22
- AsciiCodePoint.CLOSE_ANGLE)
17
+ nodePoints[firstNonWhitespaceIndex].codePoint !== AsciiCodePoint.CLOSE_ANGLE)
23
18
  return null;
24
19
  let nextIndex = firstNonWhitespaceIndex + 1;
25
- if (nextIndex < endIndex &&
26
- isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
20
+ if (nextIndex < endIndex && isSpaceCharacter(nodePoints[nextIndex].codePoint)) {
27
21
  nextIndex += 1;
28
- if (nextIndex < endIndex &&
29
- nodePoints[nextIndex].codePoint === VirtualCodePoint.SPACE) {
22
+ if (nextIndex < endIndex && nodePoints[nextIndex].codePoint === VirtualCodePoint.SPACE) {
30
23
  nextIndex += 1;
31
24
  }
32
25
  }
@@ -40,8 +33,8 @@ class BlockquoteTokenizer extends BaseBlockTokenizer {
40
33
  };
41
34
  return { token, nextIndex };
42
35
  }
43
- eatAndInterruptPreviousSibling(line, prevSiblingToken) {
44
- const result = this.eatOpener(line);
36
+ function eatAndInterruptPreviousSibling(line, prevSiblingToken) {
37
+ const result = eatOpener(line);
45
38
  if (result == null)
46
39
  return null;
47
40
  return {
@@ -50,12 +43,11 @@ class BlockquoteTokenizer extends BaseBlockTokenizer {
50
43
  remainingSibling: prevSiblingToken,
51
44
  };
52
45
  }
53
- eatContinuationText(line, token, parentToken) {
54
- const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces, } = line;
46
+ function eatContinuationText(line, token, parentToken) {
47
+ const { nodePoints, startIndex, endIndex, firstNonWhitespaceIndex, countOfPrecedeSpaces } = line;
55
48
  if (countOfPrecedeSpaces >= 4 ||
56
49
  firstNonWhitespaceIndex >= endIndex ||
57
- nodePoints[firstNonWhitespaceIndex].codePoint !==
58
- AsciiCodePoint.CLOSE_ANGLE) {
50
+ nodePoints[firstNonWhitespaceIndex].codePoint !== AsciiCodePoint.CLOSE_ANGLE) {
59
51
  if (parentToken.nodeType === BlockquoteType) {
60
52
  return { status: 'opening', nextIndex: startIndex };
61
53
  }
@@ -67,13 +59,34 @@ class BlockquoteTokenizer extends BaseBlockTokenizer {
67
59
  : firstNonWhitespaceIndex + 1;
68
60
  return { status: 'opening', nextIndex };
69
61
  }
70
- parseBlock(token, children) {
71
- const node = {
72
- type: BlockquoteType,
73
- children: (children || []),
74
- };
75
- return node;
62
+ };
63
+
64
+ const parse = function (api) {
65
+ return {
66
+ parse: tokens => tokens.map(token => {
67
+ const children = token.children ? api.parseBlockTokens(token.children) : [];
68
+ const node = {
69
+ type: BlockquoteType,
70
+ position: token.position,
71
+ children,
72
+ };
73
+ return node;
74
+ }),
75
+ };
76
+ };
77
+
78
+ const uniqueName = '@yozora/tokenizer-blockquote';
79
+
80
+ class BlockquoteTokenizer extends BaseBlockTokenizer {
81
+ constructor(props = {}) {
82
+ var _a, _b;
83
+ super({
84
+ name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
85
+ priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.CONTAINING_BLOCK,
86
+ });
87
+ this.match = match;
88
+ this.parse = parse;
76
89
  }
77
90
  }
78
91
 
79
- export { BlockquoteTokenizer, uniqueName as BlockquoteTokenizerName, BlockquoteTokenizer as default };
92
+ export { BlockquoteTokenizer, uniqueName as BlockquoteTokenizerName, match as blockquoteMatch, parse as blockquoteParse, BlockquoteTokenizer as default };
@@ -1,5 +1,5 @@
1
- import { BlockquoteTokenizer } from './tokenizer';
2
- export { BlockquoteTokenizer } from './tokenizer';
1
+ export { match as blockquoteMatch } from './match';
2
+ export { parse as blockquoteParse } from './parse';
3
+ export { BlockquoteTokenizer, BlockquoteTokenizer as default } from './tokenizer';
3
4
  export { uniqueName as BlockquoteTokenizerName } from './types';
4
- export type { Token as BlockquoteToken, TokenizerProps as BlockquoteTokenizerProps, } from './types';
5
- export default BlockquoteTokenizer;
5
+ export type { IThis as IBlockquoteHookContext, IToken as IBlockquoteToken, ITokenizerProps as IBlockquoteTokenizerProps, } from './types';
@@ -0,0 +1,27 @@
1
+ import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
2
+ import type { IThis, IToken, T } from './types';
3
+ /**
4
+ * A block quote marker consists of 0-3 spaces of initial indent, plus
5
+ * (a) the character > together with a following space, or
6
+ * (b) a single character > not followed by a space.
7
+ *
8
+ * The following rules define block quotes:
9
+ * - Basic case. If a string of lines Ls constitute a sequence of blocks Bs,
10
+ * then the result of prepending a block quote marker to the beginning of
11
+ * each line in Ls is a block quote containing Bs.
12
+ *
13
+ * - Laziness. If a string of lines Ls constitute a block quote with contents
14
+ * Bs, then the result of deleting the initial block quote marker from one
15
+ * or more lines in which the next non-whitespace character after the block
16
+ * quote marker is paragraph continuation text is a block quote with Bs as
17
+ * its content. Paragraph continuation text is text that will be parsed as
18
+ * part of the content of a paragraph, but does not occur at the beginning
19
+ * of the paragraph.
20
+ *
21
+ * - Consecutiveness. A document cannot contain two block quotes in a row
22
+ * unless there is a blank line between them.
23
+ *
24
+ * @see https://github.com/syntax-tree/mdast#blockquote
25
+ * @see https://github.github.com/gfm/#block-quotes
26
+ */
27
+ export declare const match: IMatchBlockHookCreator<T, IToken, IThis>;
@@ -0,0 +1,3 @@
1
+ import type { IParseBlockHookCreator } from '@yozora/core-tokenizer';
2
+ import type { INode, IThis, IToken, T } from './types';
3
+ export declare const parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
@@ -1,54 +1,13 @@
1
- import type { YastNode } from '@yozora/ast';
2
- import type { PhrasingContentLine, ResultOfEatAndInterruptPreviousSibling, ResultOfEatContinuationText, ResultOfEatOpener, ResultOfParse, Tokenizer, TokenizerMatchBlockHook, TokenizerParseBlockHook, YastBlockToken } from '@yozora/core-tokenizer';
1
+ import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
3
2
  import { BaseBlockTokenizer } from '@yozora/core-tokenizer';
4
- import type { Node, T, Token, TokenizerProps } from './types';
3
+ import type { INode, IThis, IToken, ITokenizerProps, T } from './types';
5
4
  /**
6
5
  * Lexical Analyzer for Blockquote.
7
- *
8
- * A block quote marker consists of 0-3 spaces of initial indent, plus
9
- * (a) the character > together with a following space, or
10
- * (b) a single character > not followed by a space.
11
- *
12
- * The following rules define block quotes:
13
- * - Basic case. If a string of lines Ls constitute a sequence of blocks Bs,
14
- * then the result of prepending a block quote marker to the beginning of
15
- * each line in Ls is a block quote containing Bs.
16
- *
17
- * - Laziness. If a string of lines Ls constitute a block quote with contents
18
- * Bs, then the result of deleting the initial block quote marker from one
19
- * or more lines in which the next non-whitespace character after the block
20
- * quote marker is paragraph continuation text is a block quote with Bs as
21
- * its content. Paragraph continuation text is text that will be parsed as
22
- * part of the content of a paragraph, but does not occur at the beginning
23
- * of the paragraph.
24
- *
25
- * - Consecutiveness. A document cannot contain two block quotes in a row
26
- * unless there is a blank line between them.
27
- *
28
6
  * @see https://github.com/syntax-tree/mdast#blockquote
29
7
  * @see https://github.github.com/gfm/#block-quotes
30
8
  */
31
- export declare class BlockquoteTokenizer extends BaseBlockTokenizer implements Tokenizer, TokenizerMatchBlockHook<T, Token>, TokenizerParseBlockHook<T, Token, Node> {
32
- readonly isContainingBlock = true;
33
- constructor(props?: TokenizerProps);
34
- /**
35
- * @override
36
- * @see TokenizerMatchBlockHook
37
- */
38
- eatOpener(line: Readonly<PhrasingContentLine>): ResultOfEatOpener<T, Token>;
39
- /**
40
- * @override
41
- * @see TokenizerMatchBlockHook
42
- */
43
- eatAndInterruptPreviousSibling(line: Readonly<PhrasingContentLine>, prevSiblingToken: Readonly<YastBlockToken>): ResultOfEatAndInterruptPreviousSibling<T, Token>;
44
- /**
45
- * @override
46
- * @see TokenizerMatchBlockHook
47
- */
48
- eatContinuationText(line: Readonly<PhrasingContentLine>, token: Token, parentToken: Readonly<YastBlockToken>): ResultOfEatContinuationText;
49
- /**
50
- * @override
51
- * @see TokenizerParseBlockHook
52
- */
53
- parseBlock(token: Readonly<Token>, children?: YastNode[]): ResultOfParse<T, Node>;
9
+ export declare class BlockquoteTokenizer extends BaseBlockTokenizer<T, IToken, INode, IThis> implements IBlockTokenizer<T, IToken, INode, IThis> {
10
+ constructor(props?: ITokenizerProps);
11
+ readonly match: IMatchBlockHookCreator<T, IToken, IThis>;
12
+ readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
54
13
  }
@@ -1,12 +1,13 @@
1
- import type { Blockquote, BlockquoteType } from '@yozora/ast';
2
- import type { BaseBlockTokenizerProps, PartialYastBlockToken, YastBlockToken } from '@yozora/core-tokenizer';
1
+ import type { BlockquoteType, IBlockquote } from '@yozora/ast';
2
+ import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, ITokenizer, IYastBlockToken } from '@yozora/core-tokenizer';
3
3
  export declare type T = BlockquoteType;
4
- export declare type Node = Blockquote;
4
+ export declare type INode = IBlockquote;
5
5
  export declare const uniqueName = "@yozora/tokenizer-blockquote";
6
- export interface Token extends PartialYastBlockToken<T> {
6
+ export interface IToken extends IPartialYastBlockToken<T> {
7
7
  /**
8
8
  *
9
9
  */
10
- children: YastBlockToken[];
10
+ children: IYastBlockToken[];
11
11
  }
12
- export declare type TokenizerProps = Partial<BaseBlockTokenizerProps>;
12
+ export declare type IThis = ITokenizer;
13
+ export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-blockquote",
3
- "version": "1.2.1",
3
+ "version": "2.0.0-alpha.1",
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": "^1.2.1",
39
- "@yozora/character": "^1.2.1",
40
- "@yozora/core-tokenizer": "^1.2.1"
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"
41
41
  },
42
- "gitHead": "d98d07d7c56dd9f6bb60149b2b0a4be2787e1046"
42
+ "gitHead": "86202e1d2b03ccfc2ab030517d9d314f7aee7666"
43
43
  }