]> git.openstreetmap.org Git - rails.git/blob - config/initializers/sanitize.rb
Merge remote-tracking branch 'upstream/pull/5387'
[rails.git] / config / initializers / sanitize.rb
1 Sanitize::Config::OSM = Sanitize::Config.merge(
2   Sanitize::Config::RELAXED,
3   :elements => Sanitize::Config::RELAXED[:elements] - %w[div style],
4   :remove_contents => %w[script style],
5   :transformers => lambda do |env|
6     style = env[:node]["style"] || ""
7
8     env[:node].remove_class
9     env[:node].remove_attribute("style")
10
11     env[:node].add_class("table table-sm w-auto") if env[:node_name] == "table"
12
13     case style
14     when /\btext-align:\s+left\b/
15       env[:node].add_class("text-start")
16     when /\btext-align:\s+center\b/
17       env[:node].add_class("text-center")
18     when /\btext-align:\s+right\b/
19       env[:node].add_class("text-end")
20     end
21
22     if env[:node_name] == "a"
23       rel = env[:node]["rel"] || ""
24
25       env[:node]["rel"] = rel.split.select { |r| r == "me" }.append("nofollow", "noopener", "noreferrer").sort.join(" ")
26     end
27   end
28 )