From 759fad447281f6523263edc0e13236a11602d048 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 21 Dec 2023 16:06:22 +0100 Subject: [PATCH] [FIX] web_editor: preserve image/link on convert card When converting a card for e-mail client compatibility, we apply the attributes of the card's block children to their respective cells and unwrap them. However, that's an issue if the child is an image or a link since their respective `src` and `href` attributes are meaningless on the cells. task-3631900 opw-3580317 opw-3630693 closes odoo/odoo#148529 X-original-commit: d3bdb08c97ad7eab005ac185f393807df35f383e Signed-off-by: Nicolas Bayet (nby) Signed-off-by: Antoine Guenet (age) --- addons/web_editor/static/src/js/backend/convert_inline.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index e457cb3f737..a90211ae739 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -332,7 +332,7 @@ function cardToTable(editable) { for (const child of [...card.childNodes]) { const row = document.createElement('tr'); const col = document.createElement('td'); - if (isBlock(child)) { + if (!['IMG', 'A'].includes(child.nodeName) && isBlock(child)) { for (const attr of child.attributes) { col.setAttribute(attr.name, attr.value); } @@ -357,7 +357,10 @@ function cardToTable(editable) { superCol.append(subTable); superRow.append(superCol); table.append(superRow); - if (child.classList && child.classList.contains('card-img-top')) { + const hasImgTop = [child, ...child.querySelectorAll('.card-img-top')].some(node => ( + node.classList && node.classList.contains('card-img-top') && node.closest && node.closest('.card') === table + )); + if (hasImgTop) { // Collect .card-img-top superRows to manipulate their heights. cardImgTopSuperRows.push(superRow); }