Skip to content

Commit a1fdd65

Browse files
authored
Enables CKeditior html elements (#2780)
2 parents 412b450 + 3a21ebb commit a1fdd65

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

frontend/src/modules/scaffold/backboneFormsOverrides.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,31 @@ define([
8484
};
8585
}
8686

87+
function convertStringsToRegExDeep (arr) {
88+
function processEntry ([key, value]) {
89+
value = (typeof value === "string")
90+
? new RegExp(value, 'i')
91+
: Array.isArray(value)
92+
? arr.map((value, index) => processEntry([index, value])[1])
93+
: (typeof value === "object" && value !== null)
94+
? Object.fromEntries(Object.entries(value).map(processEntry))
95+
: value;
96+
return [key, value];
97+
}
98+
return arr.map((value, index) => processEntry([index, value])[1])
99+
}
100+
87101
until(isAttached(this.$el)).then(() => {
88102
return CKEDITOR.create(this.$el[0], {
89103
dataIndentationChars: '',
90104
disableNativeSpellChecker: false,
91105
enterMode: CKEDITOR[Origin.constants.ckEditorEnterMode],
92106
entities: false,
93-
extraAllowedContent: Origin.constants.ckEditorExtraAllowedContent,
107+
htmlSupport: {
108+
// Convert all allow/disallow strings to regexp, as config is json only
109+
allow: convertStringsToRegExDeep((Origin.constants.ckEditorHtmlSupport && Origin.constants.ckEditorHtmlSupport.allow) || []),
110+
disallow: convertStringsToRegExDeep((Origin.constants.ckEditorHtmlSupport && Origin.constants.ckEditorHtmlSupport.disallow) || [])
111+
},
94112
on: {
95113
change: function() {
96114
this.trigger('change', this);

lib/configuration.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ var ALLOWED_CLIENT_SIDE_KEYS = [
3232
'useSmtp',
3333
'isProduction',
3434
'maxLoginAttempts',
35-
'ckEditorExtraAllowedContent',
35+
'ckEditorHtmlSupport',
3636
'ckEditorEnterMode',
3737
'maxFileUploadSize',
3838
'supportLink',
@@ -81,7 +81,20 @@ function Configuration() {
8181
this.conf = {
8282
root: this.serverRoot,
8383
maxLoginAttempts: 3,
84-
ckEditorExtraAllowedContent: 'span(*)',
84+
ckEditorHtmlSupport: {
85+
allow: [{
86+
name: "^(blockquote|ul|ol|span)$"
87+
},{
88+
name: ".*",
89+
classes: true,
90+
styles: true
91+
},{
92+
name: "^a$",
93+
attributes: {
94+
target: true
95+
}
96+
}]
97+
},
8598
maxFileUploadSize: '200MB',
8699
ckEditorEnterMode: 'ENTER_P'
87100
};

routes/index/index.hbs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
Code,
7171
Essentials,
7272
FindAndReplace,
73+
GeneralHtmlSupport,
7374
Font,
7475
Highlight,
7576
Indent,
@@ -115,6 +116,7 @@
115116
Code,
116117
Essentials,
117118
FindAndReplace,
119+
GeneralHtmlSupport,
118120
Font,
119121
Highlight,
120122
Indent,

0 commit comments

Comments
 (0)