markdown-to-jsx
markdown-to-jsx copied to clipboard
Slow Regex HTML_BLOCK_ELEMENT_R because of issue with self closing tags
We found out, the following regex is very slow and takes up to 50ms with a single self closing tag on the page.
const HTML_BLOCK_ELEMENT_R = /^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?([^>]*)\/{0}>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/i
The reason for that seems to be a non working check for self closing tags \/{0}
.
The final regex would be:
const HTML_BLOCK_ELEMENT_R = /^ *(?!<[a-z][^ >/]* ?\/>)<([a-z][^ >/]*) ?((?:[^>]*[^/])?)>\n?(\s*(?:<\1[^>]*?>[\s\S]*?<\/\1>|(?!<\1)[\s\S])*?)<\/\1>\n*/i
Thank you very much