refactor markdown generation