Repository navigation
Expand file tree
/
Copy pathplugin.rb
More file actions
65 lines (52 loc) · 2.19 KB
/
Copy pathplugin.rb
File metadata and controls
65 lines (52 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# frozen_string_literal: true
# name: bbcode
# about: RpN BBCode Parser Plugin
# version: 0.0.1
# authors: RpNation
# url: https://github.com/RpNation/bbcode
# required_version: 2.7.0
enabled_site_setting :bbcode_enabled
register_asset "bundled/bbcode-parser.min.js", :vendored_pretty_text
register_asset "bundled/bbcode-parser.min.js"
register_asset "bundled/bbcode-parser.min.js.map"
register_asset "stylesheets/common/index.scss"
add_admin_route "bbcode.title", "bbcode", use_new_show_route: true
Discourse::Application.routes.append do
get "/admin/plugins/bbcode/reset" => "admin/plugins#index", :constraints => AdminConstraint.new
end
module ::BbCode
PLUGIN_NAME = "BbCode"
ENGINE_RESET_CHANNEL = "/bbcode/engine-reset"
end
require_relative "lib/bb_code/engine"
require_relative "lib/bb_code/css_hotlinked_media"
after_initialize do
# Code which should run after Rails has finished booting
# should clear out the context so the initial setup logic for bbcode parser runs
PrettyText.reset_context()
unless Rails.env.test?
MessageBus.subscribe(::BbCode::ENGINE_RESET_CHANNEL) { PrettyText.reset_context }
end
::HotlinkedMedia.singleton_class.prepend(::BbCode::CssHotlinkedMedia::ExtendExtractCandidates)
::InlineUploads.singleton_class.prepend(::BbCode::CssHotlinkedMedia::RewriteRawCssUrls)
on(:post_process_cooked) { |doc, post| ::BbCode::CssHotlinkedMedia.rewrite_doc!(doc, post) }
# overrides the default normalize_whitespaces function in discourse/lib/text_cleaner.rb
# adds discourse_normalize_whitespace setting (defaults to false)
# when true, normalize_whitespace runs as normal
# when false, it does nothing, which allows for persistence of non-default whitespace.
class ::TextCleaner # rubocop:disable Discourse/Plugins/NoMonkeyPatching
module Optional_normalize_whitespace
def title_options
options = super
options[:normalize_whitespace_opt] = SiteSetting.discourse_normalize_whitespace
options
end
def normalize_whitespaces(text)
options = title_options
text = super(text) if (options[:normalize_whitespace_opt])
text
end
end
singleton_class.prepend Optional_normalize_whitespace
end
end