Python-Markdown / markdown

A Python implementation of John Gruber’s Markdown with Extension support.
https://python-markdown.github.io/
BSD 3-Clause "New" or "Revised" License
3.74k stars 858 forks source link

Is there a way to convert Linked Images to B64 during markdown to html conversion? #1233

Closed bpsizemore closed 2 years ago

bpsizemore commented 2 years ago

Wondering if there is existing functionality to take a markdown link like:

![text]('https://site.com/path')
![text]('./some/local/path')

and convert to html like

<img src="data:image/png;base64, ...">
<img src="data:image/png;base64, ...">

I'm trying to convert a markdown file that references images either remote or on the local filesystem and produce a single HTML file that can be loaded anywhere. I don't see any functionality currently that would achieve that, and looking at potentially adding it to the ImageInlineProcessor. https://github.com/Python-Markdown/markdown/blob/9aa4586d92181a07d3c054d81ada9b100c879d68/markdown/inlinepatterns.py#L757

Is this something the markdown project would be open to a PR for? I imagine flag that can be toggled to enable or disable global image encoding into the resulting conversion.

facelessuser commented 2 years ago

You can try with an extension. Here is one that I wrote: https://facelessuser.github.io/pymdown-extensions/extensions/b64/. If that isn't to your liking, there may be others, or you can write your own.