Python markdown refactor