Skip to content

Commit

Permalink
Merge branch 'hotfix/unicode_title'
Browse files Browse the repository at this point in the history
  • Loading branch information
ikirudennis committed Jul 18, 2016
2 parents 621e431 + e7763b3 commit 3324a12
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.textile
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
h1. Textile Changelog

h2. Version 2.3.3
* Bugfix: Unicode in URL titles no longer break everything ("#30":https://github.com/textile/python-textile/issues/30)
* Display DeprecationWarning when using textile on Python 2.6.

h2. Version 2.3.2
* Bugfix: properly handle @":"@ as text, not a link.

Expand Down
6 changes: 6 additions & 0 deletions tests/test_github_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,9 @@ def parseWapProfile(self, url):
\t<p>Of course there&#8217;s a lot more error handling to do (and useful data to glean off the <a href="XML"><span class="caps">XML</span></a>), but being able to cut through all the usual parsing crap is immensely gratifying.</p>""")
assert result == expect

def test_github_issue_30():
text ='"Tëxtíle (Tëxtíle)":http://lala.com'
result = textile.textile(text)
expect = '\t<p><a href="http://lala.com" title="Tëxtíle">Tëxtíle</a></p>'
assert result == expect
12 changes: 12 additions & 0 deletions textile/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
from __future__ import unicode_literals

import sys
import warnings

from .core import textile, textile_restricted, Textile
from .version import VERSION

__all__ = ['textile', 'textile_restricted']

__version__ = VERSION


if sys.version_info[:2] == (2, 6):
warnings.warn(
"Python 2.6 is no longer supported by the Python core team, please "
"upgrade your Python. A future version of textile will drop support "
"for Python 2.6",
DeprecationWarning
)
5 changes: 4 additions & 1 deletion textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,10 @@ def _casesdefault(c, pop, popped, url_chars, counts, pre):
url = self.shelveURL(self.encode_url(urlunsplit(uri_parts)))
attributes = parse_attributes(atts)
if title:
attributes['title'] = title
# if the title contains unicode data, it is annoying to get Python
# 2.6 and all the latter versions working properly. But shelving
# the title is a quick and dirty solution.
attributes['title'] = self.shelve(title)
attributes['href'] = url
if self.rel:
attributes['rel'] = self.rel
Expand Down
10 changes: 5 additions & 5 deletions textile/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ def generate_tag(tag, content, attributes=None):
content are strings, the attributes argument is a dictionary. As
a convenience, if the content is ' /', a self-closing tag is generated."""
content = six.text_type(content)
element = ElementTree.Element(tag, attrib=attributes)
enc = 'unicode'
if six.PY2:
enc = 'UTF-8'
if not tag:
return content
element = ElementTree.Element(tag, attrib=attributes)
# FIXME: Kind of an ugly hack. There *must* be a cleaner way. I tried
# adding text by assigning it to a.text. That results in non-ascii text
# being html-entity encoded. Not bad, but not entirely matching
# php-textile either.
# adding text by assigning it to element_tag.text. That results in
# non-ascii text being html-entity encoded. Not bad, but not entirely
# matching php-textile either.
try:
element_tag = ElementTree.tostringlist(element, encoding=enc,
method='html')
element_tag.insert(len(element_tag) - 1, content)
element_text = ''.join(element_tag)
except AttributeError:
# Python 2.6 doesn't have the tostringlist method, so we have to treat
# it different.
# it differently.
element_tag = ElementTree.tostring(element, encoding=enc)
element_text = re.sub(r"<\?xml version='1.0' encoding='UTF-8'\?>\n",
'', element_tag)
Expand Down
2 changes: 1 addition & 1 deletion textile/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VERSION = '2.3.2'
VERSION = '2.3.3'

0 comments on commit 3324a12

Please sign in to comment.