diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 0a60eb83e85..0e13cc2f926 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -1982,8 +1982,11 @@ export function setTagName(el, newTagName) { while (el.firstChild) { n.append(el.firstChild); } - if (el.tagName === 'LI') { + const closestLi = el.closest('li'); + if (el.tagName === 'LI' && newTagName !== 'p') { el.append(n); + } else if (closestLi && newTagName === 'p') { + closestLi.replaceChildren(...n.childNodes); } else { el.parentNode.replaceChild(n, el); } diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js index 40b12e16979..4aeae1f0d4f 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js @@ -775,6 +775,20 @@ describe('setTagName', () => { contentAfter: '
[ab]