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

Marwin Hochfelsner notifications at github.com
Fri Dec 5 01:58:03 UTC 2025


@hlfan commented on this pull request.



>      end
 
     private
 
+    def expand_link_shorthands(text)
+      Array.wrap(Settings.linkify&.detection_rules)
+           .select { |rule| rule.path_template && rule.patterns.is_a?(Array) }
+           .flat_map { |rule| linkify_detection_rule_to_gsub(rule) }
+           .reduce(text) { |text, (pattern, replacement)| text.gsub(pattern, replacement) }
+    end
+
+    def linkify_detection_rule_to_gsub(rule)
+      expanded_path = "#{rule.host || "#{Settings.server_protocol}://#{Settings.server_url}"}/#{rule.path_template}"
+      rule.patterns
+          .select { |pattern| pattern.is_a?(String) }
+          .map do |pattern|
+        [
+          Regexp.new("(?<before>\\s|^|>)#{pattern}(?<after>\\s|$|<)", Regexp::IGNORECASE),

`\b` only matches after the `@` for user links or before the `=*` for key links, which sadly makes it unusable here.
I still tried to make it more easily readable now.

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

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


More information about the rails-dev mailing list