Named links in rich embed markdown

This commit is contained in:
Jeremy Zhang 2020-03-07 16:30:19 -08:00
parent 6578526ef6
commit 64cb595f0d

View File

@ -1494,7 +1494,7 @@
return message; return message;
} }
function parse_message_markdown(text) { function parse_message_markdown(text, embed=false) {
var geturl_regex = /(\(.*?)?\b((?:https?|ftp|file):\/\/[-a-z0-9+&@#\/%?=~_()|!:,.;]*[-a-z0-9+&@#\/%=~_()|])/ig; var geturl_regex = /(\(.*?)?\b((?:https?|ftp|file):\/\/[-a-z0-9+&@#\/%?=~_()|!:,.;]*[-a-z0-9+&@#\/%=~_()|])/ig;
var links = text.match(geturl_regex); // temporarily remove urls so markdown won't mark inside of the url var links = text.match(geturl_regex); // temporarily remove urls so markdown won't mark inside of the url
if (links) { if (links) {
@ -1514,6 +1514,9 @@
text = text.replace("$LINK"+i+"$", links[i]); text = text.replace("$LINK"+i+"$", links[i]);
} }
} }
if (embed) {
text = text.replace(/\[(.*?)\]\((.*?)\)/g, "<a href=\"$2\" target=\"_blank\">$1</a>");
}
return text; return text;
} }
@ -1621,7 +1624,7 @@
content = content.replaceAll("\\>", ">"); content = content.replaceAll("\\>", ">");
content = escapeHtml(content); content = escapeHtml(content);
content = parse_role_mention(content); content = parse_role_mention(content);
content = parse_message_markdown(content); content = parse_message_markdown(content, true);
content = parse_channels_in_message(content); content = parse_channels_in_message(content);
content = parse_emoji_in_message(content); content = parse_emoji_in_message(content);
content = content.replace(/&lt;https:\/\/(.*?)&gt;/g, "https://$1"); content = content.replace(/&lt;https:\/\/(.*?)&gt;/g, "https://$1");