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

OK, fancified bug tracker links.. #733

Merged
merged 1 commit into from
Oct 1, 2015
Merged
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
23 changes: 23 additions & 0 deletions webcompat/static/js/lib/models/issue.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,29 @@ var defaultLinkOpenRender = md.renderer.rules.link_open || function(tokens, idx,

md.renderer.rules.link_open = function (tokens, idx, options, env, self) {
tokens[idx].attrPush(['rel', 'nofollow']);
// Transform link text for some well-known sites
if (tokens[idx].attrIndex('href')>-1) {
var link = tokens[idx].attrs[tokens[idx].attrIndex('href')][1];
var transformations = {
'https://bugzilla.mozilla.org/show_bug': 'Mozilla',
'https://bugs.webkit.org/show_bug': 'WebKit',
'https://code.google.com/p/chromium/issues/detail?': 'Chromium',
'https://github.com/': 'GitHub'
};
for (var bugtracker in transformations){
if (link.indexOf(bugtracker) > -1) {
var bugNumRx = /(\?id=|\/issues\/)(\d+)/, matches;
if (matches = link.match(bugNumRx)) {
for (var i = idx, theToken; theToken = tokens[i]; i++) { // find the token for link text
if (theToken.content === link) {
theToken.content = '#' + matches[2] + ' (' + transformations[bugtracker] + ')';
break;
}
}
}
}
}
}
// pass token to default renderer.
return defaultLinkOpenRender(tokens, idx, options, env, self);
};
Expand Down