Refactor markdown parsing implementation