quantizor / markdown-to-jsx

🏭 The most lightweight, customizable React markdown component.
https://markdown-to-jsx.quantizor.dev/
MIT License
1.99k stars 172 forks source link

App crashes while streaming data & converting to markdown #602

Open ItzCrazyKns opened 2 weeks ago

ItzCrazyKns commented 2 weeks ago

When we stream data (in my case from a chatbot) to the frontend and then parse the markdown using markdown-to-jsx if the chatbot starts outputting a code block the app would crash (only for HTML). This happens as:

Since we stream the responses from chatbot the chatbot starts the code with opening the code block and then starts writing its HTML but since the code block isn't closed markdown-to-jsx detects it as plain HTML and renders it inside a <p> tag which causes DOM errors as the <html> tag cannot be a child of the <p> tag.

I believe markdown-to-jsx should detect the starting of the code block and till the code block is not closed by '```' it should just detect the chars after the starting as the code.

willtpwise commented 3 days ago

We're facing a similar issue where invalid markdown causes a CPU blowout. We essentially need a way to handle markdown which contains invalid html/markdown. Perhaps there's a way to strip this invalid markup or escape it?