borrow code from htmlview plugin