@yozora/tokenizer-admonition 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` 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
@@ -180,7 +180,7 @@ Name | Type | Required | Default
180
180
  ### Node Type
181
181
 
182
182
  ```typescript
183
- export interface Admonition extends YastParent<'admonition'> {
183
+ export interface Admonition extends Parent<'admonition'> {
184
184
  type: 'admonition'
185
185
  /**
186
186
  * Keyword of an admonition.
@@ -189,11 +189,11 @@ export interface Admonition extends YastParent<'admonition'> {
189
189
  /**
190
190
  * Admonition title.
191
191
  */
192
- title: YastNode[]
192
+ title: Node[]
193
193
  /**
194
194
  * Admonition body.
195
195
  */
196
- children: YastNode[]
196
+ children: Node[]
197
197
  }
198
198
  ```
199
199
 
@@ -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
@@ -12,7 +12,7 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
12
12
  var FencedBlockTokenizer__default = /*#__PURE__*/_interopDefaultLegacy(FencedBlockTokenizer);
13
13
 
14
14
  const match = function (api) {
15
- const hook = FencedBlockTokenizer.fencedMatch.call(this, api);
15
+ const hook = FencedBlockTokenizer.fencedBlockMatch.call(this, api);
16
16
  return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
17
17
  function onClose(token) {
18
18
  const children = api.rollbackPhrasingLines(token.lines);
@@ -22,15 +22,15 @@ const match = function (api) {
22
22
 
23
23
  const parse = function (api) {
24
24
  return {
25
- parse: (token, children) => {
25
+ parse: tokens => tokens.map(token => {
26
26
  const infoString = token.infoString;
27
27
  let i = 0;
28
- const keyword = [];
28
+ const keywordNodePoints = [];
29
29
  for (; i < infoString.length; ++i) {
30
30
  const p = infoString[i];
31
31
  if (character.isUnicodeWhitespaceCharacter(p.codePoint))
32
32
  break;
33
- keyword.push(p);
33
+ keywordNodePoints.push(p);
34
34
  }
35
35
  i = coreTokenizer.eatOptionalWhitespaces(infoString, i, infoString.length);
36
36
  const title = (() => {
@@ -45,19 +45,16 @@ const parse = function (api) {
45
45
  countOfPrecedeSpaces: 0,
46
46
  },
47
47
  ];
48
- const phrasingContent = api.buildPhrasingContent(titleLines);
49
- if (phrasingContent == null)
50
- return [];
51
- return api.parsePhrasingContent(phrasingContent);
48
+ const contents = coreTokenizer.mergeAndStripContentLines(titleLines);
49
+ return api.processInlines(contents);
52
50
  })();
53
- const node = {
54
- type: ast.AdmonitionType,
55
- keyword: character.calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
56
- title,
57
- children,
58
- };
51
+ const keyword = character.calcEscapedStringFromNodePoints(keywordNodePoints, 0, keywordNodePoints.length, true);
52
+ const children = api.parseBlockTokens(token.children);
53
+ const node = api.shouldReservePosition
54
+ ? { type: ast.AdmonitionType, position: token.position, keyword, title, children }
55
+ : { type: ast.AdmonitionType, keyword, title, children };
59
56
  return node;
60
- },
57
+ }),
61
58
  };
62
59
  };
63
60
 
package/lib/esm/index.js CHANGED
@@ -1,10 +1,10 @@
1
- import FencedBlockTokenizer, { fencedMatch } from '@yozora/tokenizer-fenced-block';
1
+ import FencedBlockTokenizer, { fencedBlockMatch } from '@yozora/tokenizer-fenced-block';
2
2
  import { AdmonitionType } from '@yozora/ast';
3
3
  import { isUnicodeWhitespaceCharacter, calcEscapedStringFromNodePoints, AsciiCodePoint } from '@yozora/character';
4
- import { eatOptionalWhitespaces, TokenizerPriority } from '@yozora/core-tokenizer';
4
+ import { eatOptionalWhitespaces, mergeAndStripContentLines, TokenizerPriority } from '@yozora/core-tokenizer';
5
5
 
6
6
  const match = function (api) {
7
- const hook = fencedMatch.call(this, api);
7
+ const hook = fencedBlockMatch.call(this, api);
8
8
  return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
9
9
  function onClose(token) {
10
10
  const children = api.rollbackPhrasingLines(token.lines);
@@ -14,15 +14,15 @@ const match = function (api) {
14
14
 
15
15
  const parse = function (api) {
16
16
  return {
17
- parse: (token, children) => {
17
+ parse: tokens => tokens.map(token => {
18
18
  const infoString = token.infoString;
19
19
  let i = 0;
20
- const keyword = [];
20
+ const keywordNodePoints = [];
21
21
  for (; i < infoString.length; ++i) {
22
22
  const p = infoString[i];
23
23
  if (isUnicodeWhitespaceCharacter(p.codePoint))
24
24
  break;
25
- keyword.push(p);
25
+ keywordNodePoints.push(p);
26
26
  }
27
27
  i = eatOptionalWhitespaces(infoString, i, infoString.length);
28
28
  const title = (() => {
@@ -37,19 +37,16 @@ const parse = function (api) {
37
37
  countOfPrecedeSpaces: 0,
38
38
  },
39
39
  ];
40
- const phrasingContent = api.buildPhrasingContent(titleLines);
41
- if (phrasingContent == null)
42
- return [];
43
- return api.parsePhrasingContent(phrasingContent);
40
+ const contents = mergeAndStripContentLines(titleLines);
41
+ return api.processInlines(contents);
44
42
  })();
45
- const node = {
46
- type: AdmonitionType,
47
- keyword: calcEscapedStringFromNodePoints(keyword, 0, keyword.length, true),
48
- title,
49
- children,
50
- };
43
+ const keyword = calcEscapedStringFromNodePoints(keywordNodePoints, 0, keywordNodePoints.length, true);
44
+ const children = api.parseBlockTokens(token.children);
45
+ const node = api.shouldReservePosition
46
+ ? { type: AdmonitionType, position: token.position, keyword, title, children }
47
+ : { type: AdmonitionType, keyword, title, children };
51
48
  return node;
52
- },
49
+ }),
53
50
  };
54
51
  };
55
52
 
@@ -2,4 +2,4 @@ export { match as admonitionMatch } from './match';
2
2
  export { parse as admonitionParse } from './parse';
3
3
  export { AdmonitionTokenizer, AdmonitionTokenizer as default } from './tokenizer';
4
4
  export { uniqueName as AdmonitionTokenizerName } from './types';
5
- export type { IHookContext as IAdmonitionHookContext, IToken as IAdmonitionToken, ITokenizerProps as IAdmonitionTokenizerProps, } from './types';
5
+ export type { IThis as IAdmonitionHookContext, IToken as IAdmonitionToken, ITokenizerProps as IAdmonitionTokenizerProps, } from './types';
@@ -1,5 +1,5 @@
1
1
  import type { IMatchBlockHookCreator } from '@yozora/core-tokenizer';
2
- import type { IHookContext, IToken, T } from './types';
2
+ import type { IThis, IToken, T } from './types';
3
3
  /**
4
4
  * A code fence is a sequence of at least three consecutive backtick characters
5
5
  * (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code
@@ -8,4 +8,4 @@ import type { IHookContext, IToken, T } from './types';
8
8
  * @see https://github.com/syntax-tree/mdast#code
9
9
  * @see https://github.github.com/gfm/#code-fence
10
10
  */
11
- export declare const match: IMatchBlockHookCreator<T, IToken, IHookContext>;
11
+ export declare const match: IMatchBlockHookCreator<T, IToken, IThis>;
@@ -1,3 +1,3 @@
1
1
  import type { IParseBlockHookCreator } from '@yozora/core-tokenizer';
2
- import type { IHookContext, INode, IToken, T } from './types';
3
- export declare const parse: IParseBlockHookCreator<T, IToken, INode, IHookContext>;
2
+ import type { INode, IThis, IToken, T } from './types';
3
+ export declare const parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
@@ -1,13 +1,13 @@
1
1
  import type { IBlockTokenizer, IMatchBlockHookCreator, IParseBlockHookCreator } from '@yozora/core-tokenizer';
2
2
  import FencedBlockTokenizer from '@yozora/tokenizer-fenced-block';
3
- import type { IHookContext, INode, IToken, ITokenizerProps, T } from './types';
3
+ import type { INode, IThis, IToken, ITokenizerProps, T } from './types';
4
4
  /**
5
5
  * Lexical Analyzer for Admonition.
6
6
  * @see https://github.com/syntax-tree/mdast#code
7
7
  * @see https://github.github.com/gfm/#code-fence
8
8
  */
9
- export declare class AdmonitionTokenizer extends FencedBlockTokenizer<T, INode, IHookContext> implements IBlockTokenizer<T, IToken, INode, IHookContext> {
9
+ export declare class AdmonitionTokenizer extends FencedBlockTokenizer<T, INode, IThis> implements IBlockTokenizer<T, IToken, INode, IThis> {
10
10
  constructor(props?: ITokenizerProps);
11
- readonly match: IMatchBlockHookCreator<T, IToken, IHookContext>;
12
- readonly parse: IParseBlockHookCreator<T, IToken, INode, IHookContext>;
11
+ readonly match: IMatchBlockHookCreator<T, IToken, IThis>;
12
+ readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis>;
13
13
  }
@@ -1,8 +1,8 @@
1
- import type { AdmonitionType, IAdmonition } from '@yozora/ast';
1
+ import type { Admonition, AdmonitionType } from '@yozora/ast';
2
2
  import type { IBaseBlockTokenizerProps, IYastBlockToken } from '@yozora/core-tokenizer';
3
3
  import type { IFencedBlockHookContext, IFencedBlockToken } from '@yozora/tokenizer-fenced-block';
4
4
  export declare type T = AdmonitionType;
5
- export declare type INode = IAdmonition;
5
+ export declare type INode = Admonition;
6
6
  export declare const uniqueName = "@yozora/tokenizer-admonition";
7
7
  export interface IToken extends IFencedBlockToken<T> {
8
8
  /**
@@ -10,5 +10,5 @@ export interface IToken extends IFencedBlockToken<T> {
10
10
  */
11
11
  children?: IYastBlockToken[];
12
12
  }
13
- export declare type IHookContext = IFencedBlockHookContext<T>;
13
+ export declare type IThis = IFencedBlockHookContext<T>;
14
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": "2.0.0-alpha.0",
3
+ "version": "2.0.0",
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": "^2.0.0-alpha.0",
46
- "@yozora/character": "^2.0.0-alpha.0",
47
- "@yozora/core-tokenizer": "^2.0.0-alpha.0",
48
- "@yozora/tokenizer-fenced-block": "^2.0.0-alpha.0"
45
+ "@yozora/ast": "^2.0.0",
46
+ "@yozora/character": "^2.0.0",
47
+ "@yozora/core-tokenizer": "^2.0.0",
48
+ "@yozora/tokenizer-fenced-block": "^2.0.0"
49
49
  },
50
- "gitHead": "0171501339c49ffd02ed16a63447fa20a47a29a7"
50
+ "gitHead": "65e99d1709fdd1c918465dce6b1e91de96bdab5e"
51
51
  }