SMOLNET PORTAL home about changes

Vim HTML img tag to markdown


DATE: 2020-06-30
AUTHOR: John L. Godlee


I was quite proud of myself for figuring this one out in only about 2 minutes, in Vim. Starting with an HTML img tag:

<img src="img/jetz_table.png" alt="Functional diversity measures" width="640">


And using this Vim regex:

s/<img src="\(.\{-}\)".*alt="\(.\{-}\)".*/![\2](\1)/g


To create this Markdown formatted image link:

![Functional diversity measures](img/jetz_table.png)


This was my first proper outing using \{-} for non-greedy matching, used on the double quotes ". It also uses capture groups \(.{-}\) -> \1.

Response: 20 (Success), text/gemini
Original URLgemini://republic.circumlunar.space/users/johngodlee/post...
Status Code20 (Success)
Content-Typetext/gemini; charset=utf-8