about summary refs log tree commit diff
path: root/app/lib/formatter.rb
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-10-12 20:52:09 -0500
committermultiple creatures <dev@multiple-creature.party>2019-10-12 20:52:09 -0500
commit249d70d13c10b85fefd29ce1b7e0581c6bd3a147 (patch)
treec7c3ad6f04e92e5b95dd7c1a5cda46ec503e3e8f /app/lib/formatter.rb
parentd4383994fc8c1ae62d7f6d5fe0eca88b03cadfe9 (diff)
when somone's posting in html mode, convert newlines to html line breaks (resolves #12)
Diffstat (limited to 'app/lib/formatter.rb')
-rw-r--r--app/lib/formatter.rb12
1 files changed, 9 insertions, 3 deletions
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", '<br>') 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)