Skip to content

Commit

Permalink
Fix Autolinker url-decoding all tokens (#1723)
Browse files Browse the repository at this point in the history
This PR fixes #1721.

The problem was that the url-decoding introduced in #1173 was applied to all tokens.
  • Loading branch information
RunDevelopment authored and mAAdhaTTah committed Feb 11, 2019
1 parent 00f4f04 commit 8cf20d4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
20 changes: 10 additions & 10 deletions plugins/autolinker/prism-autolinker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (
var url = /\b([a-z]{3,7}:\/\/|tel:)[\w\-+%~/.:=&]+(?:\?[\w\-+%~/.:#=?&!$'()*,;]*)?(?:#[\w\-+%~/.:#=?&!$'()*,;]*)?/,
email = /\b\S+@[\w.]+[a-z]{2}/,
linkMd = /\[([^\]]+)]\(([^)]+)\)/,

// Tokens that may contain URLs and emails
candidates = ['comment', 'url', 'attr-value', 'string'];

Expand Down Expand Up @@ -55,27 +55,27 @@ Prism.hooks.add('before-highlight', function(env) {
Prism.hooks.add('wrap', function(env) {
if (/-link$/.test(env.type)) {
env.tag = 'a';

var href = env.content;

if (env.type == 'email-link' && href.indexOf('mailto:') != 0) {
href = 'mailto:' + href;
}
else if (env.type == 'md-link') {
// Markdown
var match = env.content.match(linkMd);

href = match[2];
env.content = match[1];
}

env.attributes.href = href;
}

// Silently catch any error thrown by decodeURIComponent (#1186)
try {
env.content = decodeURIComponent(env.content);
} catch(e) {}
// Silently catch any error thrown by decodeURIComponent (#1186)
try {
env.content = decodeURIComponent(env.content);
} catch(e) {}
}
});

})();
2 changes: 1 addition & 1 deletion plugins/autolinker/prism-autolinker.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cf20d4

Please sign in to comment.