Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix escape characters in links #2628

Merged
merged 3 commits into from Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/Tokenizer.js
Expand Up @@ -103,7 +103,7 @@ export class Tokenizer {
return {
type: 'code',
raw,
lang: cap[2] ? cap[2].trim() : cap[2],
lang: cap[2] ? cap[2].trim().replace(this.rules.inline._escapes, '$1') : cap[2],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would #2627 be better achieved using something like this approach, a' la DRY? #2627 works, but that regex is becoming more and more unwieldy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No because that has to do with finding the correct tokens. This only works for removing escapes after the token is already found.

text
};
}
Expand Down Expand Up @@ -371,8 +371,8 @@ export class Tokenizer {
type: 'def',
tag,
raw: cap[0],
href: cap[2],
title: cap[3]
href: cap[2] ? cap[2].replace(this.rules.inline._escapes, '$1') : cap[2],
title: cap[3] ? cap[3].replace(this.rules.inline._escapes, '$1') : cap[3]
};
}
}
Expand Down
9 changes: 3 additions & 6 deletions test/specs/commonmark/commonmark.0.30.json
Expand Up @@ -181,17 +181,15 @@
"example": 23,
"start_line": 605,
"end_line": 611,
"section": "Backslash escapes",
"shouldFail": true
"section": "Backslash escapes"
},
{
"markdown": "``` foo\\+bar\nfoo\n```\n",
"html": "<pre><code class=\"language-foo+bar\">foo\n</code></pre>\n",
"example": 24,
"start_line": 614,
"end_line": 621,
"section": "Backslash escapes",
"shouldFail": true
"section": "Backslash escapes"
},
{
"markdown": "&nbsp; &amp; &copy; &AElig; &Dcaron;\n&frac34; &HilbertSpace; &DifferentialD;\n&ClockwiseContourIntegral; &ngE;\n",
Expand Down Expand Up @@ -1624,8 +1622,7 @@
"example": 202,
"start_line": 3307,
"end_line": 3313,
"section": "Link reference definitions",
"shouldFail": true
"section": "Link reference definitions"
},
{
"markdown": "[foo]\n\n[foo]: url\n",
Expand Down
9 changes: 3 additions & 6 deletions test/specs/gfm/commonmark.0.30.json
Expand Up @@ -181,17 +181,15 @@
"example": 23,
"start_line": 605,
"end_line": 611,
"section": "Backslash escapes",
"shouldFail": true
"section": "Backslash escapes"
},
{
"markdown": "``` foo\\+bar\nfoo\n```\n",
"html": "<pre><code class=\"language-foo+bar\">foo\n</code></pre>\n",
"example": 24,
"start_line": 614,
"end_line": 621,
"section": "Backslash escapes",
"shouldFail": true
"section": "Backslash escapes"
},
{
"markdown": "&nbsp; &amp; &copy; &AElig; &Dcaron;\n&frac34; &HilbertSpace; &DifferentialD;\n&ClockwiseContourIntegral; &ngE;\n",
Expand Down Expand Up @@ -1624,8 +1622,7 @@
"example": 202,
"start_line": 3307,
"end_line": 3313,
"section": "Link reference definitions",
"shouldFail": true
"section": "Link reference definitions"
},
{
"markdown": "[foo]\n\n[foo]: url\n",
Expand Down