diff --git a/webapp/titanembeds/static/js/embed.js b/webapp/titanembeds/static/js/embed.js index 25aa422..03d2aad 100644 --- a/webapp/titanembeds/static/js/embed.js +++ b/webapp/titanembeds/static/js/embed.js @@ -1343,6 +1343,12 @@ message.content = message.content.replace(new RegExp("<@!" + mention.id + ">", 'g'), rendered); } + message.content = parse_role_mention(message.content); + + return message; + } + + function parse_role_mention(content) { var template = $("#mustache_rolemention").html(); Mustache.parse(template); for (var i = 0; i < guild_roles_list.length; i++) { @@ -1352,9 +1358,9 @@ roleobj.color = "#" + role.color.toString(16); } var rendered = Mustache.render(template, roleobj).trim(); - message.content = message.content.replace("<@&" + role.id + ">", rendered); + content = content.replace("<@&" + role.id + ">", rendered); } - return message; + return content; } function getPosition(string, subString, index) { @@ -1450,7 +1456,7 @@ for (var i = 0; i < channelids.length; i++) { var pattern = "<#" + channelids[i] + ">"; var elem = "#" + guild_channels[channelids[i]].channel.name + ""; - message.content = message.content.replace(new RegExp(pattern, "g"), elem); + message = message.replace(new RegExp(pattern, "g"), elem); } return message; } @@ -1467,13 +1473,13 @@ emoji_format = "<:" + emoji.name + ":" + emoji.id + ">"; } var rendered = Mustache.render(template, {"id": emoji.id, "name": emoji.name, "animated": emoji.animated}).trim(); - message.content = message.content.replaceAll(emoji_format, rendered); + message = message.replaceAll(emoji_format, rendered); } var rendered = Mustache.render(template, {"id": "$2", "name": "$1"}).trim(); - message.content = message.content.replace(/<:(.*?):(.*?)>/g, rendered); + message = message.replace(/<:(.*?):(.*?)>/g, rendered); rendered = Mustache.render(template, {"id": "$2", "name": "$1", "animated": true}).trim(); - message.content = message.content.replace(/<a:(.*?):(.*?)>/g, rendered); - message.content = twemoji.parse(message.content, { + message = message.replace(/<a:(.*?):(.*?)>/g, rendered); + message = twemoji.parse(message, { className: "message_emoji", callback: function(icon, options, variant) { // exclude special characters switch (icon) { @@ -1592,11 +1598,40 @@ if (disembed.color) { disembed.hexColor = "#" + disembed.color.toString(16); } + if (disembed.title) { + disembed.title = render_embed_text_formatting(disembed.title); + } + if (disembed.description) { + disembed.description = render_embed_text_formatting(disembed.description); + } + if (disembed.fields) { + for (var i = 0; i < disembed.fields.length; i++) { + disembed.fields[i].name = render_embed_text_formatting(disembed.fields[i].name); + disembed.fields[i].value = render_embed_text_formatting(disembed.fields[i].value); + } + } var template = $('#mustache_richembed').html(); Mustache.parse(template); var rendered = Mustache.render(template, disembed); return rendered; } + + function render_embed_text_formatting(content) { + content = content.replaceAll("\\<", "<"); + content = content.replaceAll("\\>", ">"); + content = escapeHtml(content); + content = parse_role_mention(content); + content = parse_message_markdown(content); + content = parse_channels_in_message(content); + content = parse_emoji_in_message(content); + content = content.replace(/<https:\/\/(.*?)>/g, "https://$1"); + content = content.replace(/<http:\/\/(.*?)>/g, "http://$1"); + var el = $("
").html(content); + el.linkify({ + target: "_blank" + }); + return el.html(); + } function parse_message_reactions(reactions) { var reacts = [] @@ -1700,8 +1735,8 @@ message = replace_message_mentions(message); message = parse_message_attachments(message); message.content = parse_message_markdown(message.content); - message = parse_channels_in_message(message); - message = parse_emoji_in_message(message); + message.content = parse_channels_in_message(message.content); + message.content = parse_emoji_in_message(message.content); message.content = message.content.replace(/<https:\/\/(.*?)>/g, "https://$1"); message.content = message.content.replace(/<http:\/\/(.*?)>/g, "http://$1"); if (message.type == 7) { diff --git a/webapp/titanembeds/templates/embed.html.j2 b/webapp/titanembeds/templates/embed.html.j2 index 2256b19..a408669 100644 --- a/webapp/titanembeds/templates/embed.html.j2 +++ b/webapp/titanembeds/templates/embed.html.j2 @@ -530,12 +530,12 @@ {{title}} + " target="_blank">{{{title}}} {{/title}} {{^isVideo}} {{#description}} -