Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A Mistune renderer that embeds images into the final document.

Project description

Latest Version Travis CI Status

Overview

This project allows you to translate markdown to HTML and to convert URLs or even local image file-paths to embedded images.

Local file-paths must be specifically enabled, for security reasons.

This project is Python 2 and Python 3 compatible.

Example

Image URLs

Short usage:

import mei

markdown = "![Random Ingenuity](http://www.randomingenuity.com/ri72.png)"
actual = mei.markdown(markdown)

# <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSU...kJggg==" alt="Random Ingenuity"></p>

Long usage:

import mei.embed_images
import mistune

renderer = mei.embed_images.EmbedImagesRenderer()
m = mistune.Markdown(renderer=renderer)

markdown = "![Random Ingenuity](http://www.randomingenuity.com/ri72.png)"
actual = m.render(markdown)

# <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSU...kJggg==" alt="Random Ingenuity"></p>

Local Images

Short usage:

import mei

markdown = "![alt text](/drawable-mdpi/ic_menu_paste.png)"
actual = mei.markdown(markdown)

# <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSU...TkSuQCC" alt="Random Ingenuity"></p>

Long usage:

import mei.embed_images
import mistune

renderer = mei.embed_images.EmbedImagesRenderer(embed_local_images=True)
m = mistune.Markdown(renderer=renderer)

markdown = "![alt text](/drawable-mdpi/ic_menu_paste.png)"
actual = m.render(markdown)

# <p><img src="data:image/png;base64,iVBORw0KGgoAAAANSU...TkSuQCC" alt="Random Ingenuity"></p>

Testing

Just run the test script:

$ ./test.sh
test_embed_images_local (test_embed_images.TestEmbedImages) ... ok
test_embed_images_url (test_embed_images.TestEmbedImages) ... ok
test_get_base64_with_image_filepath (test_embed_images.TestEmbedImages) ... ok
test_get_base64_with_image_url (test_embed_images.TestEmbedImages) ... ok
test_get_embedded_image_filepath (test_embed_images.TestEmbedImages) ... ok
test_get_embedded_image_filepath__xhtml (test_embed_images.TestEmbedImages) ... ok
test_get_embedded_image_url (test_embed_images.TestEmbedImages) ... ok
test_get_embedded_image_url__xhtml (test_embed_images.TestEmbedImages) ... ok
test_get_http2 (test_embed_images.TestEmbedImages) ... ok
test_get_http3 (test_embed_images.TestEmbedImages) ... ok
test_http (test_embed_images.TestEmbedImages) ... ok
test_http__instance_cached (test_embed_images.TestEmbedImages) ... ok
test_markdown (test_embed_images.TestEmbedImages) ... ok

----------------------------------------------------------------------
Ran 13 tests in 0.016s

OK

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for markdown-embedimages, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size markdown-embedimages-0.1.4.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page