Linkify subreddit in community description

(closes #4997)
This commit is contained in:
Bryan Housel
2018-04-18 17:10:54 -04:00
parent 0d6bb565e2
commit a86167f0d1
+11 -3
View File
@@ -213,10 +213,17 @@ export function uiSuccess(context) {
.attr('href', d.url)
.text(t('community.' + d.id + '.name'));
var descriptionHTML = t('community.' + d.id + '.description', replacements);
if (d.type === 'reddit') { // linkify subreddits #4997
descriptionHTML = descriptionHTML
.replace(/(\/r\/\w*\/*)/i, function(match) { return linkify(d.url, match); });
}
selection
.append('div')
.attr('class', 'community-description')
.html(t('community.' + d.id + '.description', replacements));
.html(descriptionHTML);
if (d.extendedDescription || (d.languageCodes && d.languageCodes.length)) {
selection
@@ -345,8 +352,9 @@ export function uiSuccess(context) {
}
function linkify(url) {
return '<a target="_blank" href="' + url + '">' + url + '</a>';
function linkify(url, text) {
text = text || url;
return '<a target="_blank" href="' + url + '">' + text + '</a>';
}
}