hi have thousands of these regex links in html for images
<img src="image.png" alt="" style="zoom:55%;" />
I want to convert them to a quatro (.qmd) markdown links which will look like this
![](image.png){.r-stretch}
I have seen you can use a select in "
but am unclear on how to only choose the image.png
link but not anything in the documents in quotes. Also unclear is how to do the find and replace part (sed, VS code?)
CodePudding user response:
Try searching
<img\s (?=[^>]*\bsrc="([^>]*?)")(?=[^>]*\balt="([^>]*?)")?[^>]*\/>
and replacing it with
![$2]($1){.r-stretch}
You may check the test cases here
This will also put anything in alt
inside of the square brakets if there's any. If you don't want this behavior, you may just try <img\s (?=[^>]*\bsrc="([^>]*?)")[^>]*\/>
with subsitution of ![]($1){.r-stretch}
.