diff --git a/config/current.ver b/config/current.ver index b8d0e57..3b495c7 100644 --- a/config/current.ver +++ b/config/current.ver @@ -1 +1 @@ -1.1.77 \ No newline at end of file +1.1.78 \ No newline at end of file diff --git a/public/assets/js/bridge/rte-editor.js b/public/assets/js/bridge/rte-editor.js index dfbde14..b5d0a7e 100644 --- a/public/assets/js/bridge/rte-editor.js +++ b/public/assets/js/bridge/rte-editor.js @@ -485,33 +485,85 @@ if (component && component.view && component.view.el) { const viewEl = component.view.el; const hasInline = / { try { - const cs = (viewEl.ownerDocument || document).defaultView.getComputedStyle(viewEl); - const styles = []; - const pushStyle = (prop, val) => { - if (val) styles.push(`${prop}:${val}`); + const docRef = sourceEl.ownerDocument || document; + const winRef = docRef.defaultView || window; + const clone = sourceEl.cloneNode(true); + const props = [ + 'font-family', + 'font-size', + 'font-weight', + 'font-style', + 'text-decoration-line', + 'text-align', + 'line-height', + 'color', + ]; + const walk = (orig, copy) => { + if (!orig || !copy) return; + if (orig.nodeType === 1 && copy.nodeType === 1) { + const cs = winRef.getComputedStyle(orig); + let style = copy.getAttribute('style') || ''; + const hasStyle = (name) => new RegExp(`${name}\\s*:`, 'i').test(style); + const pushStyle = (name, value) => { + if (!value || hasStyle(name)) return; + style += `${style && !style.trim().endsWith(';') ? ';' : ''}${name}:${value};`; + }; + props.forEach((prop) => { + let value = cs.getPropertyValue(prop); + if (!value) return; + if (prop === 'text-decoration-line' && value === 'none') return; + if (prop === 'text-align' && value === 'start') return; + if (prop === 'line-height' && value === 'normal') return; + pushStyle(prop === 'text-decoration-line' ? 'text-decoration' : prop, value.trim()); + }); + if (style) copy.setAttribute('style', style.trim()); + } + const origChildren = orig.childNodes || []; + const copyChildren = copy.childNodes || []; + for (let i = 0; i < origChildren.length; i += 1) { + walk(origChildren[i], copyChildren[i]); + } }; - pushStyle('font-family', cs.fontFamily); - pushStyle('font-size', cs.fontSize); - pushStyle('font-weight', cs.fontWeight); - pushStyle('font-style', cs.fontStyle); - if (cs.textDecorationLine && cs.textDecorationLine !== 'none') { - pushStyle('text-decoration', cs.textDecorationLine); - } - if (cs.textAlign && cs.textAlign !== 'start') { - pushStyle('text-align', cs.textAlign); - } - if (cs.lineHeight && cs.lineHeight !== 'normal') { - pushStyle('line-height', cs.lineHeight); - } - if (cs.color) { - pushStyle('color', cs.color); - } - if (styles.length) { - htmlSource = `${htmlSource}`; - } - } catch {} + walk(sourceEl, clone); + return clone.innerHTML || ''; + } catch { + return ''; + } + }; + if (!hasInline) { + const inlined = inlineComputedStyles(viewEl); + if (inlined) { + htmlSource = inlined; + } else { + try { + const cs = (viewEl.ownerDocument || document).defaultView.getComputedStyle(viewEl); + const styles = []; + const pushStyle = (prop, val) => { + if (val) styles.push(`${prop}:${val}`); + }; + pushStyle('font-family', cs.fontFamily); + pushStyle('font-size', cs.fontSize); + pushStyle('font-weight', cs.fontWeight); + pushStyle('font-style', cs.fontStyle); + if (cs.textDecorationLine && cs.textDecorationLine !== 'none') { + pushStyle('text-decoration', cs.textDecorationLine); + } + if (cs.textAlign && cs.textAlign !== 'start') { + pushStyle('text-align', cs.textAlign); + } + if (cs.lineHeight && cs.lineHeight !== 'normal') { + pushStyle('line-height', cs.lineHeight); + } + if (cs.color) { + pushStyle('color', cs.color); + } + if (styles.length) { + htmlSource = `${htmlSource}`; + } + } catch {} + } } } const initialHtml = this.sanitizeInlineHtml(htmlSource, modelContent || '');