Very slightly refactor generation of formatListText

This was previously done in its own block, presumably because the
`formatListText` and `curSection` variables are not used outside
of the block. However, a block does not introduce a new variable
scope in JavaScript, so it makes more sense to use a function.