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

Autolinker: Fixed that all tokens were url-decoded #1723

Merged
merged 1 commit into from
Feb 11, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.