[FIX] web_editor: properly convert inherited and inline color styles

The mass mailing transpiler wrongly applied inherited colors to children
and failed to take inline styles into account, while those are supposed
to have the highest specificity.

Part-of: odoo/odoo#77724
This commit is contained in:
Antoine Guenet
2021-10-04 15:31:12 +00:00
parent 6e5827e472
commit ecad4b282e
@@ -118,6 +118,14 @@ function getMatchedCSSRules(a) {
return a*100 + b*10 + c;
}
css.sort(function (a, b) { return specificity(a[0]) - specificity(b[0]); });
// Add inline styles at the highest specificity.
if (a.style.length) {
const inlineStyles = {};
for (const styleName of a.style) {
inlineStyles[styleName] = a.style[styleName];
}
css.push([a, inlineStyles]);
}
style = {};
_.each(css, function (v,k) {
@@ -210,10 +218,10 @@ function getMatchedCSSRules(a) {
const camelCased = styleName.replace(/-(\w)/g, match => match[1].toUpperCase());
node.style[camelCased] = style[styleName];
for (const child of $(node).children()) {
const childStyle = $(child).css(styleName);
if (childStyle && childStyle !== 'inherit') {
_styleDescendants(child, styleName);
if (child.style[camelCased] !== style[styleName]) {
break;
}
_styleDescendants(child, styleName);
}
}
if (style.color) {