Improved handling of bold and italic formatting

We now shrink sections of formatting so they don't contain any leading
or trailing whitespace, which complies better with markdown "spec",
looks neater, and displays better in Mou etc.