@yozora/tokenizer-html-inline 2.1.3 → 2.1.5
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/CHANGELOG.md +688 -0
- package/README.md +42 -42
- package/package.json +7 -7
- package/src/index.ts +0 -15
- package/src/match.ts +0 -101
- package/src/parse.ts +0 -20
- package/src/tokenizer.ts +0 -37
- package/src/types.ts +0 -52
- package/src/util/cdata.ts +0 -64
- package/src/util/closing.ts +0 -56
- package/src/util/comment.ts +0 -87
- package/src/util/declaration.ts +0 -77
- package/src/util/instruction.ts +0 -56
- package/src/util/open.ts +0 -88
package/src/util/declaration.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import type { INodeInterval, INodePoint } from '@yozora/character'
|
|
2
|
-
import { AsciiCodePoint, isAsciiUpperLetter, isWhitespaceCharacter } from '@yozora/character'
|
|
3
|
-
import type { ITokenDelimiter } from '@yozora/core-tokenizer'
|
|
4
|
-
|
|
5
|
-
export interface IHtmlInlineDeclarationData {
|
|
6
|
-
htmlType: 'declaration'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export interface IHtmlInlineDeclarationTokenData {
|
|
10
|
-
htmlType: 'declaration'
|
|
11
|
-
tagName: INodeInterval
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export interface IHtmlInlineDeclarationDelimiter
|
|
15
|
-
extends ITokenDelimiter,
|
|
16
|
-
IHtmlInlineDeclarationTokenData {
|
|
17
|
-
type: 'full'
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* A declaration consists of the string `<!`, a name consisting of one or more
|
|
22
|
-
* uppercase ASCII letters, whitespace, a string of characters not including
|
|
23
|
-
* the character `>`, and the character `>`.
|
|
24
|
-
*
|
|
25
|
-
* @param nodePoints
|
|
26
|
-
* @param startIndex
|
|
27
|
-
* @param endIndex
|
|
28
|
-
* @see https://github.github.com/gfm/#declaration
|
|
29
|
-
*/
|
|
30
|
-
export function eatHtmlInlineDeclarationDelimiter(
|
|
31
|
-
nodePoints: ReadonlyArray<INodePoint>,
|
|
32
|
-
startIndex: number,
|
|
33
|
-
endIndex: number,
|
|
34
|
-
): IHtmlInlineDeclarationDelimiter | null {
|
|
35
|
-
let i = startIndex
|
|
36
|
-
if (i + 4 >= endIndex || nodePoints[i + 1].codePoint !== AsciiCodePoint.EXCLAMATION_MARK)
|
|
37
|
-
return null
|
|
38
|
-
|
|
39
|
-
const tagNameStartIndex = i + 2
|
|
40
|
-
|
|
41
|
-
// Try to eating a declaration name.
|
|
42
|
-
for (i = tagNameStartIndex; i < endIndex; ++i) {
|
|
43
|
-
const p = nodePoints[i]
|
|
44
|
-
if (!isAsciiUpperLetter(p.codePoint)) break
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* If no uppercase name or a following whitespace exists,
|
|
49
|
-
* then it's not a valid declaration.
|
|
50
|
-
*/
|
|
51
|
-
if (
|
|
52
|
-
i - tagNameStartIndex <= 0 ||
|
|
53
|
-
i + 1 >= endIndex ||
|
|
54
|
-
!isWhitespaceCharacter(nodePoints[i].codePoint)
|
|
55
|
-
)
|
|
56
|
-
return null
|
|
57
|
-
|
|
58
|
-
const tagNameEndIndex = i,
|
|
59
|
-
si = i + 1
|
|
60
|
-
for (i = si; i < endIndex; ++i) {
|
|
61
|
-
const p = nodePoints[i]
|
|
62
|
-
if (p.codePoint === AsciiCodePoint.CLOSE_ANGLE) {
|
|
63
|
-
const delimiter: IHtmlInlineDeclarationDelimiter = {
|
|
64
|
-
type: 'full',
|
|
65
|
-
startIndex,
|
|
66
|
-
endIndex: i + 1,
|
|
67
|
-
htmlType: 'declaration',
|
|
68
|
-
tagName: {
|
|
69
|
-
startIndex: tagNameStartIndex,
|
|
70
|
-
endIndex: tagNameEndIndex,
|
|
71
|
-
},
|
|
72
|
-
}
|
|
73
|
-
return delimiter
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return null
|
|
77
|
-
}
|
package/src/util/instruction.ts
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { INodePoint } from '@yozora/character'
|
|
2
|
-
import { AsciiCodePoint } from '@yozora/character'
|
|
3
|
-
import type { ITokenDelimiter } from '@yozora/core-tokenizer'
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @see https://github.github.com/gfm/#processing-instruction
|
|
8
|
-
*/
|
|
9
|
-
export interface IHtmlInlineInstructionData {
|
|
10
|
-
htmlType: 'instruction'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export interface IHtmlInlineInstructionTokenData {
|
|
14
|
-
htmlType: 'instruction'
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export interface IHtmlInlineInstructionDelimiter
|
|
18
|
-
extends ITokenDelimiter,
|
|
19
|
-
IHtmlInlineInstructionTokenData {
|
|
20
|
-
type: 'full'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* A processing instruction consists of the string `<?`, a string of characters
|
|
25
|
-
* not including the string `?>`, and the string `?>`.
|
|
26
|
-
*
|
|
27
|
-
* @param nodePoints
|
|
28
|
-
* @param startIndex
|
|
29
|
-
* @param endIndex
|
|
30
|
-
* @see https://github.github.com/gfm/#processing-instruction
|
|
31
|
-
*/
|
|
32
|
-
export function eatHtmlInlineInstructionDelimiter(
|
|
33
|
-
nodePoints: ReadonlyArray<INodePoint>,
|
|
34
|
-
startIndex: number,
|
|
35
|
-
endIndex: number,
|
|
36
|
-
): IHtmlInlineInstructionDelimiter | null {
|
|
37
|
-
let i = startIndex
|
|
38
|
-
if (i + 3 >= endIndex || nodePoints[i + 1].codePoint !== AsciiCodePoint.QUESTION_MARK) return null
|
|
39
|
-
|
|
40
|
-
const si = i + 2
|
|
41
|
-
for (i = si; i < endIndex; ++i) {
|
|
42
|
-
const p = nodePoints[i]
|
|
43
|
-
if (p.codePoint !== AsciiCodePoint.QUESTION_MARK) continue
|
|
44
|
-
if (i + 1 >= endIndex) return null
|
|
45
|
-
if (nodePoints[i + 1].codePoint === AsciiCodePoint.CLOSE_ANGLE) {
|
|
46
|
-
const delimiter: IHtmlInlineInstructionDelimiter = {
|
|
47
|
-
type: 'full',
|
|
48
|
-
startIndex,
|
|
49
|
-
endIndex: i + 2,
|
|
50
|
-
htmlType: 'instruction',
|
|
51
|
-
}
|
|
52
|
-
return delimiter
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return null
|
|
56
|
-
}
|
package/src/util/open.ts
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { INodeInterval, INodePoint } from '@yozora/character'
|
|
2
|
-
import { AsciiCodePoint } from '@yozora/character'
|
|
3
|
-
import type { ITokenDelimiter } from '@yozora/core-tokenizer'
|
|
4
|
-
import { eatOptionalWhitespaces } from '@yozora/core-tokenizer'
|
|
5
|
-
import type { RawHTMLAttribute } from '@yozora/tokenizer-html-block'
|
|
6
|
-
import { eatHTMLAttribute, eatHTMLTagName } from '@yozora/tokenizer-html-block'
|
|
7
|
-
|
|
8
|
-
export interface IHtmlInlineOpenTagData {
|
|
9
|
-
htmlType: 'open'
|
|
10
|
-
/**
|
|
11
|
-
* HTML tag name.
|
|
12
|
-
*/
|
|
13
|
-
tagName: string
|
|
14
|
-
/**
|
|
15
|
-
* HTML attributes.
|
|
16
|
-
*/
|
|
17
|
-
attributes: Array<{ name: string; value?: string }>
|
|
18
|
-
/**
|
|
19
|
-
* Whether if a html tag is self closed.
|
|
20
|
-
*/
|
|
21
|
-
selfClosed: boolean
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface IHtmlInlineOpenTokenData {
|
|
25
|
-
htmlType: 'open'
|
|
26
|
-
tagName: INodeInterval
|
|
27
|
-
attributes: RawHTMLAttribute[]
|
|
28
|
-
selfClosed: boolean
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export interface IHtmlInlineOpenDelimiter extends ITokenDelimiter, IHtmlInlineOpenTokenData {
|
|
32
|
-
type: 'full'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* An open tag consists of a '<' character, a tag name, zero or more attributes,
|
|
37
|
-
* optional whitespace, an optional '/' character, and a '>' character.
|
|
38
|
-
*
|
|
39
|
-
* @param nodePoints
|
|
40
|
-
* @param startIndex
|
|
41
|
-
* @param endIndex
|
|
42
|
-
* @see https://github.github.com/gfm/#open-tag
|
|
43
|
-
*/
|
|
44
|
-
export function eatHtmlInlineTokenOpenDelimiter(
|
|
45
|
-
nodePoints: ReadonlyArray<INodePoint>,
|
|
46
|
-
startIndex: number,
|
|
47
|
-
endIndex: number,
|
|
48
|
-
): IHtmlInlineOpenDelimiter | null {
|
|
49
|
-
let i = startIndex
|
|
50
|
-
if (i + 2 >= endIndex) return null
|
|
51
|
-
|
|
52
|
-
const tagNameStartIndex = i + 1
|
|
53
|
-
const tagNameEndIndex = eatHTMLTagName(nodePoints, tagNameStartIndex, endIndex)
|
|
54
|
-
if (tagNameEndIndex == null) return null
|
|
55
|
-
|
|
56
|
-
const attributes: RawHTMLAttribute[] = []
|
|
57
|
-
for (i = tagNameEndIndex; i < endIndex; ) {
|
|
58
|
-
const result = eatHTMLAttribute(nodePoints, i, endIndex)
|
|
59
|
-
if (result == null) break
|
|
60
|
-
attributes.push(result.attribute)
|
|
61
|
-
i = result.nextIndex
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
i = eatOptionalWhitespaces(nodePoints, i, endIndex)
|
|
65
|
-
if (i >= endIndex) return null
|
|
66
|
-
|
|
67
|
-
let selfClosed = false
|
|
68
|
-
if (nodePoints[i].codePoint === AsciiCodePoint.SLASH) {
|
|
69
|
-
i += 1
|
|
70
|
-
selfClosed = true
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (i >= endIndex || nodePoints[i].codePoint !== AsciiCodePoint.CLOSE_ANGLE) return null
|
|
74
|
-
|
|
75
|
-
const delimiter: IHtmlInlineOpenDelimiter = {
|
|
76
|
-
type: 'full',
|
|
77
|
-
startIndex,
|
|
78
|
-
endIndex: i + 1,
|
|
79
|
-
htmlType: 'open',
|
|
80
|
-
tagName: {
|
|
81
|
-
startIndex: tagNameStartIndex,
|
|
82
|
-
endIndex: tagNameEndIndex,
|
|
83
|
-
},
|
|
84
|
-
attributes,
|
|
85
|
-
selfClosed,
|
|
86
|
-
}
|
|
87
|
-
return delimiter
|
|
88
|
-
}
|