package renderer

import "../parser"
import "core:strings"

escape_html :: proc(s: string, allocator := context.temp_allocator) -> string {
	escaped := parser.decode_escapes(s, allocator)

	b := strings.builder_make(allocator)
	for ch in escaped {
		switch ch {
		case '&':
			strings.write_string(&b, "&amp;")
		case '<':
			strings.write_string(&b, "&lt;")
		case '>':
			strings.write_string(&b, "&gt;")
		case '"':
			strings.write_string(&b, "&quot;")
		case:
			strings.write_rune(&b, ch)
		}
	}
	return strings.to_string(b)
}
