diff options
author | Darius Kazemi <darius.kazemi@gmail.com> | 2019-04-30 15:29:28 -0700 |
---|---|---|
committer | Fire Demon <firedemon@creature.cafe> | 2020-08-30 05:45:15 -0500 |
commit | 6378feffa8935238bdb5f1f1c01fcb102440fe30 (patch) | |
tree | b1eea210ace7eb72a00ab4604c3ec10c5ae4db4b /app/lib/formatter.rb | |
parent | 4eb49257fc618219709b357fb68f4d6156cab249 (diff) |
[Feature, Federation, Port: hometown@b3e6597] Support locally cached inline images [+ Monsterfork additions]
Changes added by Monsterfork: - Do not limit to only Articles - Reuse existing media; retroactively using more-detailed descriptions - Also scrub carrige returns between tags - Handle download failures - Attach to statuses and keep track of inlined media - Handle local edits Co-authored-by: Fire Demon <firedemon@creature.cafe>
Diffstat (limited to 'app/lib/formatter.rb')
-rw-r--r-- | app/lib/formatter.rb | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index d5408a30b..39c42c8db 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -24,6 +24,7 @@ class HTMLRenderer < Redcarpet::Render::HTML end end +# rubocop:disable Metrics/ClassLength class Formatter include Singleton include RoutingHelper @@ -75,6 +76,11 @@ class Formatter html.delete("\r").delete("\n") end + def format_article(text) + text = text.gsub(/>[\r\n]+</, "><") + text.html_safe # rubocop:disable Rails/OutputSafety + end + def reformat(html, outgoing = false) sanitize(html, Sanitize::Config::MASTODON_STRICT.merge(outgoing: outgoing)) rescue ArgumentError @@ -154,7 +160,7 @@ class Formatter renderer = HTMLRenderer.new({ filter_html: false, escape_html: false, - no_images: true, + no_images: false, no_styles: true, safe_links_only: true, hard_wrap: true, @@ -389,3 +395,4 @@ class Formatter "<span class=\"h-card\"><a href=\"#{encode(ActivityPub::TagManager.instance.url_for(account))}\" class=\"u-url mention\">@<span>#{encode(account.username)}</span></a></span>" end end +# rubocop:enable Metrics/ClassLength |