@yozora/tokenizer-heading 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 HeadingTokenizer from '@yozora/tokenizer-heading'
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 HeadingTokenizer())
96
96
 
97
97
  // parse source markdown content
@@ -238,7 +238,6 @@ Name | Type | Required | Default
238
238
  [@yozora/tokenizer-link]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link#readme
239
239
  [@yozora/tokenizer-link-reference]: https://github.com/yozorajs/yozora/tree/main/tokenizers/link-reference#readme
240
240
  [@yozora/tokenizer-list]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list#readme
241
- [@yozora/tokenizer-list-item]: https://github.com/yozorajs/yozora/tree/main/tokenizers/list-item#readme
242
241
  [@yozora/tokenizer-math]: https://github.com/yozorajs/yozora/tree/main/tokenizers/math#readme
243
242
  [@yozora/tokenizer-paragraph]: https://github.com/yozorajs/yozora/tree/main/tokenizers/paragraph#readme
244
243
  [@yozora/tokenizer-setext-heading]: https://github.com/yozorajs/yozora/tree/main/tokenizers/setext-heading#readme
@@ -298,7 +297,6 @@ Name | Type | Required | Default
298
297
  [doc-@yozora/tokenizer-definition]: https://yozora.guanghechen.com/docs/package/tokenizer-definition
299
298
  [doc-@yozora/tokenizer-link-reference]: https://yozora.guanghechen.com/docs/package/tokenizer-link-reference
300
299
  [doc-@yozora/tokenizer-list]: https://yozora.guanghechen.com/docs/package/tokenizer-list
301
- [doc-@yozora/tokenizer-list-item]: https://yozora.guanghechen.com/docs/package/tokenizer-list-item
302
300
  [doc-@yozora/tokenizer-math]: https://yozora.guanghechen.com/docs/package/tokenizer-math
303
301
  [doc-@yozora/tokenizer-paragraph]: https://yozora.guanghechen.com/docs/package/tokenizer-paragraph
304
302
  [doc-@yozora/tokenizer-setext-heading]: https://yozora.guanghechen.com/docs/package/tokenizer-setext-heading
package/lib/cjs/index.js CHANGED
@@ -30,8 +30,8 @@ const match = function () {
30
30
  const token = {
31
31
  nodeType: ast.HeadingType,
32
32
  position: {
33
- start: coreTokenizer.calcStartYastNodePoint(nodePoints, startIndex),
34
- end: coreTokenizer.calcEndYastNodePoint(nodePoints, nextIndex - 1),
33
+ start: coreTokenizer.calcStartPoint(nodePoints, startIndex),
34
+ end: coreTokenizer.calcEndPoint(nodePoints, nextIndex - 1),
35
35
  },
36
36
  depth: depth,
37
37
  line,
@@ -52,7 +52,7 @@ const match = function () {
52
52
 
53
53
  const parse = function (api) {
54
54
  return {
55
- parse: token => {
55
+ parse: tokens => tokens.map(token => {
56
56
  const { nodePoints, firstNonWhitespaceIndex, endIndex } = token.line;
57
57
  let [leftIndex, rightIndex] = character.calcTrimBoundaryOfCodePoints(nodePoints, firstNonWhitespaceIndex + token.depth, endIndex);
58
58
  let closeCharCount = 0;
@@ -83,14 +83,13 @@ const parse = function (api) {
83
83
  countOfPrecedeSpaces: 0,
84
84
  },
85
85
  ];
86
- const phrasingContent = api.buildPhrasingContent(lines);
87
- const node = {
88
- type: ast.HeadingType,
89
- depth: token.depth,
90
- children: phrasingContent == null ? [] : [phrasingContent],
91
- };
86
+ const contents = coreTokenizer.mergeAndStripContentLines(lines);
87
+ const children = api.processInlines(contents);
88
+ const node = api.shouldReservePosition
89
+ ? { type: ast.HeadingType, position: token.position, depth: token.depth, children }
90
+ : { type: ast.HeadingType, depth: token.depth, children };
92
91
  return node;
93
- },
92
+ }),
94
93
  };
95
94
  };
96
95
 
package/lib/esm/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { HeadingType } from '@yozora/ast';
2
2
  import { AsciiCodePoint, isSpaceCharacter, calcTrimBoundaryOfCodePoints, isWhitespaceCharacter } from '@yozora/character';
3
- import { eatOptionalCharacters, calcStartYastNodePoint, calcEndYastNodePoint, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
3
+ import { eatOptionalCharacters, calcStartPoint, calcEndPoint, mergeAndStripContentLines, BaseBlockTokenizer, TokenizerPriority } from '@yozora/core-tokenizer';
4
4
 
5
5
  const match = function () {
6
6
  return {
@@ -26,8 +26,8 @@ const match = function () {
26
26
  const token = {
27
27
  nodeType: HeadingType,
28
28
  position: {
29
- start: calcStartYastNodePoint(nodePoints, startIndex),
30
- end: calcEndYastNodePoint(nodePoints, nextIndex - 1),
29
+ start: calcStartPoint(nodePoints, startIndex),
30
+ end: calcEndPoint(nodePoints, nextIndex - 1),
31
31
  },
32
32
  depth: depth,
33
33
  line,
@@ -48,7 +48,7 @@ const match = function () {
48
48
 
49
49
  const parse = function (api) {
50
50
  return {
51
- parse: token => {
51
+ parse: tokens => tokens.map(token => {
52
52
  const { nodePoints, firstNonWhitespaceIndex, endIndex } = token.line;
53
53
  let [leftIndex, rightIndex] = calcTrimBoundaryOfCodePoints(nodePoints, firstNonWhitespaceIndex + token.depth, endIndex);
54
54
  let closeCharCount = 0;
@@ -79,14 +79,13 @@ const parse = function (api) {
79
79
  countOfPrecedeSpaces: 0,
80
80
  },
81
81
  ];
82
- const phrasingContent = api.buildPhrasingContent(lines);
83
- const node = {
84
- type: HeadingType,
85
- depth: token.depth,
86
- children: phrasingContent == null ? [] : [phrasingContent],
87
- };
82
+ const contents = mergeAndStripContentLines(lines);
83
+ const children = api.processInlines(contents);
84
+ const node = api.shouldReservePosition
85
+ ? { type: HeadingType, position: token.position, depth: token.depth, children }
86
+ : { type: HeadingType, depth: token.depth, children };
88
87
  return node;
89
- },
88
+ }),
90
89
  };
91
90
  };
92
91
 
@@ -2,4 +2,4 @@ export { match as headingMatch } from './match';
2
2
  export { parse as headingParse } from './parse';
3
3
  export { HeadingTokenizer, HeadingTokenizer as default } from './tokenizer';
4
4
  export { uniqueName as HeadingTokenizerName } from './types';
5
- export type { IHookContext as IHeadingHookContext, IToken as IHeadingToken, ITokenizerProps as IHeadingTokenizerProps, } from './types';
5
+ export type { IThis as IHeadingHookContext, IToken as IHeadingToken, ITokenizerProps as IHeadingTokenizerProps, } 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
  * An ATX heading consists of a string of characters, parsed as inline content,
5
5
  * between an opening sequence of 1–6 unescaped '#' characters and an optional
@@ -14,4 +14,4 @@ import type { IHookContext, IToken, T } from './types';
14
14
  * @see https://github.com/syntax-tree/mdast#heading
15
15
  * @see https://github.github.com/gfm/#atx-heading
16
16
  */
17
- export declare const match: IMatchBlockHookCreator<T, IToken, IHookContext>;
17
+ 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 { BaseBlockTokenizer } from '@yozora/core-tokenizer';
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 Heading.
6
6
  * @see https://github.com/syntax-tree/mdast#heading
7
7
  * @see https://github.github.com/gfm/#atx-heading
8
8
  */
9
- export declare class HeadingTokenizer extends BaseBlockTokenizer<T, IToken, INode, IHookContext> implements IBlockTokenizer<T, IToken, INode, IHookContext> {
9
+ export declare class HeadingTokenizer extends BaseBlockTokenizer<T, IToken, 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,7 +1,7 @@
1
- import type { HeadingType, IHeading } from '@yozora/ast';
1
+ import type { Heading, HeadingType } from '@yozora/ast';
2
2
  import type { IBaseBlockTokenizerProps, IPartialYastBlockToken, IPhrasingContentLine, ITokenizer } from '@yozora/core-tokenizer';
3
3
  export declare type T = HeadingType;
4
- export declare type INode = IHeading;
4
+ export declare type INode = Heading;
5
5
  export declare const uniqueName = "@yozora/tokenizer-heading";
6
6
  export interface IToken extends IPartialYastBlockToken<T> {
7
7
  /**
@@ -13,5 +13,5 @@ export interface IToken extends IPartialYastBlockToken<T> {
13
13
  */
14
14
  line: Readonly<IPhrasingContentLine>;
15
15
  }
16
- export declare type IHookContext = ITokenizer;
16
+ export declare type IThis = ITokenizer;
17
17
  export declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-heading",
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
  }