Implement a click-to-view spoiler system

This commit is contained in:
blackle
2017-01-12 23:54:26 -05:00
parent 1761d3f9c3
commit bf0f6eb62d
18 changed files with 192 additions and 77 deletions

View File

@ -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)