mirror of
https://github.com/TitanEmbeds/Titan.git
synced 2024-11-15 02:21:21 +01:00
Resolves #37, basic Discord markdown parsing
Adds support for bold, italics, underline, strikethrough, code, and blockcode (no Syntax highlighting yet)
This commit is contained in:
parent
b3d5a7e171
commit
8f56bea4cc
@ -169,6 +169,7 @@ body > div.navbar-fixed > nav > div {
|
||||
|
||||
#chatcontent > p {
|
||||
display: table;
|
||||
width: 90%;
|
||||
}
|
||||
|
||||
#chatcontent > p > span {
|
||||
@ -391,8 +392,7 @@ a {
|
||||
display: table-header-group;
|
||||
}
|
||||
.chatmessage {
|
||||
display: table-footer-group;
|
||||
display: inline-block;
|
||||
display: inline;
|
||||
color: rgb(195, 196, 197);
|
||||
}
|
||||
|
||||
@ -404,3 +404,18 @@ p.mentioned {
|
||||
p.mentioned span.chatmessage {
|
||||
color: #ff5252;
|
||||
}
|
||||
|
||||
.chatmessage code {
|
||||
background-color: gray;
|
||||
color: lightgray;
|
||||
border-radius: 5px;
|
||||
padding: 2px;
|
||||
}
|
||||
|
||||
.chatmessage code.blockcode {
|
||||
width: 100%;
|
||||
display: inline-block;
|
||||
white-space: pre-wrap;
|
||||
line-height: 15px;
|
||||
padding: 5px;
|
||||
}
|
@ -604,6 +604,16 @@
|
||||
return message;
|
||||
}
|
||||
|
||||
function parse_message_markdown(text) {
|
||||
text = text.replace(/\*\*(.*?)\*\*/g, "<b>$1</b>");
|
||||
text = text.replace(/\*(.*?)\*/g, "<i>$1</i>");
|
||||
text = text.replace(/__(.*?)__/g, "<u>$1</u>");
|
||||
text = text.replace(/~~(.*?)~~/g, "<del>$1</del>");
|
||||
text = text.replace(/\`\`\`([^]+)\`\`\`/g, "<code class=\"blockcode\">$1</code>");
|
||||
text = text.replace(/\`(.*?)\`/g, "<code>$1</code>");
|
||||
return text;
|
||||
}
|
||||
|
||||
function fill_discord_messages(messages, jumpscroll) {
|
||||
if (messages.length == 0) {
|
||||
return last_message_id;
|
||||
@ -619,11 +629,13 @@
|
||||
message = parse_message_attachments(message);
|
||||
message = parse_channels_in_message(message);
|
||||
message.content = escapeHtml(message.content);
|
||||
message.content = parse_message_markdown(message.content);
|
||||
message = parse_emoji_in_message(message);
|
||||
var rendered = Mustache.render(template, {"id": message.id, "full_timestamp": message.formatted_timestamp, "time": message.formatted_time, "username": message.author.username, "discriminator": message.author.discriminator, "content": nl2br(message.content)});
|
||||
$("#chatcontent").append(rendered);
|
||||
last = message.id;
|
||||
handle_last_message_mention();
|
||||
$("#chatcontent p:last-child").find(".blockcode").find("br").remove(); // Remove excessive breaks in codeblocks
|
||||
}
|
||||
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
|
||||
$('#chatcontent').linkify({
|
||||
|
Loading…
Reference in New Issue
Block a user