Refactor extractCatsTreeHtml.