from django.utils.safestring import mark_safe
import CommonMark


# Convert a markdown string into HTML5, and prevent Django from escaping it
def mdToHTML(value):

    return mark_safe(CommonMark.commonmark(value))


# Get a summary of a post
def summarize(fullBody):

    firstNewline = fullBody.find("\n")

    if firstNewline > 0:
        return fullBody[:firstNewline]

    return fullBody

@@ -1,166 +1,1123 @@
-from django.utils.safestring import mark_safe%0Aimport CommonMark%0A%0A%0A# Convert a markdown string into HTML5, and prevent Django from escaping it%0Adef mdToHTML(value):
+import CommonMark%0Afrom images.models import Image%0Afrom django.utils.safestring import mark_safe%0Afrom django.core.exceptions import ObjectDoesNotExist%0Aimport re%0A%0A%0Adef mdToHTML(value):%0A    %22%22%22Convert a markdown string into HTML5, and prevent Django from escaping it%0A    %22%22%22%0A    tags = %5B%5D%0A%0A    # Find all instance of the dynamic image markdown%0A    for tag in re.finditer(r'%5C!%5C%5BI:(%5B%5Cw-%5D+)%5C%5D', value):%0A%0A        tag_slug = tag.group(1)%0A%0A        try:%0A            image = Image.objects.get(slug=tag_slug)%0A            tag_dict = dict()%0A%0A            tag_dict%5B'start'%5D = tag.start()%0A            tag_dict%5B'end'%5D = tag.end()%0A            tag_dict%5B'image'%5D = image%0A%0A            tags.append(tag_dict)%0A%0A        except ObjectDoesNotExist:%0A            pass%0A%0A    # Replace all of the tags with actual markdown image tags, backwards, to%0A    # prevent changing string positions and messing up substitution%0A    for tag_dict in reversed(tags):%0A%0A        value = value%5B:tag_dict%5B'start'%5D%5D + %5C%0A            '!%5B%7B%7D%5D(%7B%7D)'.format(tag_dict%5B'image'%5D.desc,%0A                    tag_dict%5B'image'%5D.get_absolute_url()) + %5C%0A            value%5Btag_dict%5B'end'%5D:%5D
 %0A%0A  
@@ -1167,17 +1167,48 @@
 lue))%0A%0A%0A
-#
+def summarize(fullBody):%0A    %22%22%22
  Get a s
@@ -1228,32 +1228,15 @@
 ost%0A
-def summarize(fullBody):
+    %22%22%22
 %0A%0A  

Add code to replace custom dynamic image tag with standard markdown image syntax