Skip to content

Commit

Permalink
parse: fix whitespace between link label and destination
Browse files Browse the repository at this point in the history
Closes GH-456.
Closes GH-458.

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
samouri committed Mar 27, 2020
1 parent b4c993e commit 4f2a1d4
Show file tree
Hide file tree
Showing 5 changed files with 276 additions and 38 deletions.
14 changes: 0 additions & 14 deletions packages/remark-parse/lib/tokenize/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,6 @@ function link(eat, value, silent) {
if (depth) {
depth--
} else {
// Allow white-space between content and url in GFM mode.
if (!pedantic) {
while (index < length) {
character = value.charAt(index + 1)

if (!whitespace(character)) {
break
}

subqueue += character
index++
}
}

if (value.charAt(index + 1) !== leftParenthesis) {
return
}
Expand Down
102 changes: 96 additions & 6 deletions test/fixtures/tree/link-spaces.commonmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "http://foxtrot.golf",
"type": "linkReference",
"identifier": "echo",
"label": "echo",
"referenceType": "shortcut",
"children": [
{
"type": "text",
Expand All @@ -165,6 +166,77 @@
"column": 1,
"offset": 41
},
"end": {
"line": 6,
"column": 7,
"offset": 47
},
"indent": []
}
},
{
"type": "text",
"value": "\t(",
"position": {
"start": {
"line": 6,
"column": 7,
"offset": 47
},
"end": {
"line": 6,
"column": 9,
"offset": 49
},
"indent": []
}
},
{
"type": "link",
"title": null,
"url": "http://foxtrot.golf",
"children": [
{
"type": "text",
"value": "http://foxtrot.golf",
"position": {
"start": {
"line": 6,
"column": 9,
"offset": 49
},
"end": {
"line": 6,
"column": 28,
"offset": 68
},
"indent": []
}
}
],
"position": {
"start": {
"line": 6,
"column": 9,
"offset": 49
},
"end": {
"line": 6,
"column": 28,
"offset": 68
},
"indent": []
}
},
{
"type": "text",
"value": ")",
"position": {
"start": {
"line": 6,
"column": 28,
"offset": 68
},
"end": {
"line": 6,
"column": 29,
Expand Down Expand Up @@ -192,16 +264,34 @@
"type": "paragraph",
"children": [
{
"type": "image",
"title": null,
"url": "india.com/juliett",
"type": "imageReference",
"identifier": "hotel",
"label": "hotel",
"referenceType": "shortcut",
"alt": "hotel",
"position": {
"start": {
"line": 8,
"column": 1,
"offset": 71
},
"end": {
"line": 8,
"column": 9,
"offset": 79
},
"indent": []
}
},
{
"type": "text",
"value": " (india.com/juliett)",
"position": {
"start": {
"line": 8,
"column": 9,
"offset": 79
},
"end": {
"line": 8,
"column": 31,
Expand Down
102 changes: 96 additions & 6 deletions test/fixtures/tree/link-spaces.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "http://foxtrot.golf",
"type": "linkReference",
"identifier": "echo",
"label": "echo",
"referenceType": "shortcut",
"children": [
{
"type": "text",
Expand All @@ -165,6 +166,77 @@
"column": 1,
"offset": 41
},
"end": {
"line": 6,
"column": 7,
"offset": 47
},
"indent": []
}
},
{
"type": "text",
"value": "\t(",
"position": {
"start": {
"line": 6,
"column": 7,
"offset": 47
},
"end": {
"line": 6,
"column": 9,
"offset": 49
},
"indent": []
}
},
{
"type": "link",
"title": null,
"url": "http://foxtrot.golf",
"children": [
{
"type": "text",
"value": "http://foxtrot.golf",
"position": {
"start": {
"line": 6,
"column": 9,
"offset": 49
},
"end": {
"line": 6,
"column": 28,
"offset": 68
},
"indent": []
}
}
],
"position": {
"start": {
"line": 6,
"column": 9,
"offset": 49
},
"end": {
"line": 6,
"column": 28,
"offset": 68
},
"indent": []
}
},
{
"type": "text",
"value": ")",
"position": {
"start": {
"line": 6,
"column": 28,
"offset": 68
},
"end": {
"line": 6,
"column": 29,
Expand Down Expand Up @@ -192,16 +264,34 @@
"type": "paragraph",
"children": [
{
"type": "image",
"title": null,
"url": "india.com/juliett",
"type": "imageReference",
"identifier": "hotel",
"label": "hotel",
"referenceType": "shortcut",
"alt": "hotel",
"position": {
"start": {
"line": 8,
"column": 1,
"offset": 71
},
"end": {
"line": 8,
"column": 9,
"offset": 79
},
"indent": []
}
},
{
"type": "text",
"value": " (india.com/juliett)",
"position": {
"start": {
"line": 8,
"column": 9,
"offset": 79
},
"end": {
"line": 8,
"column": 31,
Expand Down
48 changes: 42 additions & 6 deletions test/fixtures/tree/link-spaces.nogfm.commonmark.json
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@
"type": "paragraph",
"children": [
{
"type": "link",
"title": null,
"url": "http://foxtrot.golf",
"type": "linkReference",
"identifier": "echo",
"label": "echo",
"referenceType": "shortcut",
"children": [
{
"type": "text",
Expand All @@ -165,6 +166,23 @@
"column": 1,
"offset": 41
},
"end": {
"line": 6,
"column": 7,
"offset": 47
},
"indent": []
}
},
{
"type": "text",
"value": "\t(http://foxtrot.golf)",
"position": {
"start": {
"line": 6,
"column": 7,
"offset": 47
},
"end": {
"line": 6,
"column": 29,
Expand Down Expand Up @@ -192,16 +210,34 @@
"type": "paragraph",
"children": [
{
"type": "image",
"title": null,
"url": "india.com/juliett",
"type": "imageReference",
"identifier": "hotel",
"label": "hotel",
"referenceType": "shortcut",
"alt": "hotel",
"position": {
"start": {
"line": 8,
"column": 1,
"offset": 71
},
"end": {
"line": 8,
"column": 9,
"offset": 79
},
"indent": []
}
},
{
"type": "text",
"value": " (india.com/juliett)",
"position": {
"start": {
"line": 8,
"column": 9,
"offset": 79
},
"end": {
"line": 8,
"column": 31,
Expand Down
Loading

0 comments on commit 4f2a1d4

Please sign in to comment.