mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
unicode: Changed the markup filters to use force_unicode() instead of
smart_unicode(), merely for consistency with the recommendations in the documentation. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5341 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c98f0b14c4
commit
29d2094b29
@ -16,7 +16,7 @@ silently fail and return the un-marked-up text.
|
|||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.encoding import smart_str, smart_unicode
|
from django.utils.encoding import smart_str, force_unicode
|
||||||
|
|
||||||
register = template.Library()
|
register = template.Library()
|
||||||
|
|
||||||
@ -26,9 +26,9 @@ def textile(value):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
raise template.TemplateSyntaxError, "Error in {% textile %} filter: The Python textile library isn't installed."
|
raise template.TemplateSyntaxError, "Error in {% textile %} filter: The Python textile library isn't installed."
|
||||||
return smart_unicode(value)
|
return force_unicode(value)
|
||||||
else:
|
else:
|
||||||
return smart_unicode(textile.textile(smart_str(value), encoding='utf-8', output='utf-8'))
|
return force_unicode(textile.textile(smart_str(value), encoding='utf-8', output='utf-8'))
|
||||||
|
|
||||||
def markdown(value):
|
def markdown(value):
|
||||||
try:
|
try:
|
||||||
@ -36,9 +36,9 @@ def markdown(value):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed."
|
raise template.TemplateSyntaxError, "Error in {% markdown %} filter: The Python markdown library isn't installed."
|
||||||
return smart_unicode(value)
|
return force_unicode(value)
|
||||||
else:
|
else:
|
||||||
return smart_unicode(markdown.markdown(smart_str(value)))
|
return force_unicode(markdown.markdown(smart_str(value)))
|
||||||
|
|
||||||
def restructuredtext(value):
|
def restructuredtext(value):
|
||||||
try:
|
try:
|
||||||
@ -46,11 +46,11 @@ def restructuredtext(value):
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
if settings.DEBUG:
|
if settings.DEBUG:
|
||||||
raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed."
|
raise template.TemplateSyntaxError, "Error in {% restructuredtext %} filter: The Python docutils library isn't installed."
|
||||||
return smart_unicode(value)
|
return force_unicode(value)
|
||||||
else:
|
else:
|
||||||
docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
|
docutils_settings = getattr(settings, "RESTRUCTUREDTEXT_FILTER_SETTINGS", {})
|
||||||
parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
|
parts = publish_parts(source=smart_str(value), writer_name="html4css1", settings_overrides=docutils_settings)
|
||||||
return smart_unicode(parts["fragment"])
|
return force_unicode(parts["fragment"])
|
||||||
|
|
||||||
register.filter(textile)
|
register.filter(textile)
|
||||||
register.filter(markdown)
|
register.filter(markdown)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user