about summary refs log tree commit diff
path: root/app/lib/formatter.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/formatter.rb')
-rw-r--r--app/lib/formatter.rb17
1 files changed, 16 insertions, 1 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 3565611bc..ccdef0382 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -14,7 +14,15 @@ class Formatter
 
     html = status.text
     html = encode(html)
-    html = simple_format(html, sanitize: false)
+
+    if (status.spoiler?)
+      spoilerhtml = status.spoiler_text
+      spoilerhtml = encode(spoilerhtml)
+      html = wrap_spoilers(html, spoilerhtml)
+    else
+      html = simple_format(html, sanitize: false)
+    end
+
     html = html.gsub(/\n/, '')
     html = link_urls(html)
     html = link_mentions(html, status.mentions)
@@ -43,6 +51,13 @@ class Formatter
     HTMLEntities.new.encode(html)
   end
 
+  def wrap_spoilers(html, spoilerhtml)
+    spoilerhtml = simple_format(spoilerhtml, {class: "spoiler-helper"}, {sanitize: false})
+    html = simple_format(html, {class: ["spoiler", "spoiler-on"]}, {sanitize: false})
+
+    spoilerhtml + html
+  end
+
   def link_urls(html)
     html.gsub(URI.regexp(%w(http https))) do |match|
       link_html(match)