diff options
author | Reverite <github@reverite.sh> | 2019-06-01 22:29:46 -0700 |
---|---|---|
committer | Reverite <github@reverite.sh> | 2019-06-01 22:29:46 -0700 |
commit | 846a09a7435fb9eb435e9950175ee0e696ed4909 (patch) | |
tree | 9f63c888a5c380d17e1c75ad339a8ca0d689717e /app/lib | |
parent | fdca8d63efe06675ca890358547fcbe7a42631f0 (diff) | |
parent | 17fb1c4345348da5a6f9338912824a03d348841f (diff) |
Merge branch 'glitch' into production
Diffstat (limited to 'app/lib')
-rw-r--r-- | app/lib/sanitize_config.rb | 20 | ||||
-rw-r--r-- | app/lib/user_settings_decorator.rb | 5 |
2 files changed, 25 insertions, 0 deletions
diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index 75c916485..e6e861eb9 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -19,6 +19,25 @@ 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'] + if node['alt'].present? + node.content = "[🖼 #{node['alt']}]" + else + url = node['href'] + prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s + text = url[prefix.length, 30] + text = text + "…" if url[prefix.length..-1].length > 30 + node.content = "[🖼 #{text}]" + end + 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 +62,7 @@ class Sanitize transformers: [ CLASS_WHITELIST_TRANSFORMER, + IMG_TAG_TRANSFORMER, ] ) diff --git a/app/lib/user_settings_decorator.rb b/app/lib/user_settings_decorator.rb index 802ca71fe..a95d09c5c 100644 --- a/app/lib/user_settings_decorator.rb +++ b/app/lib/user_settings_decorator.rb @@ -36,6 +36,7 @@ class UserSettingsDecorator user.settings['hide_network'] = hide_network_preference if change?('setting_hide_network') user.settings['aggregate_reblogs'] = aggregate_reblogs_preference if change?('setting_aggregate_reblogs') user.settings['show_application'] = show_application_preference if change?('setting_show_application') + user.settings['advanced_layout'] = advanced_layout_preference if change?('setting_advanced_layout') user.settings['default_content_type']= default_content_type_preference if change?('setting_default_content_type') end @@ -123,6 +124,10 @@ class UserSettingsDecorator boolean_cast_setting 'setting_aggregate_reblogs' end + def advanced_layout_preference + boolean_cast_setting 'setting_advanced_layout' + end + def default_content_type_preference settings['setting_default_content_type'] end |