Skip to content

Commit c6f9c5d

Browse files
committed
Support non-http schemas in url refs
These url schemes were already valid for inline linking. This adds the ability to use them as url references as well.
1 parent 23e7746 commit c6f9c5d

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

tests/test_getRefs.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,13 @@ def test_getRefs():
99
result = t.urlrefs
1010
expect = {'Google': 'http://www.google.com'}
1111
assert result == expect
12+
13+
t2 = Textile()
14+
15+
result = t2.getRefs("my ftp [ftp]ftp://example.com")
16+
expect = 'my ftp '
17+
assert result == expect
18+
19+
result = t2.urlrefs
20+
expect = {'ftp': 'ftp://example.com'}
21+
assert result == expect

textile/core.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -612,8 +612,14 @@ def glyphs(self, text):
612612

613613
def getRefs(self, text):
614614
"""Capture and store URL references in self.urlrefs."""
615-
pattern = re.compile(r'(?:(?<=^)|(?<=\s))\[(.+)\]((?:http(?:s?):\/\/|\/)\S+)(?=\s|$)',
616-
re.U)
615+
all_schemes = '|'.join([
616+
'(?:{0})'.format(scheme)
617+
for scheme in self.url_schemes
618+
])
619+
pattern = re.compile(
620+
r'(?:(?<=^)|(?<=\s))\[(.+)\]((?:{0}:\/\/|\/)\S+)(?=\s|$)'.format(all_schemes),
621+
re.U
622+
)
617623
text = pattern.sub(self.refs, text)
618624
return text
619625

0 commit comments

Comments
 (0)