diff --git a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js index b9793d3a34..9bc8bbd58c 100644 --- a/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js +++ b/src/bundle/Resources/public/js/scripts/fieldType/base/base-rich-text.js @@ -325,6 +325,9 @@ nativeEditor.on('change', saveRichText); nativeEditor.on('customUpdate', saveRichText); nativeEditor.on('editorInteraction', saveRichText); + nativeEditor.on('afterPaste', () => { + this.setLinksProtocol(container); + }); return alloyEditor; } @@ -390,6 +393,24 @@ splitIntoWords(text) { return text.split(' ').filter((word) => word.trim()); } + + setLinksProtocol(container) { + const links = container.querySelectorAll('a'); + const anchorPrefix = '#'; + const protocolPrefix = 'http://'; + + links.forEach((link) => { + const href = link.getAttribute('href'); + const protocolPattern = /^https?:\/\//i; + + if (href && href.indexOf(anchorPrefix) !== 0 && !protocolPattern.test(href)) { + const protocolHref = protocolPrefix.concat(href); + + link.setAttribute('href', protocolHref); + link.setAttribute('data-cke-saved-href', protocolHref); + } + }); + } }; eZ.BaseRichText = BaseRichText;