diff options
Diffstat (limited to 'addons/html_editor/static/src/utils/sanitize.js')
| -rw-r--r-- | addons/html_editor/static/src/utils/sanitize.js | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/addons/html_editor/static/src/utils/sanitize.js b/addons/html_editor/static/src/utils/sanitize.js index 4836e3f27f5..e8e90aa1d63 100644 --- a/addons/html_editor/static/src/utils/sanitize.js +++ b/addons/html_editor/static/src/utils/sanitize.js @@ -1,5 +1,6 @@ import { containsAnyInline } from "./dom_info"; import { wrapInlinesInBlocks } from "./dom"; +import { markup } from "@odoo/owl"; export function initElementForEdition(element, options = {}) { if ( @@ -16,7 +17,28 @@ export function initElementForEdition(element, options = {}) { } } +/** + * Properly close common XML-like self-closing elements to avoid HTML parsing + * issues. + * + * @param {string} content + * @returns {string} + */ export function fixInvalidHTML(content) { + if (!content) { + return content; + } + // TODO: improve the regex to support nodes with data-attributes containing + // `/` and `>` characters. const regex = /<\s*(a|strong|t)[^<]*?\/\s*>/g; return content.replace(regex, (match, g0) => match.replace(/\/\s*>/, `></${g0}>`)); } + +let Markup = null; + +export function instanceofMarkup(value) { + if (!Markup) { + Markup = markup("").constructor; + } + return value instanceof Markup; +} |
