184
edits
(cycling) |
(are you happy now epyep?) |
||
Line 60: | Line 60: | ||
function parseFormatCodes (text) { | function parseFormatCodes (text) { | ||
let spans = 0; | |||
let res = ''; | |||
for (var i = 0; i < text.length; i++) { | for (var i = 0; i < text.length; i++) { | ||
if | if (text[i] == '\\') { | ||
else if (text[i] == '/') { | res += text[i+1]; | ||
i++; | |||
} else if (/&[0-9a-fl-o]/.test(text.substring(i,i+2))) { | |||
res += '<span class="format-' + text[i+1] + '">'; | |||
spans++; | |||
i++; | |||
} else if (text.substring(i,i+2) == '&r') { | |||
res += '</span>'.repeat(spans); | |||
spans = 0; | |||
i++; | |||
} else if (/&#[0-9A-Fa-f]{6}/.test(text.substring(i,i+8))) { | |||
res += '<span style="color: ' + text.substring(i+1,i+8) + '">'; | |||
spans++; | |||
i += 7; | |||
} else if (text[i] == '/') { | |||
res += '<br>'; | res += '<br>'; | ||
} else { | |||
res += text[i]; | |||
} | } | ||
} | } | ||
return res + '</span>'.repeat(spans); | return res + '</span>'.repeat(spans); | ||
} | } |