Doesn't using TrustedTypes basically do that? I'm not really web-y, someone please correct me if I'm off.
Yup, this is basically what TrustedTypes is for!