diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-10-12 20:52:09 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-10-12 20:52:09 -0500 |
commit | 249d70d13c10b85fefd29ce1b7e0581c6bd3a147 (patch) | |
tree | c7c3ad6f04e92e5b95dd7c1a5cda46ec503e3e8f | |
parent | d4383994fc8c1ae62d7f6d5fe0eca88b03cadfe9 (diff) |
when somone's posting in html mode, convert newlines to html line breaks (resolves #12)
-rw-r--r-- | app/lib/formatter.rb | 12 |
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) |