Skip to content

Commit a12165a

Browse files
committed
merge in changes to regex module being optional and fix a bug related to that.
1 parent d4388e4 commit a12165a

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import sys
44

5-
install_requires = ['regex']
5+
install_requires = []
66

77
try:
88
from collections import OrderedDict

textile/core.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
2020
"""
2121

22-
import re
23-
import regex
2422
import uuid
2523

2624
from textile.tools import sanitizer, imagesize
@@ -48,6 +46,18 @@
4846
from HTMLParser import HTMLParser
4947

5048

49+
try:
50+
# Use regex module for matching uppercase characters if installed,
51+
# otherwise fall back to finding all the uppercase chars in a loop.
52+
import regex as re
53+
upper_re_s = r'\p{Lu}'
54+
except ImportError:
55+
import re
56+
from sys import maxunicode
57+
upper_re_s = "".join([unichr(c) for c in xrange(maxunicode) if
58+
unichr(c).isupper()])
59+
60+
5161
def _normalize_newlines(string):
5262
out = string.strip()
5363
out = re.sub(r'\r\n', '\n', out)
@@ -182,10 +192,10 @@ def __init__(self, restricted=False, lite=False, noimage=False,
182192
# plus/minus
183193
re.compile(r'[([]\+\/-[])]', re.I | re.U),
184194
# 3+ uppercase acronym
185-
regex.compile(r'\b([\p{Lu}][\p{Lu}0-9]{2,})\b(?:[(]([^)]*)[)])'),
195+
re.compile(r'\b([%s%s0-9]{2,})\b(?:[(]([^)]*)[)])' % (upper_re_s, upper_re_s)),
186196
# 3+ uppercase
187-
regex.compile(r"""(?:(?<=^)|(?<=\s)|(?<=[>\(;-]))([\p{Lu}]{3,})(\w*)(?=\s|%s|$)(?=[^">]*?(<|$))""" %
188-
self.pnct_re_s),
197+
re.compile(r"""(?:(?<=^)|(?<=\s)|(?<=[>\(;-]))([%s]{3,})(\w*)(?=\s|%s|$)(?=[^">]*?(<|$))""" %
198+
(upper_re_s, self.pnct_re_s)),
189199
]
190200

191201
# These are the changes that need to be made for characters that occur
@@ -427,7 +437,7 @@ def hasRawText(self, text):
427437
True
428438
429439
"""
430-
r = re.compile(r'<(p|blockquote|div|form|table|ul|ol|dl|pre|h\d)[^>]*?>.*</\1>',
440+
r = re.compile(r'<(pre|p|blockquote|div|form|table|ul|ol|dl|h[1-6])[^>]*?>.*</\1>',
431441
re.S).sub('', text.strip()).strip()
432442
r = re.compile(r'<(hr|br)[^>]*?/>').sub('', r)
433443
return '' != r

0 commit comments

Comments
 (0)