Re-factor message markup generation

Use a template to the extent that is possible (given the dynamic
functionality that must be attached)