Skip to content

Commit cb33419

Browse files
committed
finally fix this one lingering testing bug.
1 parent fc6530b commit cb33419

2 files changed

Lines changed: 82 additions & 82 deletions

File tree

textile/functions.py

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -114,86 +114,6 @@ class Textile(object):
114114

115115
note_index = 1
116116

117-
# We'll be searching for characters that need to be HTML-encoded to produce
118-
# properly valid html.
119-
# These are the defaults that work in most cases. Below, we'll copy this
120-
# and modify the necessary pieces to make it work for characters at the
121-
# beginning of the string.
122-
glyph_search = [
123-
# apostrophe's
124-
re.compile(r"(^|\w)'(\w)", re.U),
125-
# back in '88
126-
re.compile(r"(\s)'(\d+\w?)\b(?!')", re.U),
127-
# single closing
128-
re.compile(r"(^|\S)'(?=\s|%s|$)" % pnct, re.U),
129-
# single opening
130-
re.compile(r"'", re.U),
131-
# double closing
132-
re.compile(r'(^|\S)"(?=\s|%s|$)' % pnct, re.U),
133-
# double opening
134-
re.compile(r'"'),
135-
# ellipsis
136-
re.compile(r'([^.]?)\.{3}', re.U),
137-
# ampersand
138-
re.compile(r'(\s)&(\s)', re.U),
139-
# em dash
140-
re.compile(r'(\s?)--(\s?)', re.U),
141-
# en dash
142-
re.compile(r'\s-(?:\s|$)', re.U),
143-
# dimension sign
144-
re.compile(r'(\d+)( ?)x( ?)(?=\d+)', re.U),
145-
# trademark
146-
re.compile(r'\b ?[([]TM[])]', re.I | re.U),
147-
# registered
148-
re.compile(r'\b ?[([]R[])]', re.I | re.U),
149-
# copyright
150-
re.compile(r'\b ?[([]C[])]', re.I | re.U),
151-
# 1/2
152-
re.compile(r'[([]1\/2[])]', re.I | re.U),
153-
# 1/4
154-
re.compile(r'[([]1\/4[])]', re.I | re.U),
155-
# 3/4
156-
re.compile(r'[([]3\/4[])]', re.I | re.U),
157-
# degrees
158-
re.compile(r'[([]o[])]', re.I | re.U),
159-
# plus/minus
160-
re.compile(r'[([]\+\/-[])]', re.I | re.U),
161-
]
162-
163-
# These are the changes that need to be made for characters that occur at
164-
# the beginning of the string.
165-
glyph_search_initial = list(glyph_search)
166-
# apostrophe's
167-
glyph_search_initial[0] = re.compile(r"(\w)'(\w)", re.U)
168-
# single closing
169-
glyph_search_initial[2] = re.compile(r"(\S)'(?=\s|%s|$)" % pnct, re.U)
170-
# double closing
171-
glyph_search_initial[4] = re.compile(r'(\S)"(?=\s|%s|$)' % pnct, re.U)
172-
173-
glyph_replace = [x % _glyph_defaults for x in (
174-
r'\1%(apostrophe)s\2', # apostrophe's
175-
r'\1%(apostrophe)s\2', # back in '88
176-
r'\1%(quote_single_close)s', # single closing
177-
r'%(quote_single_open)s', # single opening
178-
r'\1%(quote_double_close)s', # double closing
179-
r'%(quote_double_open)s', # double opening
180-
r'\1%(ellipsis)s', # ellipsis
181-
r'\1%(ampersand)s\2', # ampersand
182-
r'\1%(emdash)s\2', # em dash
183-
r' %(endash)s ', # en dash
184-
r'\1\2%(dimension)s\3', # dimension sign
185-
r'%(trademark)s', # trademark
186-
r'%(registered)s', # registered
187-
r'%(copyright)s', # copyright
188-
r'%(half)s', # 1/2
189-
r'%(quarter)s', # 1/4
190-
r'%(threequarters)s', # 3/4
191-
r'%(degrees)s', # degrees
192-
r'%(plusminus)s', # plus/minus
193-
r'<acronym title="\2">\1</acronym>', # 3+ uppercase acronym
194-
r'<span class="caps">\1</span>\2', # 3+ uppercase
195-
)]
196-
197117
doctype_whitelist = ['html', 'xhtml', 'html5']
198118

199119
def __init__(self, restricted=False, lite=False, noimage=False,
@@ -212,6 +132,86 @@ def __init__(self, restricted=False, lite=False, noimage=False,
212132
self.html_type = html_type
213133
self.max_span_depth = 5
214134

135+
# We'll be searching for characters that need to be HTML-encoded to produce
136+
# properly valid html.
137+
# These are the defaults that work in most cases. Below, we'll copy this
138+
# and modify the necessary pieces to make it work for characters at the
139+
# beginning of the string.
140+
self.glyph_search = [
141+
# apostrophe's
142+
re.compile(r"(^|\w)'(\w)", re.U),
143+
# back in '88
144+
re.compile(r"(\s)'(\d+\w?)\b(?!')", re.U),
145+
# single closing
146+
re.compile(r"(^|\S)'(?=\s|%s|$)" % self.pnct, re.U),
147+
# single opening
148+
re.compile(r"'", re.U),
149+
# double closing
150+
re.compile(r'(^|\S)"(?=\s|%s|$)' % self.pnct, re.U),
151+
# double opening
152+
re.compile(r'"'),
153+
# ellipsis
154+
re.compile(r'([^.]?)\.{3}', re.U),
155+
# ampersand
156+
re.compile(r'(\s)&(\s)', re.U),
157+
# em dash
158+
re.compile(r'(\s?)--(\s?)', re.U),
159+
# en dash
160+
re.compile(r'\s-(?:\s|$)', re.U),
161+
# dimension sign
162+
re.compile(r'(\d+)( ?)x( ?)(?=\d+)', re.U),
163+
# trademark
164+
re.compile(r'\b ?[([]TM[])]', re.I | re.U),
165+
# registered
166+
re.compile(r'\b ?[([]R[])]', re.I | re.U),
167+
# copyright
168+
re.compile(r'\b ?[([]C[])]', re.I | re.U),
169+
# 1/2
170+
re.compile(r'[([]1\/2[])]', re.I | re.U),
171+
# 1/4
172+
re.compile(r'[([]1\/4[])]', re.I | re.U),
173+
# 3/4
174+
re.compile(r'[([]3\/4[])]', re.I | re.U),
175+
# degrees
176+
re.compile(r'[([]o[])]', re.I | re.U),
177+
# plus/minus
178+
re.compile(r'[([]\+\/-[])]', re.I | re.U),
179+
]
180+
181+
# These are the changes that need to be made for characters that occur at
182+
# the beginning of the string.
183+
self.glyph_search_initial = list(self.glyph_search)
184+
# apostrophe's
185+
self.glyph_search_initial[0] = re.compile(r"(\w)'(\w)", re.U)
186+
# single closing
187+
self.glyph_search_initial[2] = re.compile(r"(\S)'(?=\s|%s|$)" % self.pnct, re.U)
188+
# double closing
189+
self.glyph_search_initial[4] = re.compile(r'(\S)"(?=\s|%s|$)' % self.pnct, re.U)
190+
191+
self.glyph_replace = [x % _glyph_defaults for x in (
192+
r'\1%(apostrophe)s\2', # apostrophe's
193+
r'\1%(apostrophe)s\2', # back in '88
194+
r'\1%(quote_single_close)s', # single closing
195+
r'%(quote_single_open)s', # single opening
196+
r'\1%(quote_double_close)s', # double closing
197+
r'%(quote_double_open)s', # double opening
198+
r'\1%(ellipsis)s', # ellipsis
199+
r'\1%(ampersand)s\2', # ampersand
200+
r'\1%(emdash)s\2', # em dash
201+
r' %(endash)s ', # en dash
202+
r'\1\2%(dimension)s\3', # dimension sign
203+
r'%(trademark)s', # trademark
204+
r'%(registered)s', # registered
205+
r'%(copyright)s', # copyright
206+
r'%(half)s', # 1/2
207+
r'%(quarter)s', # 1/4
208+
r'%(threequarters)s', # 3/4
209+
r'%(degrees)s', # degrees
210+
r'%(plusminus)s', # plus/minus
211+
r'<acronym title="\2">\1</acronym>', # 3+ uppercase acronym
212+
r'<span class="caps">\1</span>\2', # 3+ uppercase
213+
)]
214+
215215
if self.html_type == 'html5':
216216
self.glyph_replace[19] = r'<abbr title="\2">\1</abbr>'
217217

textile/tests/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ class TestKnownValues():
233233
# test above properly but not this one.
234234
# In all my testing, textile properly handles the test below according
235235
# to specification... and the prophecy.
236-
# (u"""| Foreign EXPÓŅÉNTIAL |""",
237-
# u"""\t<table>\n\t\t<tr>\n\t\t\t<td> Foreign <span class="caps">EXPÓŅÉNTIAL</span> </td>\n\t\t</tr>\n\t</table>"""),
236+
(u"""| Foreign EXPÓŅÉNTIAL |""",
237+
u"""\t<table>\n\t\t<tr>\n\t\t\t<td> Foreign <span class="caps">EXPÓŅÉNTIAL</span> </td>\n\t\t</tr>\n\t</table>"""),
238238

239239
(u"""p=. Tell me, what is AJAX(Asynchronous Javascript and XML), please?""",
240240
u"""\t<p style="text-align:center;">Tell me, what is <acronym title="Asynchronous Javascript and XML"><span class="caps">AJAX</span></acronym>, please?</p>"""),

0 commit comments

Comments
 (0)