pantsdown 2.2.3 → 2.2.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/.oxfmtrc.json +17 -0
- package/CLAUDE.md +1 -0
- package/bun.lock +1500 -0
- package/eslint.config.ts +46 -0
- package/package.json +47 -43
- package/src/css/styles.css +581 -581
- package/src/lexer.ts +419 -419
- package/src/pantsdown.ts +38 -38
- package/src/parser.ts +223 -239
- package/src/renderer.ts +243 -245
- package/src/rules/block.ts +99 -101
- package/src/rules/inline.ts +92 -92
- package/src/rules/utils.ts +14 -14
- package/src/tokenizer.ts +911 -919
- package/src/types.ts +244 -244
- package/src/utils.ts +274 -236
- package/tsconfig.json +2 -1
- package/.prettierignore +0 -1
- package/src/css/styles.css.d.ts +0 -4
package/src/rules/block.ts
CHANGED
|
@@ -1,141 +1,139 @@
|
|
|
1
1
|
import { edit } from "./utils.ts";
|
|
2
2
|
|
|
3
3
|
type BlockRuleNames =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
4
|
+
| "newline"
|
|
5
|
+
| "code"
|
|
6
|
+
| "fences"
|
|
7
|
+
| "hr"
|
|
8
|
+
| "heading"
|
|
9
|
+
| "blockquote"
|
|
10
|
+
| "list"
|
|
11
|
+
| "html"
|
|
12
|
+
| "def"
|
|
13
|
+
| "table"
|
|
14
|
+
| "lheading"
|
|
15
|
+
| "text"
|
|
16
|
+
| "bullet"
|
|
17
|
+
| "listItemStart"
|
|
18
|
+
| "footnote"
|
|
19
|
+
| "paragraph"
|
|
20
|
+
| "latexBlock";
|
|
21
21
|
|
|
22
22
|
export const label = /(?!\s*\])(?:\\.|[^\[\]\\])+/;
|
|
23
23
|
|
|
24
24
|
const tag =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
25
|
+
"address|article|aside|base|basefont|blockquote|body|caption" +
|
|
26
|
+
"|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption" +
|
|
27
|
+
"|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe" +
|
|
28
|
+
"|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option" +
|
|
29
|
+
"|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title" +
|
|
30
|
+
"|tr|track|ul";
|
|
31
31
|
|
|
32
32
|
const title = /(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/;
|
|
33
33
|
|
|
34
34
|
const block_def = edit(
|
|
35
|
-
|
|
35
|
+
/^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
|
|
36
36
|
)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
37
|
+
.replace("label", label)
|
|
38
|
+
.replace("title", title)
|
|
39
|
+
.getRegex();
|
|
40
40
|
|
|
41
41
|
const block_bullet = /(?:[*+-]|\d{1,9}[.)])/;
|
|
42
42
|
|
|
43
43
|
const block_listItemStart = edit(/^( *)(bull) */)
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
.replace("bull", block_bullet)
|
|
45
|
+
.getRegex();
|
|
46
46
|
|
|
47
47
|
const block_list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
.replace(/bull/g, block_bullet)
|
|
49
|
+
.replace("hr", "\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))")
|
|
50
|
+
.replace("def", "\\n+(?=" + block_def.source + ")")
|
|
51
|
+
.getRegex();
|
|
52
52
|
|
|
53
53
|
export const comment = /<!--(?:-?>|[\s\S]*?(?:-->|$))/;
|
|
54
54
|
|
|
55
55
|
const block_html = edit(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
56
|
+
"^ {0,3}(?:" + // optional indentation
|
|
57
|
+
"<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)" + // (1)
|
|
58
|
+
"|comment[^\\n]*(\\n+|$)" + // (2)
|
|
59
|
+
"|<\\?[\\s\\S]*?(?:\\?>\\n*|$)" + // (3)
|
|
60
|
+
"|<![A-Z][\\s\\S]*?(?:>\\n*|$)" + // (4)
|
|
61
|
+
"|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)" + // (5)
|
|
62
|
+
"|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n *)+\\n|$)" + // (6)
|
|
63
|
+
"|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)" + // (7) open tag
|
|
64
|
+
"|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n *)+\\n|$)" + // (7) closing tag
|
|
65
|
+
")",
|
|
66
|
+
"i",
|
|
67
67
|
)
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/,
|
|
73
|
-
)
|
|
74
|
-
.getRegex();
|
|
68
|
+
.replace("comment", comment)
|
|
69
|
+
.replace("tag", tag)
|
|
70
|
+
.replace("attribute", / +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/)
|
|
71
|
+
.getRegex();
|
|
75
72
|
|
|
76
73
|
// const block_lheading = edit(/^(?!bull )((?:.|\n(?!\s*?\n|bull ))+?)\n {0,3}(=+|-+) *(?:\n+|$)/)
|
|
77
74
|
const block_lheading = edit(
|
|
78
|
-
|
|
75
|
+
/^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
|
|
79
76
|
)
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
77
|
+
.replace(/bull/g, block_bullet) // lists can interrupt
|
|
78
|
+
.replace(/blockCode/g, / {4}/) // indented code blocks can interrupt
|
|
79
|
+
.replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
|
|
80
|
+
.replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
|
|
81
|
+
.replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
|
|
82
|
+
.replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
|
|
83
|
+
.getRegex();
|
|
87
84
|
|
|
88
85
|
const block_hr = /^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/;
|
|
89
86
|
|
|
90
87
|
const block_table = edit(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
88
|
+
"^ *([^\\n ].*)\\n" + // Header
|
|
89
|
+
" {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)" + // Align
|
|
90
|
+
"(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)", // Cells
|
|
94
91
|
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
92
|
+
.replace("hr", block_hr)
|
|
93
|
+
.replace("heading", " {0,3}#{1,6}(?:\\s|$)")
|
|
94
|
+
.replace("blockquote", " {0,3}>")
|
|
95
|
+
.replace("code", " {4}[^\\n]")
|
|
96
|
+
.replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n")
|
|
97
|
+
.replace("list", " {0,3}(?:[*+-]|1[.)]) ") // only lists starting from 1 can interrupt
|
|
98
|
+
.replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)")
|
|
99
|
+
.replace("tag", tag) // tables can be interrupted by type (6) html blocks
|
|
100
|
+
.getRegex();
|
|
104
101
|
|
|
105
102
|
const block_paragraph = edit(
|
|
106
|
-
|
|
103
|
+
/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
|
|
107
104
|
)
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
.replace("hr", block_hr)
|
|
106
|
+
.replace("heading", " {0,3}#{1,6}(?:\\s|$)")
|
|
107
|
+
.replace("|lheading", "") // setext headings don't interrupt commonmark paragraphs
|
|
108
|
+
.replace("table", block_table) // interrupt paragraphs with table
|
|
109
|
+
.replace("blockquote", " {0,3}>")
|
|
110
|
+
.replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n")
|
|
111
|
+
.replace("list", " {0,3}(?:[*+-]|1[.)]) ") // only lists starting from 1 can interrupt
|
|
112
|
+
.replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)")
|
|
113
|
+
.replace("tag", tag) // pars can be interrupted by type (6) html blocks
|
|
114
|
+
.getRegex();
|
|
118
115
|
|
|
119
116
|
const block_blockquote = edit(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/)
|
|
120
|
-
|
|
121
|
-
|
|
117
|
+
.replace("paragraph", block_paragraph)
|
|
118
|
+
.getRegex();
|
|
122
119
|
|
|
123
120
|
export const block: Record<BlockRuleNames, RegExp> = {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
121
|
+
newline: /^(?: *(?:\n|$))+/,
|
|
122
|
+
code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
|
|
123
|
+
fences:
|
|
124
|
+
/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
|
|
125
|
+
hr: block_hr,
|
|
126
|
+
heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
|
|
127
|
+
blockquote: block_blockquote,
|
|
128
|
+
list: block_list,
|
|
129
|
+
html: block_html,
|
|
130
|
+
bullet: block_bullet,
|
|
131
|
+
listItemStart: block_listItemStart,
|
|
132
|
+
def: block_def,
|
|
133
|
+
table: block_table,
|
|
134
|
+
lheading: block_lheading,
|
|
135
|
+
paragraph: block_paragraph,
|
|
136
|
+
footnote: /^\[\^([^\]\n]+)\]:(?:[ \t]+|[\n]*?|$)([^\n]*?(?:\n|$)(?:[\n]*?[ ]{4,}[^\n]*)*)/,
|
|
137
|
+
text: /^[^\n]+/,
|
|
138
|
+
latexBlock: /^(?:\$\$([^$]*(?:\$(?!\$)[^$]*)*)\$\$|\\\[([\s\S]*?)\\\])/,
|
|
141
139
|
};
|
package/src/rules/inline.ts
CHANGED
|
@@ -2,25 +2,25 @@ import { comment as blockComment, label as blockLabel } from "./block.ts";
|
|
|
2
2
|
import { edit } from "./utils.ts";
|
|
3
3
|
|
|
4
4
|
type InlineRuleNames =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
5
|
+
| "escape"
|
|
6
|
+
| "autolink"
|
|
7
|
+
| "tag"
|
|
8
|
+
| "link"
|
|
9
|
+
| "reflink"
|
|
10
|
+
| "nolink"
|
|
11
|
+
| "reflinkSearch"
|
|
12
|
+
| "code"
|
|
13
|
+
| "br"
|
|
14
|
+
| "del"
|
|
15
|
+
| "url"
|
|
16
|
+
| "text"
|
|
17
|
+
| "emStrong"
|
|
18
|
+
| "anyPunctuation"
|
|
19
|
+
| "punctuation"
|
|
20
|
+
| "blockSkip"
|
|
21
|
+
| "footnoteRef"
|
|
22
|
+
| "backpedal"
|
|
23
|
+
| "latexInline";
|
|
24
24
|
|
|
25
25
|
// list of unicode punctuation marks, plus any missing characters from CommonMark spec
|
|
26
26
|
const punctuation = "\\p{P}\\p{S}";
|
|
@@ -31,114 +31,114 @@ const comment = edit(blockComment).replace("(?:-->|$)", "-->").getRegex();
|
|
|
31
31
|
const attribute = /\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/;
|
|
32
32
|
const label = /(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/;
|
|
33
33
|
const email =
|
|
34
|
-
|
|
34
|
+
/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/;
|
|
35
35
|
const extended_email = /[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/;
|
|
36
36
|
|
|
37
37
|
const inline_punctuation = edit(/^((?![*_])[\spunctuation])/, "u")
|
|
38
|
-
|
|
39
|
-
|
|
38
|
+
.replace(/punctuation/g, punctuation)
|
|
39
|
+
.getRegex();
|
|
40
40
|
|
|
41
41
|
// sequences em should skip over [title](link), `code`, <html>
|
|
42
42
|
const inline_blockSkip = /\[[^[\]]*?\]\([^\(\)]*?\)|`[^`]*?`|<[^<>]*?>/g;
|
|
43
43
|
|
|
44
44
|
const inline_emStrong = {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
45
|
+
lDelim: edit(/^(?:\*+(?:((?!\*)[punct])|[^\s*]))|^_+(?:((?!_)[punct])|([^\s_]))/, "u")
|
|
46
|
+
.replace(/punct/g, punctuation)
|
|
47
|
+
.getRegex(),
|
|
48
|
+
// (1) and (2) can only be a Right Delimiter. (3) and (4) can only be Left. (5) and (6) can be either Left or Right.
|
|
49
|
+
// | Skip orphan inside strong | Consume to delim | (1) #*** | (2) a***#, a*** | (3) #***a, ***a | (4) ***# | (5) #***# | (6) a***a
|
|
50
|
+
rDelimAst: edit(
|
|
51
|
+
/^[^_*]*?__[^_*]*?\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\*)[punct](\*+)(?=[\s]|$)|[^punct\s](\*+)(?!\*)(?=[punct\s]|$)|(?!\*)[punct\s](\*+)(?=[^punct\s])|[\s](\*+)(?!\*)(?=[punct])|(?!\*)[punct](\*+)(?!\*)(?=[punct])|[^punct\s](\*+)(?=[^punct\s])/,
|
|
52
|
+
"gu",
|
|
53
|
+
)
|
|
54
|
+
.replace(/punct/g, punctuation)
|
|
55
|
+
.getRegex(),
|
|
56
|
+
rDelimUnd: edit(
|
|
57
|
+
// ^- Not allowed for _
|
|
58
|
+
/^[^_*]*?\*\*[^_*]*?_[^_*]*?(?=\*\*)|[^_]+(?=[^_])|(?!_)[punct](_+)(?=[\s]|$)|[^punct\s](_+)(?!_)(?=[punct\s]|$)|(?!_)[punct\s](_+)(?=[^punct\s])|[\s](_+)(?!_)(?=[punct])|(?!_)[punct](_+)(?!_)(?=[punct])/,
|
|
59
|
+
"gu",
|
|
60
|
+
)
|
|
61
|
+
.replace(/punct/g, punctuation)
|
|
62
|
+
.getRegex(),
|
|
63
63
|
};
|
|
64
64
|
|
|
65
65
|
const inline_anyPunctuation = edit(/\\[punct]/g, "gu")
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
.replace(/punct/g, punctuation)
|
|
67
|
+
.getRegex();
|
|
68
68
|
|
|
69
69
|
const inline_autolink = edit(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/)
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
70
|
+
.replace("scheme", scheme)
|
|
71
|
+
.replace("email", email)
|
|
72
|
+
.getRegex();
|
|
73
73
|
|
|
74
74
|
const inline_tag = edit(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
"^comment" +
|
|
76
|
+
"|^</[a-zA-Z][\\w:-]*\\s*>" + // self-closing tag
|
|
77
|
+
"|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>" + // open tag
|
|
78
|
+
"|^<\\?[\\s\\S]*?\\?>" + // processing instruction, e.g. <?php ?>
|
|
79
|
+
"|^<![a-zA-Z]+\\s[\\s\\S]*?>" + // declaration, e.g. <!DOCTYPE html>
|
|
80
|
+
"|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>", // CDATA section
|
|
81
81
|
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
.replace("comment", comment)
|
|
83
|
+
.replace("attribute", attribute)
|
|
84
|
+
.getRegex();
|
|
85
85
|
|
|
86
86
|
const inline_link = edit(/^!?\[(label)\]\(\s*(href)(?:\s+(title))?\s*\)/)
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
.replace("label", label)
|
|
88
|
+
.replace("href", href)
|
|
89
|
+
.replace("title", title)
|
|
90
|
+
.getRegex();
|
|
91
91
|
|
|
92
92
|
const inline_reflink = edit(/^!?\[(label)\]\[(ref)\]/)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
.replace("label", label)
|
|
94
|
+
.replace("ref", blockLabel)
|
|
95
|
+
.getRegex();
|
|
96
96
|
|
|
97
97
|
const inline_nolink = edit(/^!?\[(ref)\](?:\[\])?/)
|
|
98
|
-
|
|
99
|
-
|
|
98
|
+
.replace("ref", blockLabel)
|
|
99
|
+
.getRegex();
|
|
100
100
|
|
|
101
101
|
const inline_reflinkSearch = edit("reflink|nolink(?!\\()", "g")
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
.replace("reflink", inline_reflink)
|
|
103
|
+
.replace("nolink", inline_nolink)
|
|
104
|
+
.getRegex();
|
|
105
105
|
|
|
106
106
|
const inline_escape = edit(/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/)
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
.replace("])", "~|])")
|
|
108
|
+
.getRegex();
|
|
109
109
|
|
|
110
110
|
const inline_backpedal =
|
|
111
|
-
|
|
111
|
+
/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/;
|
|
112
112
|
|
|
113
113
|
const inline_del = /^(~~?)(?=[^\s~])([\s\S]*?[^\s~])\1(?=[^~]|$)/;
|
|
114
114
|
|
|
115
115
|
const inline_text =
|
|
116
|
-
|
|
116
|
+
/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_$]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/;
|
|
117
117
|
|
|
118
118
|
const inline_url = edit(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/, "i")
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
.replace("email", extended_email)
|
|
120
|
+
.getRegex();
|
|
121
121
|
|
|
122
122
|
export const inline: Omit<Record<InlineRuleNames, RegExp>, "emStrong"> & {
|
|
123
|
-
|
|
123
|
+
["emStrong"]: Record<keyof typeof inline_emStrong, RegExp>;
|
|
124
124
|
} = {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
125
|
+
escape: inline_escape,
|
|
126
|
+
autolink: inline_autolink,
|
|
127
|
+
url: inline_url,
|
|
128
|
+
tag: inline_tag,
|
|
129
|
+
link: inline_link,
|
|
130
|
+
reflink: inline_reflink,
|
|
131
|
+
nolink: inline_nolink,
|
|
132
|
+
reflinkSearch: inline_reflinkSearch,
|
|
133
|
+
anyPunctuation: inline_anyPunctuation,
|
|
134
|
+
emStrong: inline_emStrong,
|
|
135
|
+
code: /^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,
|
|
136
|
+
br: /^( {2,}|\\)\n(?!\s*$)/,
|
|
137
|
+
del: inline_del,
|
|
138
|
+
text: inline_text,
|
|
139
|
+
punctuation: inline_punctuation,
|
|
140
|
+
blockSkip: inline_blockSkip,
|
|
141
|
+
backpedal: inline_backpedal,
|
|
142
|
+
footnoteRef: /^\[\^([^\]\n]+)\]/,
|
|
143
|
+
latexInline: /^(?:\$(?!\$)([^\s$](?:[^$\n]*[^\s$])?)\$(?!\$)|\\\((.+?)\\\))/,
|
|
144
144
|
};
|
package/src/rules/utils.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
const caret = /(^|[^\[])\^/g;
|
|
2
2
|
|
|
3
3
|
export function edit(rule: RegExp | string, opt?: string) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
let source = typeof rule === "string" ? rule : rule.source;
|
|
5
|
+
opt = opt ?? "";
|
|
6
|
+
const obj = {
|
|
7
|
+
replace: (name: string | RegExp, val: string | RegExp) => {
|
|
8
|
+
let valSource = typeof val === "string" ? val : val.source;
|
|
9
|
+
valSource = valSource.replace(caret, "$1");
|
|
10
|
+
source = source.replace(name, valSource);
|
|
11
|
+
return obj;
|
|
12
|
+
},
|
|
13
|
+
getRegex: () => {
|
|
14
|
+
return new RegExp(source, opt);
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
return obj;
|
|
18
18
|
}
|