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.
@@ -1,141 +1,139 @@
1
1
  import { edit } from "./utils.ts";
2
2
 
3
3
  type BlockRuleNames =
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";
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
- "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";
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
- /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
35
+ /^ {0,3}\[(label)\]: *(?:\n *)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n *)?| *\n *)(title))? *(?:\n+|$)/,
36
36
  )
37
- .replace("label", label)
38
- .replace("title", title)
39
- .getRegex();
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
- .replace("bull", block_bullet)
45
- .getRegex();
44
+ .replace("bull", block_bullet)
45
+ .getRegex();
46
46
 
47
47
  const block_list = edit(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/)
48
- .replace(/bull/g, block_bullet)
49
- .replace("hr", "\\n+(?=\\1?(?:(?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$))")
50
- .replace("def", "\\n+(?=" + block_def.source + ")")
51
- .getRegex();
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
- "^ {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",
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
- .replace("comment", comment)
69
- .replace("tag", tag)
70
- .replace(
71
- "attribute",
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
- /^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
75
+ /^(?!bull |blockCode|fences|blockquote|heading|html)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,
79
76
  )
80
- .replace(/bull/g, block_bullet) // lists can interrupt
81
- .replace(/blockCode/g, / {4}/) // indented code blocks can interrupt
82
- .replace(/fences/g, / {0,3}(?:`{3,}|~{3,})/) // fenced code blocks can interrupt
83
- .replace(/blockquote/g, / {0,3}>/) // blockquote can interrupt
84
- .replace(/heading/g, / {0,3}#{1,6}/) // ATX heading can interrupt
85
- .replace(/html/g, / {0,3}<[^\n>]+>\n/) // block html can interrupt
86
- .getRegex();
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
- "^ *([^\\n ].*)\\n" + // Header
92
- " {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)" + // Align
93
- "(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)", // Cells
88
+ "^ *([^\\n ].*)\\n" + // Header
89
+ " {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)" + // Align
90
+ "(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)", // Cells
94
91
  )
95
- .replace("hr", block_hr)
96
- .replace("heading", " {0,3}#{1,6}(?:\\s|$)")
97
- .replace("blockquote", " {0,3}>")
98
- .replace("code", " {4}[^\\n]")
99
- .replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n")
100
- .replace("list", " {0,3}(?:[*+-]|1[.)]) ") // only lists starting from 1 can interrupt
101
- .replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)")
102
- .replace("tag", tag) // tables can be interrupted by type (6) html blocks
103
- .getRegex();
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
- /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
103
+ /^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,
107
104
  )
108
- .replace("hr", block_hr)
109
- .replace("heading", " {0,3}#{1,6}(?:\\s|$)")
110
- .replace("|lheading", "") // setext headings don't interrupt commonmark paragraphs
111
- .replace("table", block_table) // interrupt paragraphs with table
112
- .replace("blockquote", " {0,3}>")
113
- .replace("fences", " {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n")
114
- .replace("list", " {0,3}(?:[*+-]|1[.)]) ") // only lists starting from 1 can interrupt
115
- .replace("html", "</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)")
116
- .replace("tag", tag) // pars can be interrupted by type (6) html blocks
117
- .getRegex();
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
- .replace("paragraph", block_paragraph)
121
- .getRegex();
117
+ .replace("paragraph", block_paragraph)
118
+ .getRegex();
122
119
 
123
120
  export const block: Record<BlockRuleNames, RegExp> = {
124
- newline: /^(?: *(?:\n|$))+/,
125
- code: /^( {4}[^\n]+(?:\n(?: *(?:\n|$))*)?)+/,
126
- fences: /^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,
127
- hr: block_hr,
128
- heading: /^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,
129
- blockquote: block_blockquote,
130
- list: block_list,
131
- html: block_html,
132
- bullet: block_bullet,
133
- listItemStart: block_listItemStart,
134
- def: block_def,
135
- table: block_table,
136
- lheading: block_lheading,
137
- paragraph: block_paragraph,
138
- footnote: /^\[\^([^\]\n]+)\]:(?:[ \t]+|[\n]*?|$)([^\n]*?(?:\n|$)(?:[\n]*?[ ]{4,}[^\n]*)*)/,
139
- text: /^[^\n]+/,
140
- latexBlock: /^(?:\$\$([^$]*(?:\$(?!\$)[^$]*)*)\$\$|\\\[([\s\S]*?)\\\])/,
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
  };
@@ -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
- | "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";
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
- /[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])?)+(?![-_])/;
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
- .replace(/punctuation/g, punctuation)
39
- .getRegex();
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
- 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(),
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
- .replace(/punct/g, punctuation)
67
- .getRegex();
66
+ .replace(/punct/g, punctuation)
67
+ .getRegex();
68
68
 
69
69
  const inline_autolink = edit(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/)
70
- .replace("scheme", scheme)
71
- .replace("email", email)
72
- .getRegex();
70
+ .replace("scheme", scheme)
71
+ .replace("email", email)
72
+ .getRegex();
73
73
 
74
74
  const inline_tag = edit(
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
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
- .replace("comment", comment)
83
- .replace("attribute", attribute)
84
- .getRegex();
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
- .replace("label", label)
88
- .replace("href", href)
89
- .replace("title", title)
90
- .getRegex();
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
- .replace("label", label)
94
- .replace("ref", blockLabel)
95
- .getRegex();
93
+ .replace("label", label)
94
+ .replace("ref", blockLabel)
95
+ .getRegex();
96
96
 
97
97
  const inline_nolink = edit(/^!?\[(ref)\](?:\[\])?/)
98
- .replace("ref", blockLabel)
99
- .getRegex();
98
+ .replace("ref", blockLabel)
99
+ .getRegex();
100
100
 
101
101
  const inline_reflinkSearch = edit("reflink|nolink(?!\\()", "g")
102
- .replace("reflink", inline_reflink)
103
- .replace("nolink", inline_nolink)
104
- .getRegex();
102
+ .replace("reflink", inline_reflink)
103
+ .replace("nolink", inline_nolink)
104
+ .getRegex();
105
105
 
106
106
  const inline_escape = edit(/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/)
107
- .replace("])", "~|])")
108
- .getRegex();
107
+ .replace("])", "~|])")
108
+ .getRegex();
109
109
 
110
110
  const inline_backpedal =
111
- /(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/;
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
- /^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_$]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/;
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
- .replace("email", extended_email)
120
- .getRegex();
119
+ .replace("email", extended_email)
120
+ .getRegex();
121
121
 
122
122
  export const inline: Omit<Record<InlineRuleNames, RegExp>, "emStrong"> & {
123
- ["emStrong"]: Record<keyof typeof inline_emStrong, RegExp>;
123
+ ["emStrong"]: Record<keyof typeof inline_emStrong, RegExp>;
124
124
  } = {
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$])?)\$(?!\$)|\\\((.+?)\\\))/,
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
  };
@@ -1,18 +1,18 @@
1
1
  const caret = /(^|[^\[])\^/g;
2
2
 
3
3
  export function edit(rule: RegExp | string, opt?: string) {
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;
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
  }