[openstreetmap/openstreetmap-website] Add URL prettification for plain texts (PR #6518)
Marwin Hochfelsner
notifications at github.com
Sun Nov 16 15:13:42 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
I just stumbled over this again here:
https://www.openstreetmap.org/user_blocks/18933
https://www.openstreetmap.org/user_blocks/18934
The first description has the import guidelines linked.
The second description, which was presumably copied and pasted, doesn't have that link.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6518#discussion_r2532019876
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/pull/6518/review/3470248221 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20251116/f6c66411/attachment.htm>
More information about the rails-dev
mailing list