markdown-djangostaticimage

Markdown extension: Add static tag to image source


Keywords
django, markdown, static, html, text, filter
License
MIT
Install
pip install markdown-djangostaticimage==0.1

Documentation

Markdown extension for modifying local links to Django static links

Author: Melvin Koh

Installing DjangoStaticImage Markdown Extension

    pip install markdown-djangostaticimage

Basic Usage

from markdown import Markdown
from django_static_image import DjangoStaticImageExtension

text = """![profile_pic](images/profile_pic.png)"""

md = markdown.Markdown(extensions=[DjangoStaticImageExtension()])
html = md.convert(text)

print(html)

# Output
'<p><img alt="profile_pic" src="{% static 'images/profile_pic.png' %}" /></p>'

Note that Markdown by default converts each line as a paragraph

Examples:

Input Markdown

    ![profile_picture](images/my_profile_picture.png)

Output without extension:

    <img alt="profile_picture" src="images/my_profile_picture.png" />

Output with this extension:

    <img alt="profile_picture" src={% static "images/my_profile_picture.png" %} />

Options:

  1. Add Prefix before link:
    <img alt="profile_picture" src={% static "<prefix>/images/my_profile_picture.png" %} />