diff options
Diffstat (limited to 'app/lib/formatter.rb')
-rw-r--r-- | app/lib/formatter.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index d85bbf0e0..bf99701b7 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -39,8 +39,14 @@ class Formatter prepend_reblog = false end + summary = nil raw_content = status.text + if status.title.present? + summary = status.spoiler_text.presence || status.text + raw_content = options[:article_content] ? status.text : summary + end + if options[:inline_poll_options] && status.preloadable_poll raw_content = raw_content + "\n\n" + status.preloadable_poll.options.map { |title| "[ ] #{title}" }.join("\n") end @@ -50,6 +56,7 @@ class Formatter unless status.local? html = reformat(raw_content) html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify] + html = format_article_content(summary, html) if options[:article_content] && summary.present? return html.html_safe # rubocop:disable Rails/OutputSafety end @@ -68,6 +75,7 @@ class Formatter html = html.delete("\n") end + html = format_article_content(summary, html) if options[:article_content] && summary.present? html.html_safe # rubocop:disable Rails/OutputSafety end @@ -77,10 +85,14 @@ class Formatter end def format_article(text) - text = text.gsub(/>[\r\n]+</, "><") + text = text.gsub(/>[\r\n]+</, '><') text.html_safe # rubocop:disable Rails/OutputSafety end + def format_article_content(summary, html) + "<blockquote data-name=\"summary\">#{format_summary(summary, html)}</blockquote>#{html}" + end + def reformat(html, outgoing = false) sanitize(html, Sanitize::Config::MASTODON_STRICT.merge(outgoing: outgoing)) rescue ArgumentError @@ -108,8 +120,12 @@ class Formatter Sanitize.fragment(html, config) end + def format_summary(summary, fallback) + summary&.strip.presence || fallback[/(?:<p>.*?<\/p>)/im].presence || '🗎❓' + end + def format_spoiler(status, **options) - html = encode(status.spoiler_text) + html = encode(status.title.presence || status.spoiler_text) html = encode_custom_emojis(html, status.emojis, options[:autoplay]) html.html_safe # rubocop:disable Rails/OutputSafety end |