Skip to content

Commit 2f1d2fe

Browse files
committed
Allow complex htmlSupport rules
1 parent 127fee5 commit 2f1d2fe

2 files changed

Lines changed: 32 additions & 7 deletions

File tree

frontend/src/modules/scaffold/backboneFormsOverrides.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@ define([
8484
};
8585
}
8686

87+
function convertStringsToRegExDeep (arr) {
88+
function processEntry ([key, value]) {
89+
if (typeof value === "string") {
90+
return [
91+
key,
92+
new RegExp(value, 'i')
93+
];
94+
}
95+
if (Array.isArray(value)) {
96+
return [
97+
key,
98+
arr.map((value, index) => processEntry([index, value])[1])
99+
];
100+
}
101+
if (typeof value === "object" && value !== null) {
102+
return [
103+
key,
104+
Object.fromEntries(Object.entries(value).map(processEntry))
105+
];
106+
}
107+
return [key, value];
108+
}
109+
return arr.map((value, index) => processEntry([index, value])[1])
110+
}
111+
87112
until(isAttached(this.$el)).then(() => {
88113
return CKEDITOR.create(this.$el[0], {
89114
dataIndentationChars: '',
@@ -92,10 +117,8 @@ define([
92117
entities: false,
93118
htmlSupport: {
94119
// Convert all allow/disallow values to regexp, as config is json only
95-
allow: ((Origin.constants.ckEditorHtmlSupport && Origin.constants.ckEditorHtmlSupport.allow) || [])
96-
.map(obj => Object.fromEntries(Object.entries(obj).map(([name, value]) => ([name, new RegExp(value)])))),
97-
disallow: ((Origin.constants.ckEditorHtmlSupport && Origin.constants.ckEditorHtmlSupport.disallow) || [])
98-
.map(obj => Object.fromEntries(Object.entries(obj).map(([name, value]) => ([name, new RegExp(value)]))))
120+
allow: convertStringsToRegExDeep((Origin.constants.ckEditorHtmlSupport && Origin.constants.ckEditorHtmlSupport.allow) || []),
121+
disallow: convertStringsToRegExDeep((Origin.constants.ckEditorHtmlSupport && Origin.constants.ckEditorHtmlSupport.disallow) || [])
99122
},
100123
on: {
101124
change: function() {

lib/configuration.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,13 @@ function Configuration() {
8686
name: "^(blockquote|ul|ol|span)$"
8787
},{
8888
name: ".*",
89-
classes: ".*",
90-
styles: ".*"
89+
classes: true,
90+
styles: true
9191
},{
9292
name: "^a$",
93-
attributes: "^target$"
93+
attributes: {
94+
target: true
95+
}
9496
}]
9597
},
9698
maxFileUploadSize: '200MB',

0 commit comments

Comments
 (0)