Skip to content

Commit

Permalink
Support non-http schemas in url refs
Browse files Browse the repository at this point in the history
These url schemes were already valid for inline linking. This adds
the ability to use them as url references as well.
  • Loading branch information
alts committed Mar 5, 2021
1 parent 23e7746 commit c6f9c5d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tests/test_getRefs.py
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
10 changes: 8 additions & 2 deletions textile/core.py
Expand Up @@ -612,8 +612,14 @@ 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)
all_schemes = '|'.join([
'(?:{0})'.format(scheme)
for scheme in self.url_schemes
])
pattern = re.compile(
r'(?:(?<=^)|(?<=\s))\[(.+)\]((?:{0}:\/\/|\/)\S+)(?=\s|$)'.format(all_schemes),
re.U
)
text = pattern.sub(self.refs, text)
return text

Expand Down

0 comments on commit c6f9c5d

Please sign in to comment.