💾 Archived View for republic.circumlunar.space › users › johngodlee › posts › 2020-06-30-vim-html-md… captured on 2024-07-09 at 00:50:29. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-12-04)

-=-=-=-=-=-=-

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.