Update text.dm

This commit is contained in:
silicons
2022-09-23 16:19:03 -07:00
committed by GitHub
parent c5a5c7e8f6
commit 899c924301
+30
View File
@@ -53,6 +53,36 @@
/proc/sanitize(t,list/repl_chars = null)
return html_encode(sanitize_simple(t,repl_chars))
//Used for preprocessing entered text
/proc/sanitize_rp(var/input, var/max_length = MAX_MESSAGE_LEN, var/encode = 1, var/trim = 1, var/extra = 1)
if(!input)
return
if(max_length)
input = copytext(input,1,max_length)
if(extra)
var/temp_input = replace_characters(input, list("\n"=" ","\t"=" "))//one character is replaced by two
if(length_char(input) < (length_char(temp_input) - 12)) //12 is the number of linebreaks allowed per message
input = replace_characters(temp_input,list(" "=" "))//replace again, this time the double spaces with single ones
if(encode)
// The below \ escapes have a space inserted to attempt to enable Travis auto-checking of span class usage. Please do not remove the space.
//In addition to processing html, html_encode removes byond formatting codes like "\ red", "\ i" and other.
//It is important to avoid double-encode text, it can "break" quotes and some other characters.
//Also, keep in mind that escaped characters don't work in the interface (window titles, lower left corner of the main window, etc.)
input = html_encode(input)
else
//If not need encode text, simply remove < and >
//note: we can also remove here byond formatting codes: 0xFF + next byte
input = replace_characters(input, list("<"=" ", ">"=" "))
if(trim)
//Maybe, we need trim text twice? Here and before copytext?
input = trim(input)
return input
//Runs sanitize and strip_html_simple
//I believe strip_html_simple() is required to run first to prevent '<' from displaying as '&lt;' after sanitize() calls byond's html_encode()
/proc/strip_html(t,limit=MAX_MESSAGE_LEN)