@yozora/tokenizer-fenced-code 2.1.2 → 2.1.4

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/lib/cjs/index.cjs CHANGED
@@ -7,6 +7,10 @@ var ast = require('@yozora/ast');
7
7
  var character = require('@yozora/character');
8
8
  var coreTokenizer = require('@yozora/core-tokenizer');
9
9
 
10
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
11
+
12
+ var FencedBlockTokenizer__default = /*#__PURE__*/_interopDefault(FencedBlockTokenizer);
13
+
10
14
  const match = function (api) {
11
15
  const hook = FencedBlockTokenizer.fencedBlockMatch.call(this, api);
12
16
  return {
@@ -55,7 +59,7 @@ const parse = function (api) {
55
59
 
56
60
  const uniqueName = '@yozora/tokenizer-fenced-code';
57
61
 
58
- class FencedCodeTokenizer extends FencedBlockTokenizer {
62
+ class FencedCodeTokenizer extends FencedBlockTokenizer__default.default {
59
63
  constructor(props = {}) {
60
64
  super({
61
65
  name: props.name ?? uniqueName,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-fenced-code",
3
- "version": "2.1.2",
3
+ "version": "2.1.4",
4
4
  "author": {
5
5
  "name": "guanghechen",
6
6
  "url": "https://github.com/guanghechen/"
@@ -27,7 +27,7 @@
27
27
  },
28
28
  "files": [
29
29
  "lib/",
30
- "src/",
30
+ "lib/**/*.map",
31
31
  "package.json",
32
32
  "CHANGELOG.md",
33
33
  "LICENSE",
@@ -39,10 +39,10 @@
39
39
  "test": "cross-env TS_NODE_FILES=true NODE_OPTIONS=--experimental-vm-modules jest --config ../../jest.config.mjs --rootDir ."
40
40
  },
41
41
  "dependencies": {
42
- "@yozora/ast": "^2.1.2",
43
- "@yozora/character": "^2.1.2",
44
- "@yozora/core-tokenizer": "^2.1.2",
45
- "@yozora/tokenizer-fenced-block": "^2.1.2"
42
+ "@yozora/ast": "^2.1.4",
43
+ "@yozora/character": "^2.1.4",
44
+ "@yozora/core-tokenizer": "^2.1.4",
45
+ "@yozora/tokenizer-fenced-block": "^2.1.4"
46
46
  },
47
- "gitHead": "992bacafd173e7788e99fed34ce8b45f6ed24cfe"
47
+ "gitHead": "aa464ed1e3cd84892773a833910cfc53a556bf5f"
48
48
  }
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- export { match as fencedCodeMatch } from './match'
2
- export { parse as fencedCodeParse } from './parse'
3
- export { FencedCodeTokenizer, FencedCodeTokenizer as default } from './tokenizer'
4
- export { uniqueName as FencedCodeTokenizerName } from './types'
5
- export type {
6
- IThis as IFencedCodeHookContext,
7
- IToken as IFencedCodeToken,
8
- ITokenizerProps as IFencedCodeTokenizerProps,
9
- } from './types'
package/src/match.ts DELETED
@@ -1,19 +0,0 @@
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: false,
18
- }
19
- }
package/src/parse.ts DELETED
@@ -1,58 +0,0 @@
1
- import { CodeType } from '@yozora/ast'
2
- import type { INodePoint } from '@yozora/character'
3
- import {
4
- calcEscapedStringFromNodePoints,
5
- calcStringFromNodePoints,
6
- isUnicodeWhitespaceCharacter,
7
- } from '@yozora/character'
8
- import type { IParseBlockHookCreator } from '@yozora/core-tokenizer'
9
- import { eatOptionalWhitespaces, mergeContentLinesFaithfully } from '@yozora/core-tokenizer'
10
- import type { INode, IThis, IToken, T } from './types'
11
-
12
- export const parse: IParseBlockHookCreator<T, IToken, INode, IThis> = function (api) {
13
- return {
14
- parse: tokens =>
15
- tokens.map(token => {
16
- const infoString = token.infoString
17
-
18
- // match lang
19
- let i = 0
20
- const langInfo: INodePoint[] = []
21
- for (; i < infoString.length; ++i) {
22
- const p = infoString[i]
23
- if (isUnicodeWhitespaceCharacter(p.codePoint)) break
24
- langInfo.push(p)
25
- }
26
- const lang: string = calcEscapedStringFromNodePoints(langInfo, 0, langInfo.length, true)
27
-
28
- // match meta
29
- i = eatOptionalWhitespaces(infoString, i, infoString.length)
30
- const meta: string = calcEscapedStringFromNodePoints(infoString, i, infoString.length, true)
31
-
32
- /**
33
- * match content
34
- * Backslash escape works in info strings in fenced code blocks.
35
- * @see https://github.github.com/gfm/#example-320
36
- */
37
- const contents: INodePoint[] = mergeContentLinesFaithfully(token.lines)
38
- let value: string = calcStringFromNodePoints(contents)
39
- if (!/\n$/.test(value)) value += '\n'
40
-
41
- const node: INode = api.shouldReservePosition
42
- ? {
43
- type: CodeType,
44
- position: token.position,
45
- lang: lang.length > 0 ? lang : null,
46
- meta: meta.length > 0 ? meta : null,
47
- value,
48
- }
49
- : {
50
- type: CodeType,
51
- lang: lang.length > 0 ? lang : null,
52
- meta: meta.length > 0 ? meta : null,
53
- value,
54
- }
55
- return node
56
- }),
57
- }
58
- }
package/src/tokenizer.ts DELETED
@@ -1,52 +0,0 @@
1
- import { CodeType } 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 FencedCode.
17
- * @see https://github.com/syntax-tree/mdast#code
18
- * @see https://github.github.com/gfm/#code-fence
19
- */
20
- export class FencedCodeTokenizer
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: CodeType,
30
- markers: [AsciiCodePoint.BACKTICK, AsciiCodePoint.TILDE],
31
- markersRequired: 3,
32
- checkInfoString: (infoString, marker): boolean => {
33
- /**
34
- * Info strings for backtick code blocks cannot contain backticks:
35
- * Info strings for tilde code blocks can contain backticks and tildes
36
- * @see https://github.github.com/gfm/#example-115
37
- * @see https://github.github.com/gfm/#example-116
38
- */
39
- if (marker === AsciiCodePoint.BACKTICK) {
40
- for (const p of infoString) {
41
- if (p.codePoint === AsciiCodePoint.BACKTICK) return false
42
- }
43
- }
44
- return true
45
- },
46
- })
47
- }
48
-
49
- public override readonly match: IMatchBlockHookCreator<T, IToken, IThis> = match
50
-
51
- public override readonly parse: IParseBlockHookCreator<T, IToken, INode, IThis> = parse
52
- }
package/src/types.ts DELETED
@@ -1,13 +0,0 @@
1
- import type { Code, CodeType } from '@yozora/ast'
2
- import type { IBaseBlockTokenizerProps } from '@yozora/core-tokenizer'
3
- import type { IFencedBlockHookContext, IFencedBlockToken } from '@yozora/tokenizer-fenced-block'
4
-
5
- export type T = CodeType
6
- export type INode = Code
7
- export const uniqueName = '@yozora/tokenizer-fenced-code'
8
-
9
- export type IToken = IFencedBlockToken<T>
10
-
11
- export type IThis = IFencedBlockHookContext<T>
12
-
13
- export type ITokenizerProps = Partial<IBaseBlockTokenizerProps>