Skip to content

Instantly share code, notes, and snippets.

@csytan
Created June 25, 2009 18:28
Show Gist options
  • Save csytan/136060 to your computer and use it in GitHub Desktop.
Save csytan/136060 to your computer and use it in GitHub Desktop.
markdown2.py django custom filter
urlfinder = re.compile('^(http:\/\/\S+)')
urlfinder2 = re.compile('\s(http:\/\/\S+)')
@register.filter('markdownify')
def markdownify(value):
import feedparser
import markdown2
value = urlfinder.sub(r'<\1>', value)
value = urlfinder2.sub(r' <\1>', value)
html = markdown2.markdown(value)
html = feedparser._sanitizeHTML(html, 'utf-8')
html = html.replace('<a href=', '<a rel="nofollow" href=')
return safestring.mark_safe(html)
markdownify.is_safe = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment