Skip to content

Commit f44241e

Browse files
committed
Added configurable whitelist tags to WYMeditor which fixes refinery#1202
1 parent ab34249 commit f44241e

3 files changed

Lines changed: 17 additions & 12 deletions

File tree

‎core/app/assets/javascripts/wymeditor/jquery.refinery.wymeditor.js.erb‎

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ $.extend(WYMeditor, {
215215
"section", "article", "aside", "details", "header", "footer",
216216
"nav", "dialog", "figure", "figcaption", "address", "hgroup",
217217
"mark", "time", "canvas", "audio", "video", "source", "output",
218-
"progress", "ruby", "rt", "rp", "summary", "command"),
218+
"progress", "ruby", "rt", "rp", "summary", "command"<%= ", #{Refinery::Core.wymeditor_whitelist_tags.keys.map{|k| %Q{"#{k}"}}.join(', ')}" if Refinery::Core.wymeditor_whitelist_tags.any? %>),
219219

220220
KEY : {
221221
BACKSPACE: 8,
@@ -2161,7 +2161,7 @@ WYMeditor.XhtmlValidator = {
21612161
{
21622162
"core":
21632163
{
2164-
"except":[
2164+
"except":<%= [
21652165
"base",
21662166
"head",
21672167
"html",
@@ -2170,7 +2170,7 @@ WYMeditor.XhtmlValidator = {
21702170
"script",
21712171
"style",
21722172
"title"
2173-
],
2173+
].reject{|a| Refinery::Core.wymeditor_whitelist_tags.keys.map(&:to_s).include?(a)}.inspect %>,
21742174
"attributes":[
21752175
"class",
21762176
"id",
@@ -2184,14 +2184,14 @@ WYMeditor.XhtmlValidator = {
21842184
},
21852185
"language":
21862186
{
2187-
"except":[
2187+
"except":<%= [
21882188
"base",
21892189
"br",
21902190
"hr",
21912191
"iframe",
21922192
"param",
21932193
"script"
2194-
],
2194+
].reject{|a| Refinery::Core.wymeditor_whitelist_tags.keys.map(&:to_s).include?(a)}.inspect %>,
21952195
"attributes":
21962196
{
21972197
"dir":[
@@ -2245,7 +2245,7 @@ WYMeditor.XhtmlValidator = {
22452245
},
22462246
"keyboard":
22472247
{
2248-
"except":[
2248+
"except":<%= [
22492249
"base",
22502250
"bdo",
22512251
"br",
@@ -2259,7 +2259,7 @@ WYMeditor.XhtmlValidator = {
22592259
"script",
22602260
"style",
22612261
"title"
2262-
],
2262+
].reject{|a| Refinery::Core.wymeditor_whitelist_tags.keys.map(&:to_s).include?(a)}.inspect %>,
22632263
"attributes":[
22642264
"onkeydown",
22652265
"onkeypress",
@@ -2268,7 +2268,7 @@ WYMeditor.XhtmlValidator = {
22682268
},
22692269
"mouse":
22702270
{
2271-
"except":[
2271+
"except":<%= [
22722272
"base",
22732273
"bdo",
22742274
"br",
@@ -2279,7 +2279,7 @@ WYMeditor.XhtmlValidator = {
22792279
"script",
22802280
"style",
22812281
"title"
2282-
],
2282+
].reject{|a| Refinery::Core.wymeditor_whitelist_tags.keys.map(&:to_s).include?(a)}.inspect %>,
22832283
"attributes":[
22842284
"onclick",
22852285
"ondblclick",
@@ -2800,7 +2800,8 @@ WYMeditor.XhtmlValidator = {
28002800
"62":"rt",
28012801
"63":"rp",
28022802
"64":"summary",
2803-
"65":"command"
2803+
"65":"command"<% Refinery::Core.wymeditor_whitelist_tags.each do |key, value| %>,
2804+
<%= key.inspect %>:<%= value.to_json %><% end %>
28042805
},
28052806

28062807
// Temporary skipped attributes
@@ -3873,7 +3874,7 @@ WYMeditor.XhtmlSaxListener = function()
38733874
"section", "article", "aside", "details", "header", "footer",
38743875
"nav", "dialog", "figure", "figcaption", "address", "hgroup",
38753876
"mark", "time", "canvas", "audio", "video", "source", "output",
3876-
"progress", "ruby", "rt", "rp", "summary", "command"];
3877+
"progress", "ruby", "rt", "rp", "summary", "command"<%= ", #{Refinery::Core.wymeditor_whitelist_tags.keys.map{|k| %Q{"#{k}"}}.join(', ')}" if Refinery::Core.wymeditor_whitelist_tags.any? %>];
38773878

38783879

38793880
// Defines self-closing tags.

‎core/lib/generators/refinery/core/templates/config/initializers/refinery.rb.erb‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ Refinery::Core.configure do |config|
3333

3434
# Show/hide browser update message in the backend
3535
# config.show_internet_explorer_upgrade_message = <%= Refinery::Core.show_internet_explorer_upgrade_message.inspect %>
36+
37+
# Add extra tags to the wymeditor whitelist e.g. = {'tag' => {'attributes': '1': 'href'}} or just {'tag' => {}}
38+
# config.wymeditor_whitelist_tags = <%= Refinery::Core.wymeditor_whitelist_tags.inspect %>
3639
end

‎core/lib/refinery/core/configuration.rb‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Core
55
config_accessor :rescue_not_found, :s3_backend, :base_cache_key, :site_name,
66
:google_analytics_page_code, :authenticity_token_on_frontend,
77
:menu_hide_children, :dragonfly_secret, :ie6_upgrade_message_enabled,
8-
:show_internet_explorer_upgrade_message
8+
:show_internet_explorer_upgrade_message, :wymeditor_whitelist_tags
99

1010
self.rescue_not_found = false
1111
self.s3_backend = false
@@ -17,5 +17,6 @@ module Core
1717
self.dragonfly_secret = Array.new(24) { rand(256) }.pack('C*').unpack('H*').first
1818
self.ie6_upgrade_message_enabled = true
1919
self.show_internet_explorer_upgrade_message = false
20+
self.wymeditor_whitelist_tags = {}
2021
end
2122
end

0 commit comments

Comments
 (0)