showdownjs / showdown

A bidirectional Markdown to HTML to Markdown converter written in Javascript
http://www.showdownjs.com/
MIT License
14.1k stars 1.57k forks source link

Incorrect parsing of images with parentheses in URL #1007

Open polterguy opened 2 months ago

polterguy commented 2 months ago

Sometimes image URLs contains parenthesis such as follows.

![Image A whale's tail out of the water with snowy mountains in the background in Juneau](https://www.travelandleisure.com/thmb/rBEDe9bXdm41kFdrXr6GxkXK0fI=/1500x0/filters:no_upscale():max_bytes(150000):strip_icc()/TAL-Whale-ALASKAUPDATE0323-7bbad6b4e1914d748074ebd3b6673273.jpg)

I realise that these can be displayed by escaping the parentheses such as for instance \(, but that is not an option, since sometimes I display markdown I'm not in control over myself. Technically it should be able to count opening / closing parentheses during parsing, and only close the URL part once it's back to zero, implying having a counter for each opening parentheses incrementing the count, and decrementing when you see an end parentheses, for then to only close the URL once it returns back to zero.

This could be a configuration, to avoid backward compatibility issues - And it might be a configuration already for all I know, however how do you suggest I solve this, if it can be solved?

I am willing to provide a patch if you're interested, but this is a problem I must solve - "marked" Angular component for instance handles this "correctly" ...

Psst, other parsers will display these correctly, which creates the problem I assume - See screenshots for examples which are taken from "marked" ...

Screenshot 2024-05-09 at 10 06 57 AM Screenshot 2024-05-09 at 10 07 05 AM