Skip to content

Commit 4f2a1d4

Browse files
authored
parse: fix whitespace between link label and destination
Closes GH-456. Closes GH-458. Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com> Reviewed-by: Titus Wormer <tituswormer@gmail.com>
1 parent b4c993e commit 4f2a1d4

5 files changed

Lines changed: 276 additions & 38 deletions

File tree

packages/remark-parse/lib/tokenize/link.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -106,20 +106,6 @@ function link(eat, value, silent) {
106106
if (depth) {
107107
depth--
108108
} else {
109-
// Allow white-space between content and url in GFM mode.
110-
if (!pedantic) {
111-
while (index < length) {
112-
character = value.charAt(index + 1)
113-
114-
if (!whitespace(character)) {
115-
break
116-
}
117-
118-
subqueue += character
119-
index++
120-
}
121-
}
122-
123109
if (value.charAt(index + 1) !== leftParenthesis) {
124110
return
125111
}

test/fixtures/tree/link-spaces.commonmark.json

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@
137137
"type": "paragraph",
138138
"children": [
139139
{
140-
"type": "link",
141-
"title": null,
142-
"url": "http://foxtrot.golf",
140+
"type": "linkReference",
141+
"identifier": "echo",
142+
"label": "echo",
143+
"referenceType": "shortcut",
143144
"children": [
144145
{
145146
"type": "text",
@@ -165,6 +166,77 @@
165166
"column": 1,
166167
"offset": 41
167168
},
169+
"end": {
170+
"line": 6,
171+
"column": 7,
172+
"offset": 47
173+
},
174+
"indent": []
175+
}
176+
},
177+
{
178+
"type": "text",
179+
"value": "\t(",
180+
"position": {
181+
"start": {
182+
"line": 6,
183+
"column": 7,
184+
"offset": 47
185+
},
186+
"end": {
187+
"line": 6,
188+
"column": 9,
189+
"offset": 49
190+
},
191+
"indent": []
192+
}
193+
},
194+
{
195+
"type": "link",
196+
"title": null,
197+
"url": "http://foxtrot.golf",
198+
"children": [
199+
{
200+
"type": "text",
201+
"value": "http://foxtrot.golf",
202+
"position": {
203+
"start": {
204+
"line": 6,
205+
"column": 9,
206+
"offset": 49
207+
},
208+
"end": {
209+
"line": 6,
210+
"column": 28,
211+
"offset": 68
212+
},
213+
"indent": []
214+
}
215+
}
216+
],
217+
"position": {
218+
"start": {
219+
"line": 6,
220+
"column": 9,
221+
"offset": 49
222+
},
223+
"end": {
224+
"line": 6,
225+
"column": 28,
226+
"offset": 68
227+
},
228+
"indent": []
229+
}
230+
},
231+
{
232+
"type": "text",
233+
"value": ")",
234+
"position": {
235+
"start": {
236+
"line": 6,
237+
"column": 28,
238+
"offset": 68
239+
},
168240
"end": {
169241
"line": 6,
170242
"column": 29,
@@ -192,16 +264,34 @@
192264
"type": "paragraph",
193265
"children": [
194266
{
195-
"type": "image",
196-
"title": null,
197-
"url": "india.com/juliett",
267+
"type": "imageReference",
268+
"identifier": "hotel",
269+
"label": "hotel",
270+
"referenceType": "shortcut",
198271
"alt": "hotel",
199272
"position": {
200273
"start": {
201274
"line": 8,
202275
"column": 1,
203276
"offset": 71
204277
},
278+
"end": {
279+
"line": 8,
280+
"column": 9,
281+
"offset": 79
282+
},
283+
"indent": []
284+
}
285+
},
286+
{
287+
"type": "text",
288+
"value": " (india.com/juliett)",
289+
"position": {
290+
"start": {
291+
"line": 8,
292+
"column": 9,
293+
"offset": 79
294+
},
205295
"end": {
206296
"line": 8,
207297
"column": 31,

test/fixtures/tree/link-spaces.json

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@
137137
"type": "paragraph",
138138
"children": [
139139
{
140-
"type": "link",
141-
"title": null,
142-
"url": "http://foxtrot.golf",
140+
"type": "linkReference",
141+
"identifier": "echo",
142+
"label": "echo",
143+
"referenceType": "shortcut",
143144
"children": [
144145
{
145146
"type": "text",
@@ -165,6 +166,77 @@
165166
"column": 1,
166167
"offset": 41
167168
},
169+
"end": {
170+
"line": 6,
171+
"column": 7,
172+
"offset": 47
173+
},
174+
"indent": []
175+
}
176+
},
177+
{
178+
"type": "text",
179+
"value": "\t(",
180+
"position": {
181+
"start": {
182+
"line": 6,
183+
"column": 7,
184+
"offset": 47
185+
},
186+
"end": {
187+
"line": 6,
188+
"column": 9,
189+
"offset": 49
190+
},
191+
"indent": []
192+
}
193+
},
194+
{
195+
"type": "link",
196+
"title": null,
197+
"url": "http://foxtrot.golf",
198+
"children": [
199+
{
200+
"type": "text",
201+
"value": "http://foxtrot.golf",
202+
"position": {
203+
"start": {
204+
"line": 6,
205+
"column": 9,
206+
"offset": 49
207+
},
208+
"end": {
209+
"line": 6,
210+
"column": 28,
211+
"offset": 68
212+
},
213+
"indent": []
214+
}
215+
}
216+
],
217+
"position": {
218+
"start": {
219+
"line": 6,
220+
"column": 9,
221+
"offset": 49
222+
},
223+
"end": {
224+
"line": 6,
225+
"column": 28,
226+
"offset": 68
227+
},
228+
"indent": []
229+
}
230+
},
231+
{
232+
"type": "text",
233+
"value": ")",
234+
"position": {
235+
"start": {
236+
"line": 6,
237+
"column": 28,
238+
"offset": 68
239+
},
168240
"end": {
169241
"line": 6,
170242
"column": 29,
@@ -192,16 +264,34 @@
192264
"type": "paragraph",
193265
"children": [
194266
{
195-
"type": "image",
196-
"title": null,
197-
"url": "india.com/juliett",
267+
"type": "imageReference",
268+
"identifier": "hotel",
269+
"label": "hotel",
270+
"referenceType": "shortcut",
198271
"alt": "hotel",
199272
"position": {
200273
"start": {
201274
"line": 8,
202275
"column": 1,
203276
"offset": 71
204277
},
278+
"end": {
279+
"line": 8,
280+
"column": 9,
281+
"offset": 79
282+
},
283+
"indent": []
284+
}
285+
},
286+
{
287+
"type": "text",
288+
"value": " (india.com/juliett)",
289+
"position": {
290+
"start": {
291+
"line": 8,
292+
"column": 9,
293+
"offset": 79
294+
},
205295
"end": {
206296
"line": 8,
207297
"column": 31,

test/fixtures/tree/link-spaces.nogfm.commonmark.json

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@
137137
"type": "paragraph",
138138
"children": [
139139
{
140-
"type": "link",
141-
"title": null,
142-
"url": "http://foxtrot.golf",
140+
"type": "linkReference",
141+
"identifier": "echo",
142+
"label": "echo",
143+
"referenceType": "shortcut",
143144
"children": [
144145
{
145146
"type": "text",
@@ -165,6 +166,23 @@
165166
"column": 1,
166167
"offset": 41
167168
},
169+
"end": {
170+
"line": 6,
171+
"column": 7,
172+
"offset": 47
173+
},
174+
"indent": []
175+
}
176+
},
177+
{
178+
"type": "text",
179+
"value": "\t(http://foxtrot.golf)",
180+
"position": {
181+
"start": {
182+
"line": 6,
183+
"column": 7,
184+
"offset": 47
185+
},
168186
"end": {
169187
"line": 6,
170188
"column": 29,
@@ -192,16 +210,34 @@
192210
"type": "paragraph",
193211
"children": [
194212
{
195-
"type": "image",
196-
"title": null,
197-
"url": "india.com/juliett",
213+
"type": "imageReference",
214+
"identifier": "hotel",
215+
"label": "hotel",
216+
"referenceType": "shortcut",
198217
"alt": "hotel",
199218
"position": {
200219
"start": {
201220
"line": 8,
202221
"column": 1,
203222
"offset": 71
204223
},
224+
"end": {
225+
"line": 8,
226+
"column": 9,
227+
"offset": 79
228+
},
229+
"indent": []
230+
}
231+
},
232+
{
233+
"type": "text",
234+
"value": " (india.com/juliett)",
235+
"position": {
236+
"start": {
237+
"line": 8,
238+
"column": 9,
239+
"offset": 79
240+
},
205241
"end": {
206242
"line": 8,
207243
"column": 31,

0 commit comments

Comments
 (0)