Skip to content

Commit

Permalink
2.47.2
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 authored Jan 15, 2025
2 parents f54b2b0 + 39b96b1 commit 1f2f738
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 22 deletions.
4 changes: 2 additions & 2 deletions dist/suneditor.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "suneditor",
"version": "2.47.1",
"version": "2.47.2",
"description": "Vanilla javascript based WYSIWYG web editor, with no dependencies",
"author": "JiHong.Lee",
"license": "MIT",
Expand Down
4 changes: 2 additions & 2 deletions sample/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
<div style="background-color: #f3f3f3; padding: 4px 20px 20px 20px;">
<h4 style="color: #b94a48;">--Value</h4>
<label><input type="checkbox" id="strictMode" checked>&nbsp;&nbsp;strictMode&nbsp;&nbsp;&nbsp;</label><br><br>
<label><input type="checkbox" id="strictHTMLValidation">&nbsp;&nbsp;strictHTMLValidation&nbsp;&nbsp;&nbsp;</label><br><br>
<label><input type="checkbox" id="strictHTMLValidation" checked>&nbsp;&nbsp;strictHTMLValidation&nbsp;&nbsp;&nbsp;</label><br><br>
<label><input type="checkbox" id="defaultTag">&nbsp;&nbsp;defaultTag&nbsp;&nbsp;&nbsp;</label>
<input type="text" id="defaultTag_value" placeholder="String ('p', 'div'..)"></input>
<br><br>
Expand Down Expand Up @@ -635,7 +635,7 @@ <h2 class="sub-title">Applied options</h2>

var options = {
strictMode: document.getElementById('strictMode').checked ? undefined : false,
strictHTMLValidation: document.getElementById('strictHTMLValidation').checked ? true : undefined,
strictHTMLValidation: document.getElementById('strictHTMLValidation').checked ? undefined : false,
defaultTag: document.getElementById('defaultTag').checked ? document.getElementById('defaultTag_value').value : undefined,
textTags: document.getElementById('textTags').checked ? {
bold: 'b',
Expand Down
2 changes: 1 addition & 1 deletion src/lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ export default {
options.plugins = plugins;
/** Values */
options.strictMode = options.strictMode !== false;
options.strictHTMLValidation = options.strictHTMLValidation === true;
options.strictHTMLValidation = options.strictHTMLValidation !== false;
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
13 changes: 5 additions & 8 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5480,12 +5480,12 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
* @returns {String}
*/
cleanHTML: function (html, whitelist, blacklist) {
if (!options.strictMode) return html;
if (!options.strictMode) return util.htmlCompress(html);

html = this._deleteDisallowedTags(this._parser.parseFromString(util.htmlCompress(html), 'text/html').body.innerHTML).replace(/(<[a-zA-Z0-9\-]+)[^>]*(?=>)/g, this._cleanTags.bind(this, true)).replace(/<br\/?>$/i, '');
const dom = _d.createRange().createContextualFragment(html);
try {
util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, this._htmlCheckBlacklistRegExp, this._classNameFilter);
util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, this._htmlCheckBlacklistRegExp, this._classNameFilter, options.strictHTMLValidation);
} catch (error) {
console.warn('[SUNEDITOR.cleanHTML.consistencyCheck.fail] ' + error);
}
Expand Down Expand Up @@ -5538,16 +5538,13 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
* @returns {String}
*/
convertContentsForEditor: function (contents) {
if (!options.strictMode) return contents;
if (!options.strictMode) return util.htmlCompress(contents);

contents = this._deleteDisallowedTags(this._parser.parseFromString(util.htmlCompress(contents), 'text/html').body.innerHTML).replace(/(<[a-zA-Z0-9\-]+)[^>]*(?=>)/g, this._cleanTags.bind(this, true));
const dom = _d.createRange().createContextualFragment(contents);

try {
if (this.options.strictHTMLValidation) {
util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, this._htmlCheckBlacklistRegExp, this._classNameFilter);
} else {
util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, false);
}
util._consistencyCheckOfHTML(dom, this._htmlCheckWhitelistRegExp, this._htmlCheckBlacklistRegExp, this._classNameFilter, options.strictHTMLValidation);
} catch (error) {
console.warn('[SUNEDITOR.convertContentsForEditor.consistencyCheck.fail] ' + error);
}
Expand Down
5 changes: 3 additions & 2 deletions src/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -1931,9 +1931,10 @@ const util = {
* @param {RegExp} htmlCheckWhitelistRegExp Editor tags whitelist (core._htmlCheckWhitelistRegExp)
* @param {RegExp} htmlCheckBlacklistRegExp Editor tags blacklist (core._htmlCheckBlacklistRegExp)
* @param {Function} classNameFilter Class name filter function
* @param {Function} strictHTMLValidation Enforces strict HTML validation based on the editor`s policy
* @private
*/
_consistencyCheckOfHTML: function (documentFragment, htmlCheckWhitelistRegExp, htmlCheckBlacklistRegExp, classNameFilter) {
_consistencyCheckOfHTML: function (documentFragment, htmlCheckWhitelistRegExp, htmlCheckBlacklistRegExp, classNameFilter, strictHTMLValidation) {
/**
* It is can use ".children(util.getListChildren)" to exclude text nodes, but "documentFragment.children" is not supported in IE.
* So check the node type and exclude the text no (current.nodeType !== 1)
Expand Down Expand Up @@ -1982,7 +1983,7 @@ const util = {
else current.removeAttribute('class');
}

const result = current.parentNode !== documentFragment && nrtag &&
const result = strictHTMLValidation && current.parentNode !== documentFragment && nrtag &&
((this.isListCell(current) && !this.isList(current.parentNode)) ||
((this.isFormatElement(current) || this.isComponent(current)) && !this.isRangeFormatElement(current.parentNode) && !this.getParentElement(current, this.isComponent)));

Expand Down
11 changes: 6 additions & 5 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,8 +988,8 @@ let s2 = window.s2 = suneditor.create(document.getElementById('editor2'), {

// `,
// imageUploadUrl: 'http://localhost:3000/editor/upload',
// strictMode: false,
// strictHTMLValidation: true,
strictMode: false,
strictHTMLValidation: false,
allowedClassNames: '.',
width: '100%',
// fontSizeUnit: 'em',
Expand Down Expand Up @@ -1059,9 +1059,10 @@ let s2 = window.s2 = suneditor.create(document.getElementById('editor2'), {
// addTagsWhitelist: "fld|sort|sortType|lst|lstfld|header|section",
lineAttrReset: 'class',
imageAccept: '*/*',
value: `<p>Ôtez la <span style="color: rgb(235, 141, 117)">complexité</span>,<br>
M.Biz vous apporte des solutions utiles<br>
</p>`,
value: `<div style="text-align: center">
<p>This text is centered.</p>
<p>This text is centered.</p>
</div>`,
// attributesWhitelist: {
// all: 'style|class',
// },
Expand Down

0 comments on commit 1f2f738

Please sign in to comment.