Skip to content

Commit

Permalink
2.44.7
Browse files Browse the repository at this point in the history
  • Loading branch information
JiHong88 committed Apr 9, 2023
2 parents e9445ad + fccf99c commit 867c8c7
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 25 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
@@ -1,6 +1,6 @@
{
"name": "suneditor",
"version": "2.44.6",
"version": "2.44.7",
"description": "Pure JavaScript based WYSIWYG web editor",
"author": "JiHong.Lee",
"license": "MIT",
Expand Down
34 changes: 12 additions & 22 deletions src/lib/core.js
Expand Up @@ -5221,8 +5221,8 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
_convertFontSize: function (to, size) {
const math = this._w.Math;
const value = size.match(/(\d+(?:\.\d+)?)(.+)/);
const sizeNum = value[1] * 1;
const from = value[2];
const sizeNum = value ? value[1] * 1 : util.fontValueMap[size];
const from = value ? value[2] : 'rem';
let pxSize = sizeNum;

if (/em/.test(from)) {
Expand Down Expand Up @@ -5263,7 +5263,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
const allowedStyle = [];
for (let i = 0, len = style.length, r; i < len; i++) {
r = style[i].match(/([a-zA-Z0-9-]+)(:)([^:]+$)/);
if (r && !/inherit|initial/i.test(r[3])) {
if (r && !/inherit|initial|revert|unset/i.test(r[3])) {
const k = util.kebabToCamelCase(r[1].trim());
const v = this.wwComputedStyle[k].replace(/"/g, '');
const c = r[3].trim();
Expand All @@ -5274,7 +5274,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
case 'fontSize':
if (!options.plugins.fontSize) continue;
if (!this._cleanStyleRegExp.fontSizeUnit.test(r[0])) {
r[0] = r[0].replace(this._w.RegExp('\\d+' + r[0].match(/\d+(.+$)/)[1]), this._convertFontSize.bind(this, options.fontSizeUnit));
r[0] = r[0].replace((r[0].match(/:\s*([^;]+)/) || [])[1], this._convertFontSize.bind(this, options.fontSizeUnit));
}
break;
case 'color':
Expand Down Expand Up @@ -5323,7 +5323,7 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
else v = m.match(lowLevelCheck ? this._attributesWhitelistRegExp : this._attributesWhitelistRegExp_all_data);

// attribute
if (lowLevelCheck) {
if (lowLevelCheck || tagName === 'span') {
if (tagName === 'a') {
const sv = m.match(/(?:(?:id|name)\s*=\s*(?:"|')[^"']*(?:"|'))/g);
if (sv) {
Expand All @@ -5343,27 +5343,17 @@ export default function (context, pluginCallButtons, plugins, lang, options, _re
else if (sv && !v.some(function (v) { return /^style/.test(v.trim()); })) v.push(sv[0]);
}

// img
if (tagName === 'img') {
let w = '', h = '';
// figure
if (util.isFigures(tagName)) {
const sv = m.match(/style\s*=\s*(?:"|')[^"']*(?:"|')/);
if (!v) v = [];
if (sv) {
w = sv[0].match(/width:(.+);/);
w = util.getNumber(w ? w[1] : '', -1) || '';
h = sv[0].match(/height:(.+);/);
h = util.getNumber(h ? h[1] : '', -1) || '';
}

if (!w || !h) {
const avw = m.match(/width\s*=\s*((?:"|')[^"']*(?:"|'))/);
const avh = m.match(/height\s*=\s*((?:"|')[^"']*(?:"|'))/);
if (avw || avh) {
w = !w ? util.getNumber(avw ? avw[1] : '') || '' : w;
h = !h ? util.getNumber(avh ? avh[1] : '') || '' : h;
}
const wsize = sv[0].match(/width\s?:\s?(\d+)(px|%)/);
const hsize = sv[0].match(/height\s?:\s?(\d+)(px|%)/);
const w_ = wsize && wsize[1] && wsize[2] ? wsize[1] + wsize[2] : 'auto';
const h_ = hsize && hsize[1] && hsize[2] ? hsize[1] + hsize[2] : 'auto';
v.push('style="width:'+ w_ + '; height:'+ h_ + ';"');
}
v.push('data-origin="' + (w + ',' + h) + '"');
}

if (v) {
Expand Down
19 changes: 19 additions & 0 deletions src/lib/util.js
Expand Up @@ -59,6 +59,16 @@ const util = {
*/
onlyZeroWidthRegExp: new RegExp('^' + String.fromCharCode(8203) + '+$'),

fontValueMap: {
'xx-small': 1,
'x-small': 2,
'small': 3,
'medium': 4,
'large': 5,
'x-large': 6,
'xx-large': 7
},

/**
* @description A method that checks If the text is blank or to see if it contains 'ZERO WIDTH SPACE' or empty (util.zeroWidthSpace)
* @param {String|Node} text String value or Node
Expand Down Expand Up @@ -857,6 +867,15 @@ const util = {
return node && /^(IMG|IFRAME|AUDIO|VIDEO|CANVAS)$/i.test(typeof node === 'string' ? node : node.nodeName);
},

/**
* @description Check the node is a figure tag or util.isMedia()
* @param {Node|String} node The element or element name to check
* @returns {Boolean}
*/
isFigures: function (node) {
return node && (this.isMedia(node) || /^(FIGURE)$/i.test(typeof node === 'string' ? node : node.nodeName));
},

/**
* @description Checks for numeric (with decimal point).
* @param {String|Number} text Text string or number
Expand Down

0 comments on commit 867c8c7

Please sign in to comment.