Skip to content

Commit

Permalink
Allows inserting custom tags and attributes (#925)
Browse files Browse the repository at this point in the history
Fixes #901

---------

Co-authored-by: Sam <[email protected]>
  • Loading branch information
codertushar and samclarke authored Feb 20, 2023
1 parent 91c3c61 commit 8172419
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/lib/SCEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,9 +424,13 @@ export default function SCEditor(original, userOptions) {
* @private
*/
function sanitize(html) {
const allowedTags = ['iframe'].concat(options.allowedTags);
const allowedAttrs = ['allowfullscreen', 'frameborder', 'target']
.concat(options.allowedAttributes);

return domPurify.sanitize(html, {
ADD_TAGS: ['iframe'],
ADD_ATTR: ['allowfullscreen', 'frameborder', 'target']
ADD_TAGS: allowedTags,
ADD_ATTR: allowedAttrs
});
};

Expand Down
27 changes: 26 additions & 1 deletion src/lib/defaultOptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,5 +370,30 @@ export default {
*
* @type {Object}
*/
dropDownCss: { }
dropDownCss: { },

/**
* An array of tags that are allowed in the editor content.
* If a tag is not listed here, it will be removed when the content is
* sanitized.
*
* 1 Tag is already added by default: ['iframe']. No need to add this
* further.
*
* @type {Array}
*/
allowedTags: [],

/**
* An array of attributes that are allowed on tags in the editor content.
* If an attribute is not listed here, it will be removed when the content
* is sanitized.
*
* 3 Attributes are already added by default:
* ['allowfullscreen', 'frameborder', 'target'].
* No need to add these further.
*
* @type {Array}
*/
allowedAttributes: []
};

0 comments on commit 8172419

Please sign in to comment.