function urlify(text) { let textregex = /(([a-z]+:\/\/)(([a-z0-9\-]+\.)+([a-z]{2}|aero|arpa|app|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|local|internal|tk|ga|xxx|to))(:[0-9]{1,5})?(\/[a-z0-9_\-\.~]+)*(\/([a-z0-9_\-\.]*)(\?[a-z0-9+_\-\.%=&]*)?)?(#[a-zA-Z0-9!$&'()*+.=-_~:@/?]*)?)(\s+|$)/gi return text.replace(textregex,'$1 ') } function newlineify(text) { let textregex = /(\n)/gi return text.replace(textregex,'
') } function crossout(text) { let textregex = /~([^~]*)~/gi return text.replace(textregex,'$1') } function italicify(text) { let textregex = /\*([^\*]*)\*/gi return text.replace(textregex,'$1 ') } function boldify(text) { let textregex = /\*\*([^\*]*)\*\*/gi return text.replace(textregex,'$1 ') } function filterMentions(text) { let textregex = /(@[^\s]*)/gi //if you find an "@" select everything until you find a whitespace (and save as $1) return text.replace(textregex,`$1 `) } function filterReplies(text) { let textregex = /_@_([^\s]*)/gi return text.replace(textregex,`$1 `) } /** * filter out html, as well as render some markdown into html * @param {string} text text to filter/format * @return {string} html that represents the filtered text */ function filterPost(text) { text = htmlesc(text) text = newlineify(text) text = urlify(text) //text = filterReplies(text) text = filterMentions(text) text = crossout(text) text = boldify(text) text = italicify(text) return text } /** * filter out html, as well as render some markdown into html, but without mentions * @param {string} text text to filter/format * @return {string} html that represents the filtered text */ function filterReply(text) { text = htmlesc(text) text = newlineify(text) text = urlify(text) text = crossout(text) text = boldify(text) text = italicify(text) return text }