diff --git a/README.md b/README.md index f77eb2f9..ac0d7614 100644 --- a/README.md +++ b/README.md @@ -392,6 +392,7 @@ plugins: [ // Values strictMode : Option to disable clean mode, which checks the styles, classes, etc. of the editor content. default : false {Boolean} +strictHTMLValidation : Enforces strict HTML validation based on the editor`s policy. Applies to methods like setContents to ensure content compliance when enabled. default: false {Boolean} lang : language object. default : en {Object} defaultTag : Specifies default tag name of the editor. default: 'p' {String} textTags : You can change the tag of the default text button. default: { bold: 'STRONG', underline: 'U', italic: 'EM', strike: 'DEL' } diff --git a/src/lib/constructor.js b/src/lib/constructor.js index 323c39c9..d1a39f97 100755 --- a/src/lib/constructor.js +++ b/src/lib/constructor.js @@ -416,6 +416,7 @@ export default { options.plugins = plugins; /** Values */ options.strictMode = options.strictMode !== false; + options.strictHTMLValidation = options.strictHTMLValidation === true; options.lang = options.lang || _defaultLang; options.value = typeof options.value === 'string' ? options.value : null; options.allowedClassNames = new util._w.RegExp((options.allowedClassNames && typeof options.allowedClassNames === 'string' ? options.allowedClassNames + '|' : '') + '^__se__|se-|katex'); diff --git a/src/lib/core.js b/src/lib/core.js index 0eab5e8e..1bc47cd6 100755 --- a/src/lib/core.js +++ b/src/lib/core.js @@ -5543,7 +5543,11 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re const dom = _d.createRange().createContextualFragment(contents); try { - util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, this._htmlCheckBlacklistRegExp, this._classNameFilter); + if (this.options.strictHTMLValidation) { + util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, this._htmlCheckBlacklistRegExp, this._classNameFilter); + } else { + util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, false); + } } catch (error) { console.warn('[SUNEDITOR.convertContentsForEditor.consistencyCheck.fail] ' + error); } diff --git a/src/options.d.ts b/src/options.d.ts index 808a2b2a..f5f663f6 100644 --- a/src/options.d.ts +++ b/src/options.d.ts @@ -7,6 +7,10 @@ export interface SunEditorOptions { * Option to disable clean mode, which checks the styles, classes, etc. of the editor content */ strictMode?: boolean; + /** + * Enforces strict HTML validation based on the editor`s policy. Applies to methods like setContents to ensure content compliance when enabled. + */ + strictHTMLValidation?: boolean; /** * Values * ====== diff --git a/test/dev/suneditor_build_test.js b/test/dev/suneditor_build_test.js index 481af51f..0ac7c3cf 100644 --- a/test/dev/suneditor_build_test.js +++ b/test/dev/suneditor_build_test.js @@ -989,6 +989,7 @@ let s2 = window.s2 = suneditor.create(document.getElementById('editor2'), { // `, // imageUploadUrl: 'http://localhost:3000/editor/upload', // strictMode: false, + // strictHTMLValidation: true, allowedClassNames: '.', width: '100%', // fontSizeUnit: 'em',