@yozora/tokenizer-break 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yozora/tokenizer-break",
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,9 +39,9 @@
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"
42
+ "@yozora/ast": "^2.1.4",
43
+ "@yozora/character": "^2.1.4",
44
+ "@yozora/core-tokenizer": "^2.1.4"
45
45
  },
46
- "gitHead": "992bacafd173e7788e99fed34ce8b45f6ed24cfe"
46
+ "gitHead": "aa464ed1e3cd84892773a833910cfc53a556bf5f"
47
47
  }
package/src/index.ts DELETED
@@ -1,9 +0,0 @@
1
- export { match as breakMatch } from './match'
2
- export { parse as breakParse } from './parse'
3
- export { BreakTokenizer, BreakTokenizer as default } from './tokenizer'
4
- export { uniqueName as BreakTokenizerName } from './types'
5
- export type {
6
- IThis as IBreakHookContext,
7
- IToken as IBreakToken,
8
- ITokenizerProps as IBreakTokenizerProps,
9
- } from './types'
package/src/match.ts DELETED
@@ -1,104 +0,0 @@
1
- import { BreakType } from '@yozora/ast'
2
- import type { INodePoint } from '@yozora/character'
3
- import { AsciiCodePoint, VirtualCodePoint } from '@yozora/character'
4
- import type {
5
- IMatchInlineHookCreator,
6
- IResultOfProcessSingleDelimiter,
7
- } from '@yozora/core-tokenizer'
8
- import { genFindDelimiter } from '@yozora/core-tokenizer'
9
- import { BreakTokenMarkerType } from './types'
10
- import type { IDelimiter, IThis, IToken, T } from './types'
11
-
12
- /**
13
- * A line break (not in a code span or HTML tag) that is preceded by two or more
14
- * spaces and does not occur at the end of a block is parsed as a hard line
15
- * break (rendered in HTML as a <br /> tag)
16
- * @see https://github.github.com/gfm/#hard-line-breaks
17
- *
18
- * A regular line break (not in a code span or HTML tag) that is not preceded
19
- * by two or more spaces or a backslash is parsed as a softbreak. (A softbreak
20
- * may be rendered in HTML either as a line ending or as a space. The result
21
- * will be the same in browsers.
22
- * @see https://github.github.com/gfm/#soft-line-breaks
23
- *
24
- * @see https://github.com/syntax-tree/mdast#break
25
- */
26
- export const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis> = function (api) {
27
- return {
28
- findDelimiter: () => genFindDelimiter<IDelimiter>(_findDelimiter),
29
- processSingleDelimiter,
30
- }
31
-
32
- function _findDelimiter(startIndex: number, endIndex: number): IDelimiter | null {
33
- const nodePoints: ReadonlyArray<INodePoint> = api.getNodePoints()
34
- for (let i = startIndex + 1; i < endIndex; ++i) {
35
- if (nodePoints[i].codePoint !== VirtualCodePoint.LINE_END) continue
36
-
37
- const c = nodePoints[i - 1].codePoint
38
- let _start: number | null = null
39
- let markerType: BreakTokenMarkerType | null = null
40
- switch (c) {
41
- /**
42
- * For a more visible alternative, a backslash
43
- * before the line ending may be used instead of two spaces
44
- * @see https://github.github.com/gfm/#example-655
45
- */
46
- case AsciiCodePoint.BACKSLASH: {
47
- let x = i - 2
48
- for (; x >= startIndex; x -= 1) {
49
- if (nodePoints[x].codePoint !== AsciiCodePoint.BACKSLASH) break
50
- }
51
- if (((i - x) & 1) === 0) {
52
- _start = i - 1
53
- markerType = BreakTokenMarkerType.BACKSLASH
54
- }
55
- break
56
- }
57
- /**
58
- * - A line break (not in a code span or HTML tag) that is preceded
59
- * by two or more spaces and does not occur at the end of a block
60
- * is parsed as a hard line break (rendered in HTML as a <br /> tag)
61
- * - More than two spaces can be used
62
- * - Leading spaces at the beginning of the next line are ignored
63
- *
64
- * @see https://github.github.com/gfm/#example-654
65
- * @see https://github.github.com/gfm/#example-656
66
- * @see https://github.github.com/gfm/#example-657
67
- */
68
- case AsciiCodePoint.SPACE: {
69
- let x = i - 2
70
- for (; x >= startIndex; x -= 1) {
71
- if (nodePoints[x].codePoint !== AsciiCodePoint.SPACE) break
72
- }
73
-
74
- if (i - x > 2) {
75
- _start = x + 1
76
- markerType = BreakTokenMarkerType.MORE_THAN_TWO_SPACES
77
- }
78
- break
79
- }
80
- }
81
-
82
- if (_start == null || markerType == null) continue
83
-
84
- return {
85
- type: 'full',
86
- markerType,
87
- startIndex: _start,
88
- endIndex: i,
89
- }
90
- }
91
- return null
92
- }
93
-
94
- function processSingleDelimiter(
95
- delimiter: IDelimiter,
96
- ): IResultOfProcessSingleDelimiter<T, IToken> {
97
- const token: IToken = {
98
- nodeType: BreakType,
99
- startIndex: delimiter.startIndex,
100
- endIndex: delimiter.endIndex,
101
- }
102
- return [token]
103
- }
104
- }
package/src/parse.ts DELETED
@@ -1,15 +0,0 @@
1
- import { BreakType } from '@yozora/ast'
2
- import type { IParseInlineHookCreator } from '@yozora/core-tokenizer'
3
- import type { INode, IThis, IToken, T } from './types'
4
-
5
- export const parse: IParseInlineHookCreator<T, IToken, INode, IThis> = function (api) {
6
- return {
7
- parse: tokens =>
8
- tokens.map(token => {
9
- const node: INode = api.shouldReservePosition
10
- ? { type: BreakType, position: api.calcPosition(token) }
11
- : { type: BreakType }
12
- return node
13
- }),
14
- }
15
- }
package/src/tokenizer.ts DELETED
@@ -1,33 +0,0 @@
1
- import type {
2
- IInlineTokenizer,
3
- IMatchInlineHookCreator,
4
- IParseInlineHookCreator,
5
- } from '@yozora/core-tokenizer'
6
- import { BaseInlineTokenizer, TokenizerPriority } from '@yozora/core-tokenizer'
7
- import { match } from './match'
8
- import { parse } from './parse'
9
- import { uniqueName } from './types'
10
- import type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types'
11
-
12
- /**
13
- * Lexical Analyzer for a line break.
14
- * @see https://github.github.com/gfm/#hard-line-breaks
15
- * @see https://github.github.com/gfm/#soft-line-breaks
16
- * @see https://github.com/syntax-tree/mdast#break
17
- */
18
- export class BreakTokenizer
19
- extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis>
20
- implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis>
21
- {
22
- /* istanbul ignore next */
23
- constructor(props: ITokenizerProps = {}) {
24
- super({
25
- name: props.name ?? uniqueName,
26
- priority: props.priority ?? TokenizerPriority.SOFT_INLINE,
27
- })
28
- }
29
-
30
- public override readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis> = match
31
-
32
- public override readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis> = parse
33
- }
package/src/types.ts DELETED
@@ -1,39 +0,0 @@
1
- import type { Break, BreakType } from '@yozora/ast'
2
- import type {
3
- IBaseInlineTokenizerProps,
4
- IPartialInlineToken,
5
- ITokenDelimiter,
6
- ITokenizer,
7
- } from '@yozora/core-tokenizer'
8
-
9
- export type T = BreakType
10
- export type INode = Break
11
- export const uniqueName = '@yozora/tokenizer-break'
12
-
13
- export type IToken = IPartialInlineToken<T>
14
-
15
- export interface IDelimiter extends ITokenDelimiter {
16
- type: 'full'
17
- /**
18
- * Line break marker type.
19
- */
20
- markerType: BreakTokenMarkerType
21
- }
22
-
23
- export type IThis = ITokenizer
24
-
25
- export type ITokenizerProps = Partial<IBaseInlineTokenizerProps>
26
-
27
- /**
28
- * Line break marker type.
29
- */
30
- export enum BreakTokenMarkerType {
31
- /**
32
- * Backslash at the end of the line
33
- */
34
- BACKSLASH = 'backslash',
35
- /**
36
- * More than two spaces at the end of the line
37
- */
38
- MORE_THAN_TWO_SPACES = 'more-than-two-spaces',
39
- }