@yozora/tokenizer-footnote 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 +7 -7
- package/src/index.ts +0 -9
- package/src/match.ts +0 -102
- package/src/parse.ts +0 -17
- package/src/tokenizer.ts +0 -35
- package/src/types.ts +0 -24
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yozora/tokenizer-footnote",
|
|
3
|
-
"version": "2.1.
|
|
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
|
-
"
|
|
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.
|
|
43
|
-
"@yozora/character": "^2.1.
|
|
44
|
-
"@yozora/core-tokenizer": "^2.1.
|
|
45
|
-
"@yozora/tokenizer-link": "^2.1.
|
|
42
|
+
"@yozora/ast": "^2.1.4",
|
|
43
|
+
"@yozora/character": "^2.1.4",
|
|
44
|
+
"@yozora/core-tokenizer": "^2.1.4",
|
|
45
|
+
"@yozora/tokenizer-link": "^2.1.4"
|
|
46
46
|
},
|
|
47
|
-
"gitHead": "
|
|
47
|
+
"gitHead": "aa464ed1e3cd84892773a833910cfc53a556bf5f"
|
|
48
48
|
}
|
package/src/index.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export { match as footnoteMatch } from './match'
|
|
2
|
-
export { parse as footnoteParse } from './parse'
|
|
3
|
-
export { FootnoteTokenizer, FootnoteTokenizer as default } from './tokenizer'
|
|
4
|
-
export { uniqueName as FootnoteTokenizerName } from './types'
|
|
5
|
-
export type {
|
|
6
|
-
IThis as IFootnoteHookContext,
|
|
7
|
-
IToken as IFootnoteToken,
|
|
8
|
-
ITokenizerProps as IFootnoteTokenizerProps,
|
|
9
|
-
} from './types'
|
package/src/match.ts
DELETED
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
import { FootnoteType } from '@yozora/ast'
|
|
2
|
-
import type { INodePoint } from '@yozora/character'
|
|
3
|
-
import { AsciiCodePoint } from '@yozora/character'
|
|
4
|
-
import type {
|
|
5
|
-
IInlineToken,
|
|
6
|
-
IMatchInlineHookCreator,
|
|
7
|
-
IResultOfIsDelimiterPair,
|
|
8
|
-
IResultOfProcessDelimiterPair,
|
|
9
|
-
} from '@yozora/core-tokenizer'
|
|
10
|
-
import { genFindDelimiter } from '@yozora/core-tokenizer'
|
|
11
|
-
import { checkBalancedBracketsStatus } from '@yozora/tokenizer-link'
|
|
12
|
-
import type { IDelimiter, IThis, IToken, T } from './types'
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* An inline footnote consists of a footnote text followed immediately by a right
|
|
16
|
-
* square bracket ']'.
|
|
17
|
-
*
|
|
18
|
-
* Like the inline links, footnote could not be contained by other footnote.
|
|
19
|
-
*
|
|
20
|
-
* @see https://github.com/syntax-tree/mdast-util-footnote
|
|
21
|
-
* @see https://github.com/remarkjs/remark-footnotes
|
|
22
|
-
* @see https://github.com/syntax-tree/mdast#link
|
|
23
|
-
* @see https://github.github.com/gfm/#links
|
|
24
|
-
* @see https://www.markdownguide.org/extended-syntax/#footnotes
|
|
25
|
-
*/
|
|
26
|
-
export const match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis> = function (api) {
|
|
27
|
-
return {
|
|
28
|
-
findDelimiter: () => genFindDelimiter<IDelimiter>(_findDelimiter),
|
|
29
|
-
isDelimiterPair,
|
|
30
|
-
processDelimiterPair,
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function _findDelimiter(startIndex: number, endIndex: number): IDelimiter | null {
|
|
34
|
-
const nodePoints: ReadonlyArray<INodePoint> = api.getNodePoints()
|
|
35
|
-
|
|
36
|
-
for (let i = startIndex; i < endIndex; ++i) {
|
|
37
|
-
const c = nodePoints[i].codePoint
|
|
38
|
-
switch (c) {
|
|
39
|
-
case AsciiCodePoint.BACKSLASH:
|
|
40
|
-
i += 1
|
|
41
|
-
break
|
|
42
|
-
case AsciiCodePoint.CARET: {
|
|
43
|
-
if (i + 1 < endIndex && nodePoints[i + 1].codePoint === AsciiCodePoint.OPEN_BRACKET) {
|
|
44
|
-
return {
|
|
45
|
-
type: 'opener',
|
|
46
|
-
startIndex: i,
|
|
47
|
-
endIndex: i + 2,
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
break
|
|
51
|
-
}
|
|
52
|
-
case AsciiCodePoint.CLOSE_BRACKET:
|
|
53
|
-
return {
|
|
54
|
-
type: 'closer',
|
|
55
|
-
startIndex: i,
|
|
56
|
-
endIndex: i + 1,
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return null
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function isDelimiterPair(
|
|
64
|
-
openerDelimiter: IDelimiter,
|
|
65
|
-
closerDelimiter: IDelimiter,
|
|
66
|
-
internalTokens: ReadonlyArray<IInlineToken>,
|
|
67
|
-
): IResultOfIsDelimiterPair {
|
|
68
|
-
const nodePoints: ReadonlyArray<INodePoint> = api.getNodePoints()
|
|
69
|
-
const balancedBracketsStatus: -1 | 0 | 1 = checkBalancedBracketsStatus(
|
|
70
|
-
openerDelimiter.endIndex,
|
|
71
|
-
closerDelimiter.startIndex,
|
|
72
|
-
internalTokens,
|
|
73
|
-
nodePoints,
|
|
74
|
-
)
|
|
75
|
-
switch (balancedBracketsStatus) {
|
|
76
|
-
case -1:
|
|
77
|
-
return { paired: false, opener: false, closer: true }
|
|
78
|
-
case 0:
|
|
79
|
-
return { paired: true }
|
|
80
|
-
case 1:
|
|
81
|
-
return { paired: false, opener: true, closer: false }
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
function processDelimiterPair(
|
|
86
|
-
openerDelimiter: IDelimiter,
|
|
87
|
-
closerDelimiter: IDelimiter,
|
|
88
|
-
internalTokens: ReadonlyArray<IInlineToken>,
|
|
89
|
-
): IResultOfProcessDelimiterPair<T, IToken, IDelimiter> {
|
|
90
|
-
const token: IToken = {
|
|
91
|
-
nodeType: FootnoteType,
|
|
92
|
-
startIndex: openerDelimiter.startIndex,
|
|
93
|
-
endIndex: closerDelimiter.endIndex,
|
|
94
|
-
children: api.resolveInternalTokens(
|
|
95
|
-
internalTokens,
|
|
96
|
-
openerDelimiter.endIndex,
|
|
97
|
-
closerDelimiter.startIndex,
|
|
98
|
-
),
|
|
99
|
-
}
|
|
100
|
-
return { tokens: [token] }
|
|
101
|
-
}
|
|
102
|
-
}
|
package/src/parse.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { Node } from '@yozora/ast'
|
|
2
|
-
import { FootnoteType } from '@yozora/ast'
|
|
3
|
-
import type { IParseInlineHookCreator } from '@yozora/core-tokenizer'
|
|
4
|
-
import type { INode, IThis, IToken, T } from './types'
|
|
5
|
-
|
|
6
|
-
export const parse: IParseInlineHookCreator<T, IToken, INode, IThis> = function (api) {
|
|
7
|
-
return {
|
|
8
|
-
parse: tokens =>
|
|
9
|
-
tokens.map(token => {
|
|
10
|
-
const children: Node[] = api.parseInlineTokens(token.children)
|
|
11
|
-
const node: INode = api.shouldReservePosition
|
|
12
|
-
? { type: FootnoteType, position: api.calcPosition(token), children }
|
|
13
|
-
: { type: FootnoteType, children }
|
|
14
|
-
return node
|
|
15
|
-
}),
|
|
16
|
-
}
|
|
17
|
-
}
|
package/src/tokenizer.ts
DELETED
|
@@ -1,35 +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 type { IDelimiter, INode, IThis, IToken, ITokenizerProps, T } from './types'
|
|
10
|
-
import { uniqueName } from './types'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Lexical Analyzer for inline footnote.
|
|
14
|
-
* @see https://github.com/syntax-tree/mdast-util-footnote
|
|
15
|
-
* @see https://github.com/remarkjs/remark-footnotes
|
|
16
|
-
* @see https://github.com/syntax-tree/mdast#link
|
|
17
|
-
* @see https://github.github.com/gfm/#links
|
|
18
|
-
* @see https://www.markdownguide.org/extended-syntax/#footnotes
|
|
19
|
-
*/
|
|
20
|
-
export class FootnoteTokenizer
|
|
21
|
-
extends BaseInlineTokenizer<T, IDelimiter, IToken, INode, IThis>
|
|
22
|
-
implements IInlineTokenizer<T, IDelimiter, IToken, INode, IThis>
|
|
23
|
-
{
|
|
24
|
-
/* istanbul ignore next */
|
|
25
|
-
constructor(props: ITokenizerProps = {}) {
|
|
26
|
-
super({
|
|
27
|
-
name: props.name ?? uniqueName,
|
|
28
|
-
priority: props.priority ?? TokenizerPriority.LINKS,
|
|
29
|
-
})
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
public override readonly match: IMatchInlineHookCreator<T, IDelimiter, IToken, IThis> = match
|
|
33
|
-
|
|
34
|
-
public override readonly parse: IParseInlineHookCreator<T, IToken, INode, IThis> = parse
|
|
35
|
-
}
|
package/src/types.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { Footnote, FootnoteType } from '@yozora/ast'
|
|
2
|
-
import type {
|
|
3
|
-
IBaseInlineTokenizerProps,
|
|
4
|
-
IPartialInlineToken,
|
|
5
|
-
ITokenDelimiter,
|
|
6
|
-
ITokenizer,
|
|
7
|
-
} from '@yozora/core-tokenizer'
|
|
8
|
-
|
|
9
|
-
export type T = FootnoteType
|
|
10
|
-
export type INode = Footnote
|
|
11
|
-
export const uniqueName = '@yozora/tokenizer-footnote'
|
|
12
|
-
|
|
13
|
-
export type IToken = IPartialInlineToken<T>
|
|
14
|
-
|
|
15
|
-
export interface IDelimiter extends ITokenDelimiter {
|
|
16
|
-
/**
|
|
17
|
-
* IDelimiter type.
|
|
18
|
-
*/
|
|
19
|
-
type: 'opener' | 'closer'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export type IThis = ITokenizer
|
|
23
|
-
|
|
24
|
-
export type ITokenizerProps = Partial<IBaseInlineTokenizerProps>
|