Refactored format.py unit tests.

Also refactored/decomposed various functions in format.py to be easier to test. The unit tests shouldn't be such a pain to maintain now. Also consolidated all HTML/javascript text in format.py at the bottom of the file, as it used to be interspersed throughout the functions and made things hard to find.

This fixes #97.