From 249d70d13c10b85fefd29ce1b7e0581c6bd3a147 Mon Sep 17 00:00:00 2001 From: multiple creatures Date: Sat, 12 Oct 2019 20:52:09 -0500 Subject: when somone's posting in html mode, convert newlines to html line breaks (resolves #12) --- app/lib/formatter.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'app/lib') diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index e21ff07d0..9c3733ca1 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -237,7 +237,9 @@ class Formatter html = encode_custom_emojis(html, status.emojis, options[:autoplay]) if options[:custom_emojify] if %w(text/markdown text/x-bbcode text/x-bbcode+markdown text/html).include?(status.content_type) - html = reformat(html) + is_html = status.content_type == 'text/html' + html = reformat(html, strip_newlines: !is_html) + html.gsub!("\n", '
') if is_html else html = simple_format(html, {}, sanitize: false) html = html.delete("\n") @@ -280,8 +282,12 @@ class Formatter format_markdown(html) end - def reformat(html) - sanitize(html, Sanitize::Config::MASTODON_STRICT).delete("\r").delete("\n") + def reformat(html, strip_newlines: true) + html = sanitize(html, Sanitize::Config::MASTODON_STRICT) + return html.delete("\r").delete("\n") if strip_newlines + html.gsub!("\r\n", "\n") + html.gsub!("\n\r", "\n") + html.gsub("\r", "\n") end def plaintext(status) -- cgit