David Chambers avatar David Chambers committed fc3c641

Updated `fetch_comments` to have it convert comments to HTML before caching them.

Comments (0)

Files changed (2)

 import mango
 from mango import utf8
 from mango.settings import *
+from mango.templatetags.mango_extras import sanitize
 from mango.utils import canonicalize, logger
 
 block = r'(?m)^(%s(?=[ \n])[^\n]*(\n|$))+'
             except disqus.APIError, error:
                 logger.warning('Disqus API error: %s' % error)
             else:
-                comments = [c for c in thread_posts if c.has_been_moderated or not COMMENTS_REQUIRE_APPROVAL]
+                for comment in thread_posts:
+                    if comment.has_been_moderated or not COMMENTS_REQUIRE_APPROVAL:
+                        md.reset()
+                        comment.html = sanitize(md.convert(comment.message))
+                        comments.append(comment)
                 comments.sort(key=lambda comment: comment.created_at)
                 cache.set(cache_key, comments, 24*60*60)
                 logger.debug('Disqus comments for "%s" cached' % thread.title)

templates/comment.dhtml

 {% load mango_extras %}
 					<article class="{% if comment|is_author_comment %}author {% endif %}comment">
 						<div>
-							{{ comment.message|convert|sanitize }}
+							{{ comment.html }}
 						</div>
 						<footer>
 							<img alt="" src="{{ comment|author_email_hash|gravatar }}" />{% if comment|author_url %}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.