2
2
* @typedef {import('./types.js').Unsafe } Unsafe
3
3
*/
4
4
5
+ /**
6
+ * List of constructs that occur in phrasing (paragraphs, headings), but cannot
7
+ * contain things like attention (emphasis, strong), images, or links.
8
+ * So they sort of cancel each other out.
9
+ * Note: could use a better name.
10
+ */
11
+ const fullPhrasingSpans = [
12
+ 'autolink' ,
13
+ 'destinationLiteral' ,
14
+ 'destinationRaw' ,
15
+ 'reference' ,
16
+ 'titleQuote' ,
17
+ 'titleApostrophe'
18
+ ]
19
+
5
20
/** @type {Array.<Unsafe> } */
6
21
export const unsafe = [
7
22
{ character : '\t' , after : '[\\r\\n]' , inConstruct : 'phrasing' } ,
@@ -40,7 +55,12 @@ export const unsafe = [
40
55
} ,
41
56
// An exclamation mark can start an image, if it is followed by a link or
42
57
// a link reference.
43
- { character : '!' , after : '\\[' , inConstruct : 'phrasing' } ,
58
+ {
59
+ character : '!' ,
60
+ after : '\\[' ,
61
+ inConstruct : 'phrasing' ,
62
+ notInConstruct : fullPhrasingSpans
63
+ } ,
44
64
// A quote can break out of a title.
45
65
{ character : '"' , inConstruct : 'titleQuote' } ,
46
66
// A number sign could start an ATX heading if it starts a line.
@@ -53,14 +73,20 @@ export const unsafe = [
53
73
{ character : "'" , inConstruct : 'titleApostrophe' } ,
54
74
// A left paren could break out of a destination raw.
55
75
{ character : '(' , inConstruct : 'destinationRaw' } ,
56
- { before : '\\]' , character : '(' , inConstruct : 'phrasing' } ,
76
+ // A left paren followed by `]` could make something into a link or image.
77
+ {
78
+ before : '\\]' ,
79
+ character : '(' ,
80
+ inConstruct : 'phrasing' ,
81
+ notInConstruct : fullPhrasingSpans
82
+ } ,
57
83
// A right paren could start a list item or break out of a destination
58
84
// raw.
59
85
{ atBreak : true , before : '\\d+' , character : ')' } ,
60
86
{ character : ')' , inConstruct : 'destinationRaw' } ,
61
87
// An asterisk can start thematic breaks, list items, emphasis, strong.
62
88
{ atBreak : true , character : '*' } ,
63
- { character : '*' , inConstruct : 'phrasing' } ,
89
+ { character : '*' , inConstruct : 'phrasing' , notInConstruct : fullPhrasingSpans } ,
64
90
// A plus sign could start a list item.
65
91
{ atBreak : true , character : '+' } ,
66
92
// A dash can start thematic breaks, list items, and setext heading
@@ -75,7 +101,12 @@ export const unsafe = [
75
101
// An autolink also starts with a letter.
76
102
// Finally, it could break out of a destination literal.
77
103
{ atBreak : true , character : '<' , after : '[!/?A-Za-z]' } ,
78
- { character : '<' , after : '[!/?A-Za-z]' , inConstruct : 'phrasing' } ,
104
+ {
105
+ character : '<' ,
106
+ after : '[!/?A-Za-z]' ,
107
+ inConstruct : 'phrasing' ,
108
+ notInConstruct : fullPhrasingSpans
109
+ } ,
79
110
{ character : '<' , inConstruct : 'destinationLiteral' } ,
80
111
// An equals to can start setext heading underlines.
81
112
{ atBreak : true , character : '=' } ,
@@ -86,7 +117,8 @@ export const unsafe = [
86
117
// Question mark and at sign are not used in markdown for constructs.
87
118
// A left bracket can start definitions, references, labels,
88
119
{ atBreak : true , character : '[' } ,
89
- { character : '[' , inConstruct : [ 'phrasing' , 'label' , 'reference' ] } ,
120
+ { character : '[' , inConstruct : 'phrasing' , notInConstruct : fullPhrasingSpans } ,
121
+ { character : '[' , inConstruct : [ 'label' , 'reference' ] } ,
90
122
// A backslash can start an escape (when followed by punctuation) or a
91
123
// hard break (when followed by an eol).
92
124
// Note: typical escapes are handled in `safe`!
@@ -96,18 +128,15 @@ export const unsafe = [
96
128
// Caret is not used in markdown for constructs.
97
129
// An underscore can start emphasis, strong, or a thematic break.
98
130
{ atBreak : true , character : '_' } ,
99
- { character : '_' , inConstruct : 'phrasing' } ,
131
+ { character : '_' , inConstruct : 'phrasing' , notInConstruct : fullPhrasingSpans } ,
100
132
// A grave accent can start code (fenced or text), or it can break out of
101
133
// a grave accent code fence.
102
134
{ atBreak : true , character : '`' } ,
103
135
{
104
136
character : '`' ,
105
- inConstruct : [
106
- 'codeFencedLangGraveAccent' ,
107
- 'codeFencedMetaGraveAccent' ,
108
- 'phrasing'
109
- ]
137
+ inConstruct : [ 'codeFencedLangGraveAccent' , 'codeFencedMetaGraveAccent' ]
110
138
} ,
139
+ { character : '`' , inConstruct : 'phrasing' , notInConstruct : fullPhrasingSpans } ,
111
140
// Left brace, vertical bar, right brace are not used in markdown for
112
141
// constructs.
113
142
// A tilde can start code (fenced).
0 commit comments