Skip to content

Commit

Permalink
2.43.9
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Jun 10, 2022
2 parents e184a24 + 025acbb commit 27e86aa
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 54 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.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "suneditor",
"version": "2.43.8",
"version": "2.43.9",
"description": "Pure JavaScript based WYSIWYG web editor",
"author": "JiHong.Lee",
"license": "MIT",
Expand Down
1 change: 1 addition & 0 deletions sample/html/customPlugins.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="author" content="https://github.com/JiHong88" />
<meta name="keywords" content="wysiwyg,editor,javascript,suneditor,wysiwyg eidtor,rich text editor,html editor,contenteditable,위지위그 에디터 웹에디터">
<meta name="description" content="Pure javascript wysiwyg web editor" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>SunEditor</title>
<!-- sample css -->
<link rel="stylesheet" href="../css/bootstrap.css" media="all">
Expand Down
1 change: 1 addition & 0 deletions sample/html/document.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<meta http-equiv="refresh" content="0; url=out/index.html" />
</html>
1 change: 1 addition & 0 deletions sample/html/examples.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="author" content="https://github.com/JiHong88" />
<meta name="keywords" content="wysiwyg,editor,javascript,suneditor,wysiwyg eidtor,rich text editor,html editor,contenteditable,위지위그 에디터 웹에디터">
<meta name="description" content="Pure javascript wysiwyg web editor" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>SunEditor</title>
<!-- sample css -->
<link rel="stylesheet" href="../css/bootstrap.css" media="all">
Expand Down
1 change: 1 addition & 0 deletions sample/html/getting-started.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="author" content="https://github.com/JiHong88" />
<meta name="keywords" content="wysiwyg,editor,javascript,suneditor,wysiwyg eidtor,rich text editor,html editor,contenteditable,위지위그 에디터 웹에디터">
<meta name="description" content="Pure javascript wysiwyg web editor" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>SunEditor</title>
<!-- sample css -->
<link rel="stylesheet" href="../css/bootstrap.css" media="all">
Expand Down
1 change: 1 addition & 0 deletions sample/html/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="author" content="https://github.com/JiHong88" />
<meta name="keywords" content="wysiwyg,editor,javascript,suneditor,wysiwyg eidtor,rich text editor,html editor,contenteditable,위지위그 에디터 웹에디터">
<meta name="description" content="Pure javascript wysiwyg web editor" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>SunEditor</title>
<!-- sample css -->
<link rel="stylesheet" href="../css/bootstrap.css" media="all">
Expand Down
1 change: 1 addition & 0 deletions sample/html/out/document-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>JSDoc: Suneditor</title>

<link rel="stylesheet" href="../../css/github.css">
Expand Down
1 change: 1 addition & 0 deletions sample/html/out/document-module.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>JSDoc: Suneditor</title>

<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
Expand Down
1 change: 1 addition & 0 deletions sample/html/out/document-user.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>JSDoc: Suneditor</title>

<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
Expand Down
1 change: 1 addition & 0 deletions sample/html/out/document-util.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>JSDoc: Suneditor</title>

<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
Expand Down
1 change: 1 addition & 0 deletions sample/html/out/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>JSDoc: Home</title>

<link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
Expand Down
1 change: 1 addition & 0 deletions sample/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<meta name="author" content="https://github.com/JiHong88" />
<meta name="keywords" content="wysiwyg,editor,javascript,suneditor,wysiwyg eidtor,rich text editor,html editor,contenteditable,위지위그 에디터 웹에디터">
<meta name="description" content="Pure javascript wysiwyg web editor" />
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-6933506635175446" crossorigin="anonymous"></script>
<title>SunEditor</title>
<!-- sample css -->
<link rel="stylesheet" href="./css/bootstrap.css" media="all">
Expand Down
3 changes: 3 additions & 0 deletions src/lib/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ export default {
options.toolbarWidth = options.toolbarWidth ? (util.isNumber(options.toolbarWidth) ? options.toolbarWidth + 'px' : options.toolbarWidth) : 'auto';
options.toolbarContainer = typeof options.toolbarContainer === 'string' ? document.querySelector(options.toolbarContainer) : options.toolbarContainer;
options.stickyToolbar = (/balloon/i.test(options.mode) || !!options.toolbarContainer) ? -1 : options.stickyToolbar === undefined ? 0 : (/^\d+/.test(options.stickyToolbar) ? util.getNumber(options.stickyToolbar, 0) : -1);
options.hideToolbar = !!options.hideToolbar;
options.fullScreenOffset = options.fullScreenOffset === undefined ? 0 : (/^\d+/.test(options.fullScreenOffset) ? util.getNumber(options.fullScreenOffset, 0) : 0);
options.fullPage = !!options.fullPage;
options.iframe = options.fullPage || !!options.iframe;
Expand Down Expand Up @@ -928,6 +929,8 @@ export default {
tool_cover.className = 'se-toolbar-cover';
tool_bar.appendChild(tool_cover);

if (options.hideToolbar) tool_bar.style.display = 'none';

return {
'element': tool_bar,
'plugins': plugins,
Expand Down
121 changes: 73 additions & 48 deletions src/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
* @private
*/
_attributesWhitelistRegExp: null,
_attributesWhitelistRegExp_all_data: null,

/**
* @description Attributes blacklist used by the cleanHTML method
Expand Down Expand Up @@ -469,6 +470,14 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
*/
_styleCommandMap: null,

/**
* @private
*/
_cleanStyleRegExp: {
span: new _w.RegExp('\s*(font-family|font-size|color|background-color)\s*:[^;]+(?!;)*', 'ig'),
format: new _w.RegExp('\s*(text-align|margin-left|margin-right)\s*:[^;]+(?!;)*', 'ig')
},

/**
* @description Variables used internally in editor operation
* @property {Boolean} isCodeView State of code view
Expand Down Expand Up @@ -5093,6 +5102,46 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
.replace(this.editorTagsBlacklistRegExp, '');
},

_cleanStyle: function (m, v, tagName) {
const sv = m.match(/style\s*=\s*(?:"|')[^"']*(?:"|')/);
if (sv) {
if (!v) v = [];
const style = sv[0].replace(/&quot;/g, '').match(this._cleanStyleRegExp[tagName]);
if (style) {
const allowedStyle = [];
for (let i = 0, len = style.length, r; i < len; i++) {
r = style[i].match(/(.+)(:)([^:]+$)/);
if (r && !/inherit|initial/i.test(r[3])) {
const k = util.kebabToCamelCase(r[1].trim());
const v = this.wwComputedStyle[k].replace(/"/g, '');
const c = r[3].trim();
switch (k) {
case 'fontFamily':
if (!options.plugins.font || options.font.indexOf(c) === -1) continue;
break;
case 'fontSize':
if (!options.plugins.fontSize) continue;
break;
case 'color':
if (!options.plugins.fontColor) continue;
break;
case 'backgroundColor':
if (!options.plugins.hiliteColor) continue;
break;
}

if (v !== c) {
allowedStyle.push(r[0]);
}
}
}
if (allowedStyle.length > 0) v.push('style="' + allowedStyle.join(';') + '"');
}
}

return v;
},

/**
* @description Tag and tag attribute check RegExp function. (used by "cleanHTML" and "convertContentsForEditor")
* @param {Boolean} lowLevelCheck Row level check
Expand All @@ -5109,64 +5158,38 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re

// blacklist
const bAttr = this._attributesTagsBlacklist[tagName];
m = m.replace(/\s(?:on[a-z]+)\s*=\s*(")[^"]*\1/ig, '');
if (bAttr) m = m.replace(bAttr, '');
else m = m.replace(this._attributesBlacklistRegExp, '');

// whitelist
const wAttr = this._attributesTagsWhitelist[tagName];
if (wAttr) v = m.match(wAttr);
else v = m.match(this._attributesWhitelistRegExp);

// anchor
if (!lowLevelCheck || /<a\b/i.test(t)) {
const sv = m.match(/(?:(?:id|name)\s*=\s*(?:"|')[^"']*(?:"|'))/g);
if (sv) {
if (!v) v = [];
v.push(sv[0]);
}
}
else v = m.match(lowLevelCheck ? this._attributesWhitelistRegExp : this._attributesWhitelistRegExp_all_data);

// span
if ((!lowLevelCheck || /<span/i.test(t)) && (!v || !/style=/i.test(v.toString()))) {
const sv = m.match(/style\s*=\s*(?:"|')[^"']*(?:"|')/);
if (sv) {
if (!v) v = [];
const style = sv[0].replace(/&quot;/g, '').match(/\s*(font-family|font-size|color|background-color)\s*:[^;]+(?!;)*/ig);
if (style) {
const allowedStyle = [];
for (let i = 0, len = style.length, r; i < len; i++) {
r = style[i].match(/(.+)(:)([^:]+$)/);
if (r && !/inherit|initial/i.test(r[3])) {
const k = util.kebabToCamelCase(r[1].trim());
const v = this.wwComputedStyle[k].replace(/"/g, '');
const c = r[3].trim();
switch (k) {
case 'fontFamily':
if (options.plugins.font ? options.font.indexOf(c) === -1 : true) continue;
break;
case 'fontSize':
if (!options.plugins.fontSize) continue;
break;
case 'color':
if (!options.plugins.fontColor) continue;
break;
case 'backgroundColor':
if (!options.plugins.hiliteColor) continue;
break;
}

if (v !== c) {
allowedStyle.push(r[0]);
}
}
}
if (allowedStyle.length > 0) v.push('style="' + allowedStyle.join(';') + '"');
// attribute
if (lowLevelCheck) {
if (tagName === 'a') {
const sv = m.match(/(?:(?:id|name)\s*=\s*(?:"|')[^"']*(?:"|'))/g);
if (sv) {
if (!v) v = [];
v.push(sv[0]);
}
} else if (!v || !/style=/i.test(v.toString())) {
if (tagName === 'span') {
v = this._cleanStyle(m, v, 'span');
} else if (/^(P|DIV|H[1-6]|PRE)$/i.test(tagName)) {
v = this._cleanStyle(m, v, 'format');
}
}
} else {
const sv = m.match(/style\s*=\s*(?:"|')[^"']*(?:"|')/);
if (sv && !v) v = [sv[0]];
else if (sv && !v.some(function (v) { return /^style/.test(v.trim()); })) v.push(sv[0]);
}

// img
if (/<img/i.test(t)) {
if (tagName === 'img') {
let w = '', h = '';
const sv = m.match(/style\s*=\s*(?:"|')[^"']*(?:"|')/);
if (!v) v = [];
Expand Down Expand Up @@ -5695,7 +5718,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
// set whitelist
const getRegList = function (str, str2) { return !str ? '^' : (str === '*' ? '[a-z-]+' : (!str2 ? str : (str + '|' + str2))); };
// tags
const defaultAttr = 'contenteditable|colspan|rowspan|target|href|download|rel|src|alt|class|type|controls|data-format|data-size|data-file-size|data-file-name|data-origin|data-align|data-image-link|data-rotate|data-proportion|data-percentage|origin-size|data-exp|data-font-size';
const defaultAttr = 'contenteditable|colspan|rowspan|target|href|download|rel|src|alt|class|type|controls|origin-size';
const dataAttr = 'data-format|data-size|data-file-size|data-file-name|data-origin|data-align|data-image-link|data-rotate|data-proportion|data-percentage|data-exp|data-font-size';
this._allowHTMLComments = options._editorTagsWhitelist.indexOf('//') > -1 || options._editorTagsWhitelist === '*';
// html check
this._htmlCheckWhitelistRegExp = new wRegExp('^(' + getRegList(options._editorTagsWhitelist.replace('|//', ''), '') + ')$', 'i');
Expand All @@ -5722,7 +5746,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
}
}

this._attributesWhitelistRegExp = new wRegExp('\\s(?:' + (allAttr || defaultAttr) + ')' + regEndStr, 'ig');
this._attributesWhitelistRegExp = new wRegExp('\\s(?:' + (allAttr || defaultAttr + '|' + dataAttr) + ')' + regEndStr, 'ig');
this._attributesWhitelistRegExp_all_data = new wRegExp('\\s(?:' + ((allAttr || defaultAttr) + '|data-[a-z0-9\\-]+') + ')' + regEndStr, 'ig');
this._attributesTagsWhitelist = tagsAttr;

// blacklist
Expand Down
6 changes: 3 additions & 3 deletions test/dev/suneditor_build_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ s1.onKeyDown = function (e, core) {
}

let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
mode: "inline",
// mode: "inline",
// value: `Let $\Omega$ be the underlying randomness space. In this case, the variables $X^-$ and $X^+$ collapse to $U$. To see why, pick an arbitrary $\omega \in \Omega$:
// \begin{align*}X^-(\Omega) = \sup\left\{y\in [0,1]: F(y)<U(\omega)\right\} = \sup\left\{y\in [0,1]: P(U\leq y)<U(\omega)\right\} = \sup\left\{y\in [0,1]: y<U(\omega)\right\} = U(\omega).\end{align*}`,
// value: `
Expand All @@ -422,6 +422,7 @@ let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
// </p>
// `,
// __defaultFontSize: "31pt",
hideToolbar: true,
paragraphStyles: [
"spaced",
"neon",
Expand All @@ -438,8 +439,7 @@ let ss = window.ss = suneditor.create(document.getElementById('editor1'), {
fontSizeUnit: 'pt',
// lineAttrReset: '*',
alignItems: ['left', 'right', 'center'],
value: `<ol><li>dsdasdasssaa</li><li>u8743789</li></ol>
`,
value: `<p style="text-align: center; color: red;" onerror="a">center</p>`,
linkTargetNewWindow: true,
imageAlignShow: false,
plugins: {...{custom_container}, ...plugins},
Expand Down

0 comments on commit 27e86aa

Please sign in to comment.