Before:
After:
I also wanted to trim those ugly empty newlines, but unfortunately it seems there's no straightforward way to do this in C. There's g_strstrip(), which only removes whitespaces, but not newlines :/
g_strstrip()