abstract out write-html function