about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThibaut Girka <thib@sitedethib.com>2019-05-26 15:10:33 +0200
committerThibG <thib@sitedethib.com>2019-05-28 19:33:43 +0200
commit18b77224d3ce4ac6aa14278ca2dca34efb0956f5 (patch)
tree3ac174843ab17713b184a6a39e5abede9f6172c4
parent2f83ffa1bd1a80567c512db79273dc75d32ef069 (diff)
Translate incoming remote img tags by a link
-rw-r--r--app/lib/sanitize_config.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb
index 75c916485..a9a2351a4 100644
--- a/app/lib/sanitize_config.rb
+++ b/app/lib/sanitize_config.rb
@@ -19,6 +19,17 @@ class Sanitize
       node['class'] = class_list.join(' ')
     end
 
+    IMG_TAG_TRANSFORMER = lambda do |env|
+      node = env[:node]
+
+      return unless env[:node_name] == 'img'
+
+      node.name = 'a'
+
+      node['href'] = node['src']
+      node.content = "[🖼 #{node['alt'] || node['href']}]"
+    end
+
     MASTODON_STRICT ||= freeze_config(
       elements: %w(p br span a abbr del pre blockquote code b strong u sub i em h1 h2 h3 h4 h5 ul ol li),
 
@@ -43,6 +54,7 @@ class Sanitize
 
       transformers: [
         CLASS_WHITELIST_TRANSFORMER,
+        IMG_TAG_TRANSFORMER,
       ]
     )