I do recall now I have used Tidy before. Can I just call it from a shell script? Is that the easiest way. It shouldn't be called that much as there are not that many editors in this application.
set cleanText [::xowiki::tidy clean $text]
-g [1] xowiki::tidy