Skip to content

Commit

Permalink
Removed dependency on Django from mdx_foreign_formats, such that it c…
Browse files Browse the repository at this point in the history
…ould now be used by non-Django apps.
  • Loading branch information
lethain committed Jul 8, 2008
1 parent 5f124ad commit e66fa35
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion markdown/mdx_foreign_formats.py
@@ -1,6 +1,22 @@
import re
from lifeflow.markdown import markdown
from django.utils.encoding import smart_str, force_unicode

def smart_str(s, encoding='utf-8', errors='strict'):
"""
Returns a bytestring version of 's', encoded as specified in 'encoding'.
Borrowed and simplified for this purpose from `django.utils.encoding`.
"""
if not isinstance(s, basestring):
try:
return str(s)
except UnicodeEncodeError:
return unicode(s).encode(encoding, errors)
elif isinstance(s, unicode):
return s.encode(encoding, errors)
elif s and encoding != 'utf-8':
return s.decode('utf-8', errors).encode(encoding, errors)
else:
return s

class ForeignFormatsExtension (markdown.Extension):

Expand Down

0 comments on commit e66fa35

Please sign in to comment.