diff --git a/templates/forum/topic.html b/templates/forum/topic.html index 65933ff..9fe0aa3 100755 --- a/templates/forum/topic.html +++ b/templates/forum/topic.html @@ -1154,7 +1154,7 @@ {% if not topic.is_locked %}
{% if topic.author_id == current_user.id or current_user.can_moderate_forum() %} - @@ -1223,7 +1223,7 @@ - {% if reply.is_deleted %} @@ -1301,7 +1301,7 @@ {% if not topic.is_locked %}
{% if reply.author_id == current_user.id %} - @@ -1310,7 +1310,7 @@ Usuń {% endif %} - diff --git a/utils/markdown.py b/utils/markdown.py index f6dd02e..7ee67ba 100644 --- a/utils/markdown.py +++ b/utils/markdown.py @@ -7,16 +7,37 @@ Supports: bold, italic, code, links, auto-links, lists, quotes, @mentions """ import re +import urllib.parse from markupsafe import Markup, escape +def _link_display(url): + """Shorten a URL to a human-friendly label while keeping the full href. + + Google Maps URLs are especially unreadable — a single place link can be + 800 characters of tracking data. Extract the place name (or coordinates) + and render it as `📍 Name` instead. + """ + if 'google.' in url and '/maps/' in url: + m = re.search(r'/maps/place/([^/@?]+)', url) + if m: + name = urllib.parse.unquote(m.group(1)).replace('+', ' ').strip() + if name: + return f'📍 {name}' + m = re.search(r'@(-?\d+\.\d+),(-?\d+\.\d+)', url) + if m: + return f'📍 Mapa ({m.group(1)}, {m.group(2)})' + return '📍 Google Maps' + return url + + def _autolink(text): """Convert bare URLs to clickable links. Works on escaped text before HTML wrapping.""" - return re.sub( - r'https?://[^\s<]+', - lambda m: f'{m.group(0)}', - text - ) + def wrap(m): + url = m.group(0) + display = _link_display(url) + return f'{display}' + return re.sub(r'https?://[^\s<]+', wrap, text) def parse_forum_markdown(text, current_user_name=None): @@ -77,12 +98,14 @@ def parse_forum_markdown(text, current_user_name=None): text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', safe_link, text) - # Auto-link bare URLs (after [text](url) to avoid doubling) - text = re.sub( - r'(?)https?://[^\s<]+', - lambda m: f'{m.group(0)}', - text - ) + # Auto-link bare URLs (after [text](url) to avoid doubling). + # Beautify Google Maps URLs via _link_display so the visible label is + # a pin + place name instead of an 800-char tracking URL. + def _wrap_autolink(m): + url = m.group(0) + display = _link_display(url) + return f'{display}' + text = re.sub(r'(?)https?://[^\s<]+', _wrap_autolink, text) # @mentions - highlight them; mark self-mentions with extra class self_variants = set() @@ -95,7 +118,10 @@ def parse_forum_markdown(text, current_user_name=None): cls = 'forum-mention forum-mention-self' if handle in self_variants else 'forum-mention' return f'@{m.group(1)}' - text = re.sub(r'@([\w.\-]+)', _render_mention, text) + # Mentions must start with a letter and not be preceded by `/` or another + # word char — this prevents matching `@54.123` from Google Maps URLs or + # `email@host` style strings that happen to land in plaintext. + text = re.sub(r'(?