I think it would be better to separate the markup generation from the rest of the work here so that it is easier for someone to customize what gets created.