Skip to content

Commit

Permalink
Merge pull request #4 from rgs258/bugfix/missing_file
Browse files Browse the repository at this point in the history
Adds missing markdown_view/markdown_extensions.py
  • Loading branch information
rgs258 authored Jul 6, 2020
2 parents ae72ba3 + f6f7284 commit 341dd08
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Changelog
0.0.2 (2020-07-06)
------------------
#. Remove support for Django pre-2.2
#.
#. Adds missing file markdown_view/markdown_extensions.py

0.0.1 (2020-06-16)
------------------
Expand Down
19 changes: 19 additions & 0 deletions markdown_view/markdown_extensions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import re

from markdown.treeprocessors import Treeprocessor
from markdown.extensions import Extension


class InlineImageProcessor(Treeprocessor):
def run(self, root):
for element in root.iter("img"):
src_orig = element.attrib.get('src', '')
src_re = re.sub("[/\\\]*static[/\\\]*", "", src_orig)
src = "{{% static '{}' %}}".format(src_re)
element.attrib["src"] = src
element.attrib["class"] = "img-fluid"


class ImageExtension(Extension):
def extendMarkdown(self, md):
md.treeprocessors.register(InlineImageProcessor(md), 'inlineimageprocessor', 15)

0 comments on commit 341dd08

Please sign in to comment.