@yozora/tokenizer-admonition 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` 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 AdmonitionTokenizer from '@yozora/tokenizer-admonition'
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 AdmonitionTokenizer())
96
96
 
97
97
  // parse source markdown content
@@ -285,7 +285,6 @@ export interface Admonition extends YastParent<'admonition'> {
285
285
  [@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
286
286
  [@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
287
287
  [@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
288
- [@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
289
288
  [@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
290
289
  [@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
291
290
  [@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
@@ -345,7 +344,6 @@ export interface Admonition extends YastParent<'admonition'> {
345
344
  [doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
346
345
  [doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
347
346
  [doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
348
- [doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
349
347
  [doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
350
348
  [doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
351
349
  [doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
package/lib/cjs/index.js CHANGED
@@ -2,18 +2,70 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var FencedBlockTokenizer = require('@yozora/tokenizer-fenced-block');
5
6
  var ast = require('@yozora/ast');
6
7
  var character = require('@yozora/character');
7
8
  var coreTokenizer = require('@yozora/core-tokenizer');
8
- var FencedBlockTokenizer = require('@yozora/tokenizer-fenced-block');
9
9
 
10
10
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
11
 
12
12
  var FencedBlockTokenizer__default = /*#__PURE__*/_interopDefaultLegacy(FencedBlockTokenizer);
13
13
 
14
+ const match = function (api) {
15
+ const hook = FencedBlockTokenizer.fencedBlockMatch.call(this, api);
16
+ return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
17
+ function onClose(token) {
18
+ const children = api.rollbackPhrasingLines(token.lines);
19
+ token.children = children;
20
+ }
21
+ };
22
+
23
+ const parse = function (api) {
24
+ return {
25
+ parse: tokens => tokens.map(token => {
26
+ const infoString = token.infoString;
27
+ let i = 0;
28
+ const keyword = [];
29
+ for (; i < infoString.length; ++i) {
30
+ const p = infoString[i];
31
+ if (character.isUnicodeWhitespaceCharacter(p.codePoint))
32
+ break;
33
+ keyword.push(p);
34
+ }
35
+ i = coreTokenizer.eatOptionalWhitespaces(infoString, i, infoString.length);
36
+ const title = (() => {
37
+ if (i >= infoString.length)
38
+ return [];
39
+ const titleLines = [
40
+ {
41
+ nodePoints: infoString,
42
+ startIndex: i,
43
+ endIndex: infoString.length,
44
+ firstNonWhitespaceIndex: i,
45
+ countOfPrecedeSpaces: 0,
46
+ },
47
+ ];
48
+ const phrasingContent = api.buildPhrasingContent(titleLines);
49
+ if (phrasingContent == null)
50
+ return [];
51
+ return api.parsePhrasingContent(phrasingContent);
52
+ })();
53
+ const children = token.children ? api.parseBlockTokens(token.children) : [];
54
+ const node = {
55
+ type: ast.AdmonitionType,
56
+ position: token.position,
57
+ keyword: character.calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
58
+ title,
59
+ children,
60
+ };
61
+ return node;
62
+ }),
63
+ };
64
+ };
65
+
14
66
  const uniqueName = '@yozora/tokenizer-admonition';
15
67
 
16
- class AdmonitionTokenizer extends FencedBlockTokenizer__default['default'] {
68
+ class AdmonitionTokenizer extends FencedBlockTokenizer__default["default"] {
17
69
  constructor(props = {}) {
18
70
  var _a, _b;
19
71
  super({
@@ -23,50 +75,13 @@ class AdmonitionTokenizer extends FencedBlockTokenizer__default['default'] {
23
75
  markers: [character.AsciiCodePoint.COLON],
24
76
  markersRequired: 3,
25
77
  });
26
- this.isContainingBlock = true;
27
- }
28
- onClose(token, api) {
29
- const children = api.rollbackPhrasingLines(token.lines);
30
- token.children = children;
31
- }
32
- parseBlock(token, children, api) {
33
- const infoString = token.infoString;
34
- let i = 0;
35
- const keyword = [];
36
- for (; i < infoString.length; ++i) {
37
- const p = infoString[i];
38
- if (character.isUnicodeWhitespaceCharacter(p.codePoint))
39
- break;
40
- keyword.push(p);
41
- }
42
- i = coreTokenizer.eatOptionalWhitespaces(infoString, i, infoString.length);
43
- const title = (() => {
44
- if (i >= infoString.length)
45
- return [];
46
- const titleLines = [
47
- {
48
- nodePoints: infoString,
49
- startIndex: i,
50
- endIndex: infoString.length,
51
- firstNonWhitespaceIndex: i,
52
- countOfPrecedeSpaces: 0,
53
- },
54
- ];
55
- const phrasingContent = api.buildPhrasingContent(titleLines);
56
- if (phrasingContent == null)
57
- return [];
58
- return api.parsePhrasingContent(phrasingContent);
59
- })();
60
- const node = {
61
- type: ast.AdmonitionType,
62
- keyword: character.calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
63
- title,
64
- children: children !== null && children !== void 0 ? children : [],
65
- };
66
- return node;
78
+ this.match = match;
79
+ this.parse = parse;
67
80
  }
68
81
  }
69
82
 
70
83
  exports.AdmonitionTokenizer = AdmonitionTokenizer;
71
84
  exports.AdmonitionTokenizerName = uniqueName;
72
- exports['default'] = AdmonitionTokenizer;
85
+ exports.admonitionMatch = match;
86
+ exports.admonitionParse = parse;
87
+ exports["default"] = AdmonitionTokenizer;
package/lib/esm/index.js CHANGED
@@ -1,7 +1,59 @@
1
+ import FencedBlockTokenizer, { fencedBlockMatch } from '@yozora/tokenizer-fenced-block';
1
2
  import { AdmonitionType } from '@yozora/ast';
2
- import { AsciiCodePoint, isUnicodeWhitespaceCharacter, calcEscapedStringFromNodePoints } from '@yozora/character';
3
- import { TokenizerPriority, eatOptionalWhitespaces } from '@yozora/core-tokenizer';
4
- import FencedBlockTokenizer from '@yozora/tokenizer-fenced-block';
3
+ import { isUnicodeWhitespaceCharacter, calcEscapedStringFromNodePoints, AsciiCodePoint } from '@yozora/character';
4
+ import { eatOptionalWhitespaces, TokenizerPriority } from '@yozora/core-tokenizer';
5
+
6
+ const match = function (api) {
7
+ const hook = fencedBlockMatch.call(this, api);
8
+ return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
9
+ function onClose(token) {
10
+ const children = api.rollbackPhrasingLines(token.lines);
11
+ token.children = children;
12
+ }
13
+ };
14
+
15
+ const parse = function (api) {
16
+ return {
17
+ parse: tokens => tokens.map(token => {
18
+ const infoString = token.infoString;
19
+ let i = 0;
20
+ const keyword = [];
21
+ for (; i < infoString.length; ++i) {
22
+ const p = infoString[i];
23
+ if (isUnicodeWhitespaceCharacter(p.codePoint))
24
+ break;
25
+ keyword.push(p);
26
+ }
27
+ i = eatOptionalWhitespaces(infoString, i, infoString.length);
28
+ const title = (() => {
29
+ if (i >= infoString.length)
30
+ return [];
31
+ const titleLines = [
32
+ {
33
+ nodePoints: infoString,
34
+ startIndex: i,
35
+ endIndex: infoString.length,
36
+ firstNonWhitespaceIndex: i,
37
+ countOfPrecedeSpaces: 0,
38
+ },
39
+ ];
40
+ const phrasingContent = api.buildPhrasingContent(titleLines);
41
+ if (phrasingContent == null)
42
+ return [];
43
+ return api.parsePhrasingContent(phrasingContent);
44
+ })();
45
+ const children = token.children ? api.parseBlockTokens(token.children) : [];
46
+ const node = {
47
+ type: AdmonitionType,
48
+ position: token.position,
49
+ keyword: calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
50
+ title,
51
+ children,
52
+ };
53
+ return node;
54
+ }),
55
+ };
56
+ };
5
57
 
6
58
  const uniqueName = '@yozora/tokenizer-admonition';
7
59
 
@@ -15,48 +67,9 @@ class AdmonitionTokenizer extends FencedBlockTokenizer {
15
67
  markers: [AsciiCodePoint.COLON],
16
68
  markersRequired: 3,
17
69
  });
18
- this.isContainingBlock = true;
19
- }
20
- onClose(token, api) {
21
- const children = api.rollbackPhrasingLines(token.lines);
22
- token.children = children;
23
- }
24
- parseBlock(token, children, api) {
25
- const infoString = token.infoString;
26
- let i = 0;
27
- const keyword = [];
28
- for (; i < infoString.length; ++i) {
29
- const p = infoString[i];
30
- if (isUnicodeWhitespaceCharacter(p.codePoint))
31
- break;
32
- keyword.push(p);
33
- }
34
- i = eatOptionalWhitespaces(infoString, i, infoString.length);
35
- const title = (() => {
36
- if (i >= infoString.length)
37
- return [];
38
- const titleLines = [
39
- {
40
- nodePoints: infoString,
41
- startIndex: i,
42
- endIndex: infoString.length,
43
- firstNonWhitespaceIndex: i,
44
- countOfPrecedeSpaces: 0,
45
- },
46
- ];
47
- const phrasingContent = api.buildPhrasingContent(titleLines);
48
- if (phrasingContent == null)
49
- return [];
50
- return api.parsePhrasingContent(phrasingContent);
51
- })();
52
- const node = {
53
- type: AdmonitionType,
54
- keyword: calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
55
- title,
56
- children: children !== null && children !== void 0 ? children : [],
57
- };
58
- return node;
70
+ this.match = match;
71
+ this.parse = parse;
59
72
  }
60
73
  }
61
74
 
62
- export { AdmonitionTokenizer, uniqueName as AdmonitionTokenizerName, AdmonitionTokenizer as default };
75
+ export { AdmonitionTokenizer, uniqueName as AdmonitionTokenizerName, match as admonitionMatch, parse as admonitionParse, AdmonitionTokenizer as default };
@@ -1,5 +1,5 @@
1
- import { AdmonitionTokenizer } from './tokenizer';
2
- export { AdmonitionTokenizer } from './tokenizer';
1
+ export { match as admonitionMatch } from './match';
2
+ export { parse as admonitionParse } from './parse';
3
+ export { AdmonitionTokenizer, AdmonitionTokenizer as default } from './tokenizer';
3
4
  export { uniqueName as AdmonitionTokenizerName } from './types';
4
- export type { Token as AdmonitionToken, TokenizerProps as AdmonitionTokenizerProps, } from './types';
5
- export default AdmonitionTokenizer;
5
+ export type { IThis as IAdmonitionHookContext, IToken as IAdmonitionToken, ITokenizerProps as IAdmonitionTokenizerProps, } from './types';
@@ -0,0 +1,11 @@
1
+ import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
2
+ import type { IThis, IToken, T } from './types';
3
+ /**
4
+ * A code fence is a sequence of at least three consecutive backtick characters
5
+ * (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code
6
+ * block begins with a code fence, indented no more than three spaces.
7
+ *
8
+ * @see https://github.com/syntax-tree/mdast#code
9
+ * @see https://github.github.com/gfm/#code-fence
10
+ */
11
+ 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,29 +1,13 @@
1
- import type { YastNode } from '@yozora/ast';
2
- import type { MatchBlockPhaseApi, ParseBlockPhaseApi, ResultOfParse, Tokenizer, TokenizerMatchBlockHook, TokenizerParseBlockHook } from '@yozora/core-tokenizer';
1
+ import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
3
2
  import FencedBlockTokenizer from '@yozora/tokenizer-fenced-block';
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 Admonition.
7
- *
8
- * A code fence is a sequence of at least three consecutive backtick characters
9
- * (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code
10
- * block begins with a code fence, indented no more than three spaces.
11
- *
12
6
  * @see https://github.com/syntax-tree/mdast#code
13
7
  * @see https://github.github.com/gfm/#code-fence
14
8
  */
15
- export declare class AdmonitionTokenizer extends FencedBlockTokenizer<T> implements Tokenizer, TokenizerMatchBlockHook<T, Token>, TokenizerParseBlockHook<T, Token, Node> {
16
- readonly isContainingBlock = true;
17
- constructor(props?: TokenizerProps);
18
- /**
19
- * Resolve children.
20
- * @override
21
- * @see TokenizerMatchBlockHook
22
- */
23
- onClose(token: Token, api: MatchBlockPhaseApi): void;
24
- /**
25
- * @override
26
- * @see TokenizerParseBlockHook
27
- */
28
- parseBlock(token: Token, children: YastNode[] | undefined, api: Readonly<ParseBlockPhaseApi>): ResultOfParse<T, Node>;
9
+ export declare class AdmonitionTokenizer extends FencedBlockTokenizer<T, 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>;
29
13
  }
@@ -1,13 +1,14 @@
1
- import type { Admonition, AdmonitionType } from '@yozora/ast';
2
- import type { BaseBlockTokenizerProps, YastBlockToken } from '@yozora/core-tokenizer';
3
- import type { FencedBlockToken } from '@yozora/tokenizer-fenced-block';
1
+ import type { AdmonitionType, IAdmonition } from '@yozora/ast';
2
+ import type { IBaseBlockTokenizerProps, IYastBlockToken } from '@yozora/core-tokenizer';
3
+ import type { IFencedBlockHookContext, IFencedBlockToken } from '@yozora/tokenizer-fenced-block';
4
4
  export declare type T = AdmonitionType;
5
- export declare type Node = Admonition;
5
+ export declare type INode = IAdmonition;
6
6
  export declare const uniqueName = "@yozora/tokenizer-admonition";
7
- export interface Token extends FencedBlockToken<T> {
7
+ export interface IToken extends IFencedBlockToken<T> {
8
8
  /**
9
9
  *
10
10
  */
11
- children?: YastBlockToken[];
11
+ children?: IYastBlockToken[];
12
12
  }
13
- export declare type TokenizerProps = Partial<BaseBlockTokenizerProps>;
13
+ export declare type IThis = IFencedBlockHookContext<T>;
14
+ export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-admonition",
3
- "version": "1.2.1",
3
+ "version": "2.0.0-alpha.1",
4
4
  "description": "Tokenizer for processing admonitions",
5
5
  "author": {
6
6
  "name": "guanghechen",
@@ -42,10 +42,10 @@
42
42
  "test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
43
43
  },
44
44
  "dependencies": {
45
- "@yozora/ast": "^1.2.1",
46
- "@yozora/character": "^1.2.1",
47
- "@yozora/core-tokenizer": "^1.2.1",
48
- "@yozora/tokenizer-fenced-block": "^1.2.1"
45
+ "@yozora/ast": "^2.0.0-alpha.1",
46
+ "@yozora/character": "^2.0.0-alpha.1",
47
+ "@yozora/core-tokenizer": "^2.0.0-alpha.1",
48
+ "@yozora/tokenizer-fenced-block": "^2.0.0-alpha.1"
49
49
  },
50
- "gitHead": "d98d07d7c56dd9f6bb60149b2b0a4be2787e1046"
50
+ "gitHead": "86202e1d2b03ccfc2ab030517d9d314f7aee7666"
51
51
  }