Skip to content

Commit 091ef9c

Browse files
Autolink usernames via the @username syntax.
1 parent feb60ab commit 091ef9c

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libs/markdown.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ renderer.heading = function (aText, aLevel) {
9494
return html;
9595
};
9696

97+
// Autolink @username syntax
98+
renderer.text = function (aText) {
99+
return aText.replace(/@([^\s\\\/:*?\'\"<>|#;@=&]+)/gm, function ($0, $1) {
100+
return '<a href="/users/' + $1 + '">' + $0 + '</a>';
101+
});
102+
};
103+
104+
renderer.link = function (aHref, aTitle, aText) {
105+
// Prevent double linking @username
106+
var autoLinkMatch = />(@[^<]+)<\/a>/mi.exec(aText);
107+
if (autoLinkMatch) {
108+
aText = autoLinkMatch[1];
109+
}
110+
111+
return marked.Renderer.prototype.link.call(renderer, aHref, aTitle, aText);
112+
};
113+
97114
// Set the options to use for rendering markdown
98115
// Keep in sync with ./views/includes/scripts/markdownEditor.html
99116
marked.setOptions({

0 commit comments

Comments
 (0)