// This function was copied from https://stackoverflow.com/a/4835406/5302652 function escapeHtml(text) { var map = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; return text.replace(/[&<>"']/g, function(m) { return map[m]; }); } // Get a list of links sent to the user var sent_chat_links = []; function open_link_id(id) { // Open the saved link open(sent_chat_links[id]); } function is_url(text) { return /^(ftp|http|https):\/\/[^ "]+$/.test(text); } function fixInt(num, size) { // Convert the number to a string num = num.toString() // Loop over the number until its big enough while(num.length < size) { // Add a zero to the start num = "0" + num; } // Return the number return num; } function text_to_html(text) { // Make the text XSS safe text = escapeHtml(text); // Split the text into an array text = text.split(" "); // Some varibles for remembering parts of the string var underline_check = false; var strikethrough_check = false; var italic_check = false; var bold_check = false; var code_check = false; var ignore_check = 0; var last_word = ""; // Create an out varible var out = ""; // Loop over the rows for(var r=0;r"+text[r]+""; } else { // Loop over the text for(var i=0;i 0) { // Remove 1 ignore_check -= 1; // Add the next character, ignoring the formatting out += text[r][i]; } else { // Is the text a backslash (ignore) if(text[r][i] == "\\" && !code_check) { // Set ignore check ignore_check = 1; } // Is the text a dash (underline) else if(text[r][i] == "-" && !code_check) { // Invert the varible underline_check = !underline_check; if(underline_check) { // Open the underline element out += ""; } else { // Close the underline element out += ""; } } // Is the text a star (bold) else if(text[r][i] == "*" && !code_check) { // Invert the varible bold_check = !bold_check; if(bold_check) { // Open the bold element out += ""; } else { // Close the bold element out += ""; } } // Is the text an underline (italic) else if(text[r][i] == "_" && !code_check) { // Invert the varible italic_check = !italic_check; if(italic_check) { // Open the bold element out += ""; } else { // Close the bold element out += ""; } } // Is the text a ~ (strikethrough) else if(text[r][i] == "~" && !code_check) { // Invert the varible strikethrough_check = !strikethrough_check; if(strikethrough_check) { // Open the strikethrough element out += ""; } else { // Close the strikethrough element out += ""; } } // Is this a newline else if(text[r][i] == "\n") { // Add a break out += "
"; } // Is this a code marker else if(text[r][i] == "`") { // Invert the varible code_check = !code_check; if(code_check) { // Open the code element out += ""; } else { // Close the code element out += ""; } } else { out += text[r][i]; } } } } // Add a space out += " "; } // Close some unclosed elements if(bold_check) out += ""; if(italic_check) out += ""; if(underline_check) out += ""; if(strikethrough_check) out += ""; if(code_check) out += ""; // Send out back return out; }