mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-06-03 05:49:35 +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
|
@ -436,6 +436,15 @@ http://www.fish.com/"""
|
||||||
f'<a href="{url}">www.fish.com/</a>.',
|
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, *_):
|
def test_format_links_special_chars(self, *_):
|
||||||
"""find and format urls into a tags"""
|
"""find and format urls into a tags"""
|
||||||
url = "https://archive.org/details/dli.granth.72113/page/n25/mode/2up"
|
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:
|
for potential_link in split_content:
|
||||||
if not potential_link:
|
if not potential_link:
|
||||||
continue
|
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)
|
wrapped = _wrapped(potential_link)
|
||||||
if wrapped:
|
if wrapped:
|
||||||
wrapper_close = potential_link[-1]
|
wrapper_close = potential_link[-1]
|
||||||
formatted_content += potential_link[0]
|
formatted_content += potential_link[0]
|
||||||
potential_link = potential_link[1:-1]
|
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:
|
try:
|
||||||
# raises an error on anything that's not a valid link
|
# raises an error on anything that's not a valid link
|
||||||
validator(potential_link)
|
validator(potential_link)
|
||||||
|
|
Loading…
Reference in a new issue