@yozora/tokenizer-admonition 2.0.4 → 2.0.5-alpha.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.
@@ -7,13 +7,13 @@ var ast = require('@yozora/ast');
7
7
  var character = require('@yozora/character');
8
8
  var coreTokenizer = require('@yozora/core-tokenizer');
9
9
 
10
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
11
-
12
- var FencedBlockTokenizer__default = /*#__PURE__*/_interopDefaultLegacy(FencedBlockTokenizer);
13
-
14
10
  const match = function (api) {
15
11
  const hook = FencedBlockTokenizer.fencedBlockMatch.call(this, api);
16
- return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
12
+ return {
13
+ ...hook,
14
+ isContainingBlock: true,
15
+ onClose,
16
+ };
17
17
  function onClose(token) {
18
18
  const children = api.rollbackPhrasingLines(token.lines);
19
19
  token.children = children;
@@ -60,23 +60,22 @@ const parse = function (api) {
60
60
 
61
61
  const uniqueName = '@yozora/tokenizer-admonition';
62
62
 
63
- class AdmonitionTokenizer extends FencedBlockTokenizer__default["default"] {
63
+ class AdmonitionTokenizer extends FencedBlockTokenizer {
64
64
  constructor(props = {}) {
65
- var _a, _b;
66
65
  super({
67
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
68
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : coreTokenizer.TokenizerPriority.FENCED_BLOCK,
66
+ name: props.name ?? uniqueName,
67
+ priority: props.priority ?? coreTokenizer.TokenizerPriority.FENCED_BLOCK,
69
68
  nodeType: ast.AdmonitionType,
70
69
  markers: [character.AsciiCodePoint.COLON],
71
70
  markersRequired: 3,
72
71
  });
73
- this.match = match;
74
- this.parse = parse;
75
72
  }
73
+ match = match;
74
+ parse = parse;
76
75
  }
77
76
 
78
77
  exports.AdmonitionTokenizer = AdmonitionTokenizer;
79
78
  exports.AdmonitionTokenizerName = uniqueName;
80
79
  exports.admonitionMatch = match;
81
80
  exports.admonitionParse = parse;
82
- exports["default"] = AdmonitionTokenizer;
81
+ exports.default = AdmonitionTokenizer;
@@ -5,7 +5,11 @@ import { eatOptionalWhitespaces, mergeAndStripContentLines, TokenizerPriority }
5
5
 
6
6
  const match = function (api) {
7
7
  const hook = fencedBlockMatch.call(this, api);
8
- return Object.assign(Object.assign({}, hook), { isContainingBlock: true, onClose });
8
+ return {
9
+ ...hook,
10
+ isContainingBlock: true,
11
+ onClose,
12
+ };
9
13
  function onClose(token) {
10
14
  const children = api.rollbackPhrasingLines(token.lines);
11
15
  token.children = children;
@@ -54,17 +58,16 @@ const uniqueName = '@yozora/tokenizer-admonition';
54
58
 
55
59
  class AdmonitionTokenizer extends FencedBlockTokenizer {
56
60
  constructor(props = {}) {
57
- var _a, _b;
58
61
  super({
59
- name: (_a = props.name) !== null && _a !== void 0 ? _a : uniqueName,
60
- priority: (_b = props.priority) !== null && _b !== void 0 ? _b : TokenizerPriority.FENCED_BLOCK,
62
+ name: props.name ?? uniqueName,
63
+ priority: props.priority ?? TokenizerPriority.FENCED_BLOCK,
61
64
  nodeType: AdmonitionType,
62
65
  markers: [AsciiCodePoint.COLON],
63
66
  markersRequired: 3,
64
67
  });
65
- this.match = match;
66
- this.parse = parse;
67
68
  }
69
+ match = match;
70
+ parse = parse;
68
71
  }
69
72
 
70
73
  export { AdmonitionTokenizer, uniqueName as AdmonitionTokenizerName, match as admonitionMatch, parse as admonitionParse, AdmonitionTokenizer as default };
@@ -2,8 +2,8 @@ import { IYastBlockToken, IBaseBlockTokenizerProps, IMatchBlockHookCreator, IPar
2
2
  import { AdmonitionType, Admonition } from '@yozora/ast';
3
3
  import FencedBlockTokenizer, { IFencedBlockToken, IFencedBlockHookContext } from '@yozora/tokenizer-fenced-block';
4
4
 
5
- declare type T = AdmonitionType;
6
- declare type INode = Admonition;
5
+ type T = AdmonitionType;
6
+ type INode = Admonition;
7
7
  declare const uniqueName = "@yozora/tokenizer-admonition";
8
8
  interface IToken extends IFencedBlockToken<T> {
9
9
  /**
@@ -11,8 +11,8 @@ interface IToken extends IFencedBlockToken<T> {
11
11
  */
12
12
  children?: IYastBlockToken[];
13
13
  }
14
- declare type IThis = IFencedBlockHookContext<T>;
15
- declare type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
14
+ type IThis = IFencedBlockHookContext<T>;
15
+ type ITokenizerProps = Partial<IBaseBlockTokenizerProps>;
16
16
 
17
17
  /**
18
18
  * A code fence is a sequence of at least three consecutive backtick characters
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-admonition",
3
- "version": "2.0.4",
3
+ "version": "2.0.5-alpha.0",
4
4
  "description": "Tokenizer for processing admonitions",
5
5
  "author": {
6
6
  "name": "guanghechen",
@@ -18,34 +18,38 @@
18
18
  "tokenizer",
19
19
  "admonition"
20
20
  ],
21
- "main": "lib/cjs/index.js",
22
- "module": "lib/esm/index.js",
23
- "types": "lib/types/index.d.ts",
24
- "source": "src/index.ts",
21
+ "type": "module",
22
+ "exports": {
23
+ "types": "./lib/types/index.d.ts",
24
+ "import": "./lib/esm/index.mjs",
25
+ "require": "./lib/cjs/index.cjs"
26
+ },
27
+ "source": "./src/index.ts",
28
+ "types": "./lib/types/index.d.ts",
29
+ "main": "./lib/cjs/index.cjs",
30
+ "module": "./lib/esm/index.mjs",
25
31
  "license": "MIT",
26
32
  "engines": {
27
33
  "node": ">= 16.0.0"
28
34
  },
29
35
  "files": [
30
36
  "lib/",
31
- "!lib/**/*.js.map",
32
- "!lib/**/*.d.ts.map",
37
+ "src/",
33
38
  "package.json",
34
39
  "CHANGELOG.md",
35
40
  "LICENSE",
36
41
  "README.md"
37
42
  ],
38
43
  "scripts": {
39
- "build": "cross-env NODE_ENV=production rollup -c ../../rollup.config.js",
40
- "prebuild": "rimraf lib/",
44
+ "build": "rimraf lib/ && cross-env NODE_ENV=production rollup -c ../../rollup.config.mjs",
41
45
  "prepublishOnly": "cross-env ROLLUP_SHOULD_SOURCEMAP=false yarn build",
42
- "test": "cross-env TS_NODE_FILES=true jest --config ../../jest.config.js --rootDir ."
46
+ "test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
43
47
  },
44
48
  "dependencies": {
45
- "@yozora/ast": "^2.0.4",
46
- "@yozora/character": "^2.0.4",
47
- "@yozora/core-tokenizer": "^2.0.4",
48
- "@yozora/tokenizer-fenced-block": "^2.0.4"
49
+ "@yozora/ast": "^2.0.5-alpha.0",
50
+ "@yozora/character": "^2.0.5-alpha.0",
51
+ "@yozora/core-tokenizer": "^2.0.5-alpha.0",
52
+ "@yozora/tokenizer-fenced-block": "^2.0.5-alpha.0"
49
53
  },
50
- "gitHead": "c980b95254394dcacba0cbb4bea251350b09397c"
54
+ "gitHead": "8bf941fe4ef82947165b0f3cc123cd493665e13b"
51
55
  }
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
1
+ export { match as admonitionMatch } from './match'
2
+ export { parse as admonitionParse } from './parse'
3
+ export { AdmonitionTokenizer, AdmonitionTokenizer as default } from './tokenizer'
4
+ export { uniqueName as AdmonitionTokenizerName } from './types'
5
+ export type {
6
+ IThis as IAdmonitionHookContext,
7
+ IToken as IAdmonitionToken,
8
+ ITokenizerProps as IAdmonitionTokenizerProps,
9
+ } from './types'
package/src/match.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { IMatchBlockHook, IMatchBlockHookCreator } from '@yozora/core-tokenizer'
2
+ import { fencedBlockMatch } from '@yozora/tokenizer-fenced-block'
3
+ import type { IThis, IToken, T } from './types'
4
+
5
+ /**
6
+ * A code fence is a sequence of at least three consecutive backtick characters
7
+ * (`) or tildes (~). (Tildes and backticks cannot be mixed.) A fenced code
8
+ * block begins with a code fence, indented no more than three spaces.
9
+ *
10
+ * @see https://github.com/syntax-tree/mdast#code
11
+ * @see https://github.github.com/gfm/#code-fence
12
+ */
13
+ export const match: IMatchBlockHookCreator<T, IToken, IThis> = function (api) {
14
+ const hook = fencedBlockMatch.call(this, api) as IMatchBlockHook<T, IToken>
15
+ return {
16
+ ...hook,
17
+ isContainingBlock: true,
18
+ onClose,
19
+ }
20
+
21
+ function onClose(token: IToken): void {
22
+ const children = api.rollbackPhrasingLines(token.lines)
23
+ // eslint-disable-next-line no-param-reassign
24
+ token.children = children
25
+ }
26
+ }
package/src/parse.ts ADDED
@@ -0,0 +1,54 @@
1
+ import type { Node } from '@yozora/ast'
2
+ import { AdmonitionType } from '@yozora/ast'
3
+ import type { INodePoint } from '@yozora/character'
4
+ import { calcEscapedStringFromNodePoints, isUnicodeWhitespaceCharacter } from '@yozora/character'
5
+ import type { IParseBlockHookCreator, IPhrasingContentLine } from '@yozora/core-tokenizer'
6
+ import { eatOptionalWhitespaces, mergeAndStripContentLines } from '@yozora/core-tokenizer'
7
+ import type { INode, IThis, IToken, T } from './types'
8
+
9
+ export const parse: IParseBlockHookCreator<T, IToken, INode, IThis> = function (api) {
10
+ return {
11
+ parse: tokens =>
12
+ tokens.map(token => {
13
+ const infoString = token.infoString
14
+
15
+ // Match an admonition keyword.
16
+ let i = 0
17
+ const keywordNodePoints: INodePoint[] = []
18
+ for (; i < infoString.length; ++i) {
19
+ const p = infoString[i]
20
+ if (isUnicodeWhitespaceCharacter(p.codePoint)) break
21
+ keywordNodePoints.push(p)
22
+ }
23
+
24
+ i = eatOptionalWhitespaces(infoString, i, infoString.length)
25
+ const title: Node[] = ((): Node[] => {
26
+ if (i >= infoString.length) return []
27
+ const titleLines: IPhrasingContentLine[] = [
28
+ {
29
+ nodePoints: infoString,
30
+ startIndex: i,
31
+ endIndex: infoString.length,
32
+ firstNonWhitespaceIndex: i,
33
+ countOfPrecedeSpaces: 0,
34
+ },
35
+ ]
36
+ const contents: INodePoint[] = mergeAndStripContentLines(titleLines)
37
+ return api.processInlines(contents)
38
+ })()
39
+
40
+ const keyword: string = calcEscapedStringFromNodePoints(
41
+ keywordNodePoints,
42
+ 0,
43
+ keywordNodePoints.length,
44
+ true,
45
+ )
46
+ const children: Node[] = api.parseBlockTokens(token.children)
47
+
48
+ const node: INode = api.shouldReservePosition
49
+ ? { type: AdmonitionType, position: token.position, keyword, title, children }
50
+ : { type: AdmonitionType, keyword, title, children }
51
+ return node
52
+ }),
53
+ }
54
+ }
@@ -0,0 +1,38 @@
1
+ import { AdmonitionType } from '@yozora/ast'
2
+ import { AsciiCodePoint } from '@yozora/character'
3
+ import type {
4
+ IBlockTokenizer,
5
+ IMatchBlockHookCreator,
6
+ IParseBlockHookCreator,
7
+ } from '@yozora/core-tokenizer'
8
+ import { TokenizerPriority } from '@yozora/core-tokenizer'
9
+ import FencedBlockTokenizer from '@yozora/tokenizer-fenced-block'
10
+ import { match } from './match'
11
+ import { parse } from './parse'
12
+ import type { INode, IThis, IToken, ITokenizerProps, T } from './types'
13
+ import { uniqueName } from './types'
14
+
15
+ /**
16
+ * Lexical Analyzer for Admonition.
17
+ * @see https://github.com/syntax-tree/mdast#code
18
+ * @see https://github.github.com/gfm/#code-fence
19
+ */
20
+ export class AdmonitionTokenizer
21
+ extends FencedBlockTokenizer<T, INode, IThis>
22
+ implements IBlockTokenizer<T, IToken, INode, IThis>
23
+ {
24
+ /* istanbul ignore next */
25
+ constructor(props: ITokenizerProps = {}) {
26
+ super({
27
+ name: props.name ?? uniqueName,
28
+ priority: props.priority ?? TokenizerPriority.FENCED_BLOCK,
29
+ nodeType: AdmonitionType,
30
+ markers: [AsciiCodePoint.COLON],
31
+ markersRequired: 3,
32
+ })
33
+ }
34
+
35
+ public override readonly match: IMatchBlockHookCreator<T, IToken, IThis> = match
36
+
37
+ public override readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis> = parse
38
+ }
package/src/types.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { Admonition, AdmonitionType } from '@yozora/ast'
2
+ import type { IBaseBlockTokenizerProps, IYastBlockToken } from '@yozora/core-tokenizer'
3
+ import type { IFencedBlockHookContext, IFencedBlockToken } from '@yozora/tokenizer-fenced-block'
4
+
5
+ export type T = AdmonitionType
6
+ export type INode = Admonition
7
+ export const uniqueName = '@yozora/tokenizer-admonition'
8
+
9
+ export interface IToken extends IFencedBlockToken<T> {
10
+ /**
11
+ *
12
+ */
13
+ children?: IYastBlockToken[]
14
+ }
15
+
16
+ export type IThis = IFencedBlockHookContext<T>
17
+
18
+ export type ITokenizerProps = Partial<IBaseBlockTokenizerProps>