// tag = tag name // newTag = full new contents including outer tag // replaces only one occurrence static S hreplacetag(S html, S tag, S newTag) { L tok = htmlcoarsetok(html); L> tags = findContainerTag(tok, tag); if (empty(tags)) ret html; L theTag = first(tags); L actualTag = subList(theTag, 1, l(theTag)-1); ret join(replaceSubList(cloneList(tok), actualTag, litlist(newTag))); }