Split out tree code from aloha html transform

This allows other parts of the code to work with the tree, instead of
having to reparse the resulting html into a tree. It leaves this code
funcionally the same though.