generalize to allow insertion of arbitrary HTML in rewriteHTML()

Also, add some better docs.