Fixed the markdown parsing order bug

Reordered some of the logic so that it was more readable and then it
was obvious where the mixup was.