From f4bebfdaa82ca90ba453509a94fabf8cb24b3fb0 Mon Sep 17 00:00:00 2001
From: Chris Lawton <chris.lawton@torchbox.com>
Date: Fri, 10 May 2019 12:12:55 +0100
Subject: [PATCH] add tomd and convert comment html to markdown

---
 .../templates/activity/include/listing_base.html         | 2 +-
 opentech/apply/funds/templatetags/markdown_tags.py       | 9 +++++++--
 requirements.txt                                         | 1 +
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/opentech/apply/activity/templates/activity/include/listing_base.html b/opentech/apply/activity/templates/activity/include/listing_base.html
index 3178eca20..a9eb4e27a 100644
--- a/opentech/apply/activity/templates/activity/include/listing_base.html
+++ b/opentech/apply/activity/templates/activity/include/listing_base.html
@@ -30,7 +30,7 @@
                 updated <a href="{{ activity.submission.get_absolute_url }}">{{ activity.submission.title }}</a>
             {% endif %}
 
-            <div class="feed__comment js-comment" data-id="{{activity.id}}" data-comment="{{activity.message}}">
+            <div class="feed__comment js-comment" data-id="{{activity.id}}" data-comment="{{activity.message|to_markdown}}">
                 {{ activity|display_for:request.user|submission_links|markdown|bleach }}
             </div>
 
diff --git a/opentech/apply/funds/templatetags/markdown_tags.py b/opentech/apply/funds/templatetags/markdown_tags.py
index 9ba5ff19d..a4e76e648 100644
--- a/opentech/apply/funds/templatetags/markdown_tags.py
+++ b/opentech/apply/funds/templatetags/markdown_tags.py
@@ -1,11 +1,16 @@
 import mistune
+import tomd
 
 from django import template
 
 register = template.Library()
 
+mistune_markdown = mistune.Markdown()
 
 @register.filter
 def markdown(value):
-    markdown = mistune.Markdown()
-    return markdown(value)
+    return mistune_markdown(value)
+
+@register.filter
+def to_markdown(value):
+    return tomd.convert(value)
diff --git a/requirements.txt b/requirements.txt
index 192f6e09a..ec3bc5337 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -43,6 +43,7 @@ mistune==0.8.4
 Pillow==4.3.0
 psycopg2==2.7.3.1
 social_auth_app_django==3.1.0
+tomd==0.1.3
 wagtail~=2.2.0
 wagtail-cache==0.5.1
 whitenoise==4.0
-- 
GitLab