Beispiel #1
0
 def item_description(self, post):
     key = 'blog_feed:%d' % post.id
     summary = cache.get(key)
     if summary is None:
         summary = FeedMath.convert(markdown(post.summary or post.content, 'blog'))
         cache.set(key, summary, 86400)
     return summary
Beispiel #2
0
 def item_description(self, comment):
     key = 'comment_feed:%d' % comment.id
     desc = cache.get(key)
     if desc is None:
         desc = FeedMath.convert(markdown(comment.body, 'comment'))
         cache.set(key, desc, 86400)
     return desc
Beispiel #3
0
 def item_description(self, problem):
     key = 'problem_feed:%d' % problem.id
     desc = cache.get(key)
     if desc is None:
         desc = FeedMath.convert(markdown(problem.description, 'problem'))[:500] + '...'
         cache.set(key, desc, 86400)
     return desc
Beispiel #4
0
 def render(self, context):
     value = self.nodelist.render(context)
     try:
         return mark_safe(markdown_trois.markdown(value, self.style))
     except ImportError:
         if settings.DEBUG:
             raise template.TemplateSyntaxError("Error in `markdown` tag: "
                                                "The python-markdown2 library isn't installed.")
         return force_unicode(value)
Beispiel #5
0
def markdown_filter(value, style="default"):
    """Processes the given value as Markdown, optionally using a particular
    Markdown style/config

    Syntax::

        {{ value|markdown }}            {# uses the "default" style #}
        {{ value|markdown:"mystyle" }}

    Markdown "styles" are defined by the `MARKDOWN_TROIS_STYLES` setting.
    """
    try:
        return mark_safe(markdown_trois.markdown(value, style))
    except ImportError:
        if settings.DEBUG:
            raise template.TemplateSyntaxError("Error in `markdown` filter: "
                                               "The python-markdown2 library isn't installed.")
        return force_unicode(value)