Move the parsing logics into separate functions.
Shorten the serialization, per gsnedder's suggestion.
Refactor all the markdown stuff to be half-sane.