mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 19:41:11 +00:00
Check for punctuation before checking for wrapping parenthesis
This allows to parse `(URL).` correctly, which was not detected as URL before.
This commit is contained in:
parent
3d123bc2f2
commit
c3c22022f6
2 changed files with 16 additions and 5 deletions
|
@ -436,6 +436,15 @@ http://www.fish.com/"""
|
|||
f'<a href="{url}">www.fish.com/</a>.',
|
||||
)
|
||||
|
||||
def test_format_links_punctuation_parens(self, *_):
|
||||
"""ignore trailing punctuation and brackets combined"""
|
||||
# Period at the end, wrapped in brackets.
|
||||
url = "http://www.fish.com"
|
||||
self.assertEqual(
|
||||
views.status.format_links(f"({url})."),
|
||||
f'(<a href="{url}">www.fish.com</a>).',
|
||||
)
|
||||
|
||||
def test_format_links_special_chars(self, *_):
|
||||
"""find and format urls into a tags"""
|
||||
url = "https://archive.org/details/dli.granth.72113/page/n25/mode/2up"
|
||||
|
|
|
@ -304,17 +304,19 @@ def format_links(content):
|
|||
for potential_link in split_content:
|
||||
if not potential_link:
|
||||
continue
|
||||
|
||||
# FIXME: allow for multiple punctuation characters, e.g. `...` and `!?`.
|
||||
ends_with_punctuation = _ends_with_punctuation(potential_link)
|
||||
if ends_with_punctuation:
|
||||
punctuation_glyph = potential_link[-1]
|
||||
potential_link = potential_link[0:-1]
|
||||
|
||||
wrapped = _wrapped(potential_link)
|
||||
if wrapped:
|
||||
wrapper_close = potential_link[-1]
|
||||
formatted_content += potential_link[0]
|
||||
potential_link = potential_link[1:-1]
|
||||
|
||||
ends_with_punctuation = _ends_with_punctuation(potential_link)
|
||||
if ends_with_punctuation:
|
||||
punctuation_glyph = potential_link[-1]
|
||||
potential_link = potential_link[0:-1]
|
||||
|
||||
try:
|
||||
# raises an error on anything that's not a valid link
|
||||
validator(potential_link)
|
||||
|
|
Loading…
Reference in a new issue