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 6753fae8ff3..4f6c7afea27 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -11,6 +11,7 @@ import { isBlock, rgbToHex } from '../../../lib/odoo-editor/src/utils/utils'; const RE_COL_MATCH = /(^| )col(-[\w\d]+)*( |$)/; const RE_OFFSET_MATCH = /(^| )offset(-[\w\d]+)*( |$)/; const RE_PADDING = /([\d.]+)/; +const RE_WHITESPACE = /[\s\u200b]*/; const SELECTORS_IGNORE = /(^\*$|:hover|:before|:after|:active|:link|::|'|\([^(),]+[,(])/; // Attributes all tables should have in a mailing. const TABLE_ATTRIBUTES = { @@ -248,25 +249,33 @@ function cardToTable($editable) { const $card = $(card); const $table = _createTable(card.attributes); for (const child of [...card.childNodes]) { - if (child.nodeType === Node.TEXT_NODE) { - $table.append(child); - } else { - const $row = $(''); - const $col = $(''); - if (child.nodeName === 'IMG') { + const $row = $(''); + const $col = $(''); + if (child.nodeName === 'IMG') { + $col.append(child); + } else if (child.nodeType === Node.TEXT_NODE) { + if (child.textContent.replace(RE_WHITESPACE, '').length) { $col.append(child); } else { - for (const attr of child.attributes) { - $col.attr(attr.name, attr.value); - } - for (const descendant of [...child.childNodes]) { - $col.append(descendant); - } - $(child).remove(); + continue; } - $row.append($col); - $table.append($row); + } else { + for (const attr of child.attributes) { + $col.attr(attr.name, attr.value); + } + for (const descendant of [...child.childNodes]) { + $col.append(descendant); + } + $(child).remove(); } + const $subTable = _createTable(); + const $superRow = $(''); + const $superCol = $(''); + $row.append($col); + $subTable.append($row); + $superCol.append($subTable); + $superRow.append($superCol); + $table.append($superRow); } $card.before($table); $card.remove(); diff --git a/addons/web_editor/static/tests/convert_inline_tests.js b/addons/web_editor/static/tests/convert_inline_tests.js index 0a642959dcf..19020c47e21 100644 --- a/addons/web_editor/static/tests/convert_inline_tests.js +++ b/addons/web_editor/static/tests/convert_inline_tests.js @@ -251,9 +251,27 @@ QUnit.module('convert_inline', {}, function () { assert.strictEqual($editable.html(), getRegularTableHtml(3, 1, 12, 100) .split('style="').join('class="card" style="') - .replace(/]*>\(0, 0\)<\/td>/, 'HEADER') - .replace(/]*>\(1, 0\)<\/td>/, '

TITLE

BODY ') - .replace(/]*>\(2, 0\)<\/td>/, 'FOOTER'), + .replace(/]*>\(0, 0\)<\/td>/, + `` + + `` + + `` + + `
HEADER
`) + .replace(/]*>\(1, 0\)<\/td>/, + `` + + `` + + `` + + `

TITLE

BODY
`) + .replace(/]*>\(2, 0\)<\/td>/, + `` + + `` + + `` + + `
`), "should have converted a card structure into a table"); }); QUnit.test('convert a list group to a table', async function (assert) {