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 :attributes => Sanitize::Config.merge(
6 Sanitize::Config::RELAXED[:attributes],
7 "img" => Sanitize::Config::RELAXED[:attributes]["img"] + ["loading"]
9 :transformers => lambda do |env|
10 style = env[:node]["style"] || ""
12 env[:node].remove_class
13 env[:node].remove_attribute("style")
15 env[:node].add_class("table table-sm w-auto") if env[:node_name] == "table"
18 when /\btext-align:\s+left\b/
19 env[:node].add_class("text-start")
20 when /\btext-align:\s+center\b/
21 env[:node].add_class("text-center")
22 when /\btext-align:\s+right\b/
23 env[:node].add_class("text-end")
26 if env[:node_name] == "a"
27 rel = env[:node]["rel"] || ""
29 env[:node]["rel"] = rel.split.select { |r| r == "me" }.append("nofollow", "noopener", "noreferrer").sort.join(" ")
32 env[:node]["loading"] = "lazy" if env[:node_name] == "img"