separate out message relate utils, create message component

This commit is contained in:
Ginger Wong
2020-08-13 01:49:10 -07:00
parent dad802f19a
commit 64e7809c26
3 changed files with 67 additions and 40 deletions

View File

@@ -5,3 +5,31 @@ export const KEY_CHAT_FIRST_MESSAGE_SENT = 'owncast_first_message_sent';
export const CHAT_INITIAL_PLACEHOLDER_TEXT = 'Type here to chat, no account necessary.';
export const CHAT_PLACEHOLDER_TEXT = 'Message';
export const CHAT_PLACEHOLDER_OFFLINE = 'Chat is offline.';
export function formatMessageText(message) {
showdown.setFlavor('github');
var markdownToHTML = new showdown.Converter({
emoji: true,
openLinksInNewWindow: true,
tables: false,
simplifiedAutoLink: false,
literalMidWordUnderscores: true,
strikethrough: true,
ghMentions: false,
}).makeHtml(this.body);
const linked = autoLink(markdownToHTML, {
embed: true,
removeHTTP: true,
linkAttr: {
target: '_blank'
}
});
const highlighted = highlightUsername(linked);
return addNewlines(highlighted);
}
function highlightUsername(message) {
const username = document.getElementById('self-message-author').value;
const pattern = new RegExp('@?' + username.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'gi');
return message.replace(pattern, '<span class="highlighted">$&</span>');
}