I am working on a nodejs CMS where users write blog posts in Markdown locally, after uploading we process the post in an HTML file. Sometimes users will add a picture like my dog.jpg
to the post by copying the image and writing:
![a picture of my dog](my dog.jpg)
I use uslug to convert all filenames so that my dog.jpg
becomes my-dog.jpg
. However I also need to update the link in the blogpost using uslug, because a) otherwise the link would break because we just changed the filename and b) because most markdown parsers for node will skip the above image syntax because of the whitespace (while the image does get previewed in a lot of local Markdown editors, like Mou).
Does anybody know how I can achieve this using regex?
You'll need a lot of slashes:
string.replace(/(!\[.*?\]\()(.+?)(\))/g, function(whole, a, b, c) {
return a + addDashesOrWhatever(b) + c;
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With