Extract section formatting to a helper

This enables it to be tested and used separately.