[openstreetmap/openstreetmap-website] Add URL prettification for plain texts (PR #6518)

Marwin Hochfelsner notifications at github.com
Wed Nov 12 18:36:30 UTC 2025


@hlfan commented on this pull request.



>        end.html_safe
     end
 
     private
 
+    def expand_link_shorthands(text)
+      linkify_detection_rules = Array.wrap(Settings.linkify&.detection_rules)
+      linkify_detection_rules.each do |rule|
+        next unless rule.path_template && rule.patterns.is_a?(Array)
+
+        rule.patterns.each do |pattern|
+          expanded_path = "#{Settings.server_protocol}://#{rule.host || Settings.server_url}/#{rule.path_template}"
+          text.gsub!(Regexp.new("(?<before>\\s|^|>)#{pattern}(?<after>\\s|$|<)", Regexp::IGNORECASE), "\\k<before>#{expanded_path}\\k<after>")
+        end
+      end
+      [[Settings.linkify_hosts, Settings.linkify_hosts_replacement], [Settings.linkify_wiki_hosts, Settings.linkify_wiki_hosts_replacement]].each do |hosts, replacement|
+        text.gsub!(/(\s)#{Regexp.escape(replacement)}/, "\\1#{Settings.server_protocol}://#{hosts[0]}") if replacement && hosts&.any?
+      end

See https://github.com/openstreetmap/openstreetmap-website/issues/5780#issuecomment-2760413875 and onward for the problem.

By canonical I mean the URL that is the target of the redirects which is on the `www.openstreetmap.org` domain. The path is still canonical on the shortened domains.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6518#discussion_r2519386751
You are receiving this because you are subscribed to this thread.

Message ID: <openstreetmap/openstreetmap-website/pull/6518/review/3454908828 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20251112/ec062bda/attachment-0001.htm>


More information about the rails-dev mailing list