guardRawText static method
text made safe to write inside a tag element (see RawTextNode).
Implementation
static String guardRawText(String text, {required String tag}) {
var safe = text.replaceAllMapped(
RegExp('</($tag)', caseSensitive: false),
(m) => '<\\/${m[1]}',
);
if (tag.toLowerCase() == 'script') {
safe = safe.replaceAll('<!--', '<\\!--');
}
return safe;
}