[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) <nby@odoo.com>
Signed-off-by: Antoine Guenet (age) <age@odoo.com>
This commit is contained in:
Antoine Guenet
2024-01-10 06:12:27 +00:00
parent 4ccc64a3e5
commit 759fad4472
@@ -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);
}