Skip to content

Commit 3324a12

Browse files
committed
Merge branch 'hotfix/unicode_title'
2 parents 621e431 + e7763b3 commit 3324a12

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

CHANGELOG.textile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
h1. Textile Changelog
22

3+
h2. Version 2.3.3
4+
* Bugfix: Unicode in URL titles no longer break everything ("#30":https://github.com/textile/python-textile/issues/30)
5+
* Display DeprecationWarning when using textile on Python 2.6.
6+
37
h2. Version 2.3.2
48
* Bugfix: properly handle @":"@ as text, not a link.
59

tests/test_github_issues.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,9 @@ def parseWapProfile(self, url):
7979
8080
\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>""")
8181
assert result == expect
82+
83+
def test_github_issue_30():
84+
text ='"Tëxtíle (Tëxtíle)":http://lala.com'
85+
result = textile.textile(text)
86+
expect = '\t<p><a href="http://lala.com" title="Tëxtíle">Tëxtíle</a></p>'
87+
assert result == expect

textile/__init__.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
from __future__ import unicode_literals
22

3+
import sys
4+
import warnings
5+
36
from .core import textile, textile_restricted, Textile
47
from .version import VERSION
58

69
__all__ = ['textile', 'textile_restricted']
710

811
__version__ = VERSION
12+
13+
14+
if sys.version_info[:2] == (2, 6):
15+
warnings.warn(
16+
"Python 2.6 is no longer supported by the Python core team, please "
17+
"upgrade your Python. A future version of textile will drop support "
18+
"for Python 2.6",
19+
DeprecationWarning
20+
)

textile/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,10 @@ def _casesdefault(c, pop, popped, url_chars, counts, pre):
874874
url = self.shelveURL(self.encode_url(urlunsplit(uri_parts)))
875875
attributes = parse_attributes(atts)
876876
if title:
877-
attributes['title'] = title
877+
# if the title contains unicode data, it is annoying to get Python
878+
# 2.6 and all the latter versions working properly. But shelving
879+
# the title is a quick and dirty solution.
880+
attributes['title'] = self.shelve(title)
878881
attributes['href'] = url
879882
if self.rel:
880883
attributes['rel'] = self.rel

textile/utils.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,24 @@ def generate_tag(tag, content, attributes=None):
5050
content are strings, the attributes argument is a dictionary. As
5151
a convenience, if the content is ' /', a self-closing tag is generated."""
5252
content = six.text_type(content)
53-
element = ElementTree.Element(tag, attrib=attributes)
5453
enc = 'unicode'
5554
if six.PY2:
5655
enc = 'UTF-8'
5756
if not tag:
5857
return content
58+
element = ElementTree.Element(tag, attrib=attributes)
5959
# FIXME: Kind of an ugly hack. There *must* be a cleaner way. I tried
60-
# adding text by assigning it to a.text. That results in non-ascii text
61-
# being html-entity encoded. Not bad, but not entirely matching
62-
# php-textile either.
60+
# adding text by assigning it to element_tag.text. That results in
61+
# non-ascii text being html-entity encoded. Not bad, but not entirely
62+
# matching php-textile either.
6363
try:
6464
element_tag = ElementTree.tostringlist(element, encoding=enc,
6565
method='html')
6666
element_tag.insert(len(element_tag) - 1, content)
6767
element_text = ''.join(element_tag)
6868
except AttributeError:
6969
# Python 2.6 doesn't have the tostringlist method, so we have to treat
70-
# it different.
70+
# it differently.
7171
element_tag = ElementTree.tostring(element, encoding=enc)
7272
element_text = re.sub(r"<\?xml version='1.0' encoding='UTF-8'\?>\n",
7373
'', element_tag)

textile/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = '2.3.2'
1+
VERSION = '2.3.3'

0 commit comments

Comments
 (0)