function replaceTags(str: string) {
  return str.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

// The inverse: text stored escaped by replaceTags back to what was typed,
// for places that render it as text (textContent, input values) or need to
// match against it.
function unescapeTags(str: string) {
  return str.replace(/&lt;/g, "<").replace(/&gt;/g, ">").replace(/&amp;/g, "&");
}
