From bf0f6eb62d0f5bd1f0d8e4e2a6e9e8fd3b297b6c Mon Sep 17 00:00:00 2001 From: blackle Date: Thu, 12 Jan 2017 23:54:26 -0500 Subject: Implement a click-to-view spoiler system --- app/lib/formatter.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'app/lib') 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) -- cgit