Skip to content

Commit

Permalink
Merge 6b787c9 into 23e7746
Browse files Browse the repository at this point in the history
  • Loading branch information
alts committed Mar 7, 2021
2 parents 23e7746 + 6b787c9 commit 3ddf5b6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 10 additions & 0 deletions tests/test_getRefs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,13 @@ def test_getRefs():
result = t.urlrefs
expect = {'Google': 'http://www.google.com'}
assert result == expect

t2 = Textile()

result = t2.getRefs("my ftp [ftp]ftp://example.com")
expect = 'my ftp '
assert result == expect

result = t2.urlrefs
expect = {'ftp': 'ftp://example.com'}
assert result == expect
14 changes: 10 additions & 4 deletions textile/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,15 @@ def __init__(self, restricted=False, lite=False, noimage=False,
else:
self.url_schemes = self.unrestricted_url_schemes

all_schemes_re_s = '|'.join([
'(?:{0})'.format(scheme)
for scheme in self.url_schemes
])
self.url_ref_regex = re.compile(
r'(?:(?<=^)|(?<=\s))\[(.+)\]\s?((?:{0}:\/\/|\/)\S+)(?=\s|$)'.format(all_schemes_re_s),
re.U
)

def parse(self, text, rel=None, sanitize=False):
"""Parse the input text as textile and return html output."""
self.notes = OrderedDict()
Expand Down Expand Up @@ -612,10 +621,7 @@ def glyphs(self, text):

def getRefs(self, text):
"""Capture and store URL references in self.urlrefs."""
pattern = re.compile(r'(?:(?<=^)|(?<=\s))\[(.+)\]((?:http(?:s?):\/\/|\/)\S+)(?=\s|$)',
re.U)
text = pattern.sub(self.refs, text)
return text
return self.url_ref_regex.sub(self.refs, text)

def refs(self, match):
flag, url = match.groups()
Expand Down

0 comments on commit 3ddf5b6

Please sign in to comment.