Add a optional function which will be applied to each item in the hierarchy before they are converted to html