Skip to content

Commit

Permalink
Add-convert: options.strictHTMLValidation #1447 #1485
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Jan 8, 2025
1 parent bfe5405 commit c5b22ff
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down
1 change: 1 addition & 0 deletions src/lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
6 changes: 5 additions & 1 deletion src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/options.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
* ======
Expand Down
1 change: 1 addition & 0 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit c5b22ff

Please sign in to comment.