// tag = tag name // newTag = full new contents including outer tag // replaces only one occurrence // returns pair(new text, extracted tag) static Pair hextracttag(S html, S tag) { L tok = htmlcoarsetok(html); L> tags = findContainerTag(tok, tag); if (empty(tags)) ret pair(html, null); L theTag = first(tags); L actualTag = subList(theTag, 1, l(theTag)-1); S s = join(actualTag); ret pair(join(replaceSubList(cloneList(tok), actualTag, emptyList())), s); }