Cleaned up fixes for #183

My previous commit (d5a94c2) broke a few things badly. Unfortunately I failed
to run the complete test suite and didn't catch it. A bad regex was crashing
the test suite. Also cleaned up a few other odds and ends from previous work
on #183. Still loosing a few random empty lines in code blocks though.

I suspect this may also fix #188.