@yozora/tokenizer-link 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.
@@ -1,82 +0,0 @@
1
- import type { INodePoint } from '@yozora/character'
2
- import { AsciiCodePoint, VirtualCodePoint } from '@yozora/character'
3
- import { eatOptionalBlankLines } from '@yozora/core-tokenizer'
4
-
5
- /**
6
- * A link title consists of either
7
- *
8
- * - a sequence of zero or more characters between straight double-quote
9
- * characters '"', including a '"' character only if it is backslash-escaped, or
10
- *
11
- * - a sequence of zero or more characters between straight single-quote
12
- * characters '\'', including a '\'' character only if it is backslash-escaped, or
13
- *
14
- * - a sequence of zero or more characters between matching parentheses '(...)',
15
- * including a '(' or ')' character only if it is backslash-escaped.
16
- */
17
- export function eatLinkTitle(
18
- nodePoints: ReadonlyArray<INodePoint>,
19
- startIndex: number,
20
- endIndex: number,
21
- ): number {
22
- if (startIndex >= endIndex) return -1
23
-
24
- let i = startIndex
25
- const titleWrapSymbol = nodePoints[i].codePoint
26
- switch (titleWrapSymbol) {
27
- case AsciiCodePoint.DOUBLE_QUOTE:
28
- case AsciiCodePoint.SINGLE_QUOTE: {
29
- for (i += 1; i < endIndex; ++i) {
30
- const p = nodePoints[i]
31
- switch (p.codePoint) {
32
- case AsciiCodePoint.BACKSLASH:
33
- i += 1
34
- break
35
- case titleWrapSymbol:
36
- return i + 1
37
- /**
38
- * Although link titles may span multiple lines, they may not contain a blank line.
39
- */
40
- case VirtualCodePoint.LINE_END: {
41
- const j = eatOptionalBlankLines(nodePoints, startIndex, i)
42
- if (nodePoints[j].line > p.line + 1) return -1
43
- break
44
- }
45
- }
46
- }
47
- break
48
- }
49
- case AsciiCodePoint.OPEN_PARENTHESIS: {
50
- let openParens = 1
51
- for (i += 1; i < endIndex; ++i) {
52
- const p = nodePoints[i]
53
- switch (p.codePoint) {
54
- case AsciiCodePoint.BACKSLASH:
55
- i += 1
56
- break
57
- /**
58
- * Although link titles may span multiple lines, they may not contain a blank line.
59
- */
60
- case VirtualCodePoint.LINE_END: {
61
- const j = eatOptionalBlankLines(nodePoints, startIndex, i)
62
- if (nodePoints[j].line > p.line + 1) return -1
63
- break
64
- }
65
- case AsciiCodePoint.OPEN_PARENTHESIS:
66
- openParens += 1
67
- break
68
- case AsciiCodePoint.CLOSE_PARENTHESIS:
69
- openParens -= 1
70
- if (openParens === 0) return i + 1
71
- break
72
- }
73
- }
74
- break
75
- }
76
- case AsciiCodePoint.CLOSE_PARENTHESIS:
77
- return i
78
- default:
79
- return -1
80
- }
81
- return -1
82
- }