discourse/plugins/spoiler-alert/plugin.rb
Blake Erickson 89580ee379
FEATURE: Bundle discourse-spoiler-alert plugin into core (#24030)
* FEATURE: Bundle discourse-spoiler-alert plugin into core

Formerly https://github.com/discourse/discourse-spoiler-alert

* DEV: Switch to new addComposerToolbarPopupMenuOption plugin API

`api.addToolbarPopupMenuOptionsCallback` has been deprecated in 913fd3a7b3

This commit was just added to the plugin, so adding it here.

49f86ba72e
2023-10-23 13:50:43 -06:00

29 lines
792 B
Ruby

# frozen_string_literal: true
# name: spoiler-alert
# about: Uses the Spoiler Alert plugin to blur text when spoiling it.
# version: 1.1.0
# authors: Discourse Team
# url: https://github.com/discourse/discourse/tree/main/plugins/spoiler-alert
# transpile_js: true
enabled_site_setting :spoiler_enabled
register_asset "stylesheets/discourse_spoiler_alert.scss"
after_initialize do
on(:reduce_cooked) do |fragment, post|
fragment
.css(".spoiler")
.each do |el|
link = fragment.document.create_element("a")
link["href"] = post.url
link.content = I18n.t("spoiler_alert.excerpt_spoiler")
el.inner_html = link.to_html
end
end
# Remove spoilers from topic excerpts
on(:reduce_excerpt) { |doc, post| doc.css(".spoiler").remove }
end