Fix and optimizations for markdown decoding