diff options
author | Dan McGee <dan@archlinux.org> | 2014-12-08 19:52:55 -0600 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2014-12-08 19:52:55 -0600 |
commit | 60327d96a687669d8b8842ecf0ac16c11a8f6483 (patch) | |
tree | fe8f5a15f994fd21251bcd9dd41f62e76a7958ad | |
parent | 9faa6d580e73adfe0f3a194b09d7f6b91b80aae9 (diff) |
Upgrade to python-markdown 2.5.2
safe_mode is now deprecated, so adjust things accordingly.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | main/utils.py | 15 | ||||
-rw-r--r-- | news/models.py | 7 | ||||
-rw-r--r-- | news/views.py | 6 | ||||
-rw-r--r-- | releng/models.py | 6 | ||||
-rw-r--r-- | requirements.txt | 2 | ||||
-rw-r--r-- | requirements_prod.txt | 2 |
6 files changed, 24 insertions, 14 deletions
diff --git a/main/utils.py b/main/utils.py index cf156566..f94f314d 100644 --- a/main/utils.py +++ b/main/utils.py @@ -4,6 +4,8 @@ except ImportError: import pickle import hashlib +import markdown +from markdown.extensions import Extension from django.core.cache import cache from django.db import connections, router @@ -109,6 +111,19 @@ def database_vendor(model, mode='read'): return connections[database].vendor +class EscapeHtml(Extension): + def extendMarkdown(self, md, md_globals): + del md.preprocessors['html_block'] + del md.inlinePatterns['html'] + + +def parse_markdown(text, allow_html=False): + if allow_html: + return markdown.markdown(text, enable_attributes=False) + ext = [EscapeHtml()] + return markdown.markdown(text, extensions=ext, enable_attributes=False) + + def groupby_preserve_order(iterable, keyfunc): '''Take an iterable and regroup using keyfunc to determine whether items belong to the same group. The order of the iterable is preserved and diff --git a/news/models.py b/news/models.py index 985c1088..a66da8d4 100644 --- a/news/models.py +++ b/news/models.py @@ -1,11 +1,11 @@ -import markdown - from django.db import models from django.contrib.auth.models import User from django.contrib.sites.models import Site from django.utils.safestring import mark_safe from django.utils.timezone import now +from main.utils import parse_markdown + class News(models.Model): slug = models.SlugField(max_length=255, unique=True) @@ -22,8 +22,7 @@ class News(models.Model): return '/news/%s/' % self.slug def html(self): - return mark_safe(markdown.markdown( - self.content, safe_mode=self.safe_mode, enable_attributes=False)) + return mark_safe(parse_markdown(self.content, not self.safe_mode)) def __unicode__(self): return self.title diff --git a/news/views.py b/news/views.py index ca4fdf97..274ba75d 100644 --- a/news/views.py +++ b/news/views.py @@ -1,5 +1,3 @@ -import markdown - from django import forms from django.http import HttpResponse from django.shortcuts import get_object_or_404, redirect @@ -8,7 +6,7 @@ from django.views.generic import (DetailView, ListView, CreateView, UpdateView, DeleteView) from .models import News -from main.utils import find_unique_slug +from main.utils import find_unique_slug, parse_markdown class NewsForm(forms.ModelForm): @@ -62,7 +60,7 @@ def view_redirect(request, object_id): @require_POST def preview(request): data = request.POST.get('data', '') - markup = markdown.markdown(data, safe_mode=True, enable_attributes=False) + markup = parse_markdown(data) return HttpResponse(markup) # vim: set ts=4 sw=4 et: diff --git a/releng/models.py b/releng/models.py index 436308f2..c1a82589 100644 --- a/releng/models.py +++ b/releng/models.py @@ -2,7 +2,6 @@ from base64 import b64decode from bencode import bdecode, bencode from datetime import datetime import hashlib -import markdown from pytz import utc from django.conf import settings @@ -12,7 +11,7 @@ from django.db.models.signals import pre_save from django.utils.safestring import mark_safe from main.fields import PositiveBigIntegerField -from main.utils import set_created_field +from main.utils import set_created_field, parse_markdown class IsoOption(models.Model): @@ -154,8 +153,7 @@ class Release(models.Model): return "magnet:?%s" % '&'.join(['%s=%s' % (k, v) for k, v in query]) def info_html(self): - return mark_safe(markdown.markdown( - self.info, safe_mode=True, enable_attributes=False)) + return mark_safe(parse_markdown(self.info)) def torrent(self): try: diff --git a/requirements.txt b/requirements.txt index 473535b6..2a5dba96 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,7 +2,7 @@ Django==1.7.1 IPy==0.81 Jinja2==2.7.3 -Markdown==2.4.1 +Markdown==2.5.2 bencode==1.0 django-jinja==1.0.5 django_countries==3.0.1 diff --git a/requirements_prod.txt b/requirements_prod.txt index bb7567f3..6edfa17f 100644 --- a/requirements_prod.txt +++ b/requirements_prod.txt @@ -2,7 +2,7 @@ Django==1.7.1 IPy==0.81 Jinja2==2.7.3 -Markdown==2.4.1 +Markdown==2.5.2 bencode==1.0 django-jinja==1.0.5 django_countries==3.0.1 |