@@ -78,6 +78,7 @@ export class OdooEditor extends EventTarget {
7878 } ,
7979 toSanitize : true ,
8080 isRootEditable : true ,
81+ defaultLinkAttributes : { } ,
8182 getContentEditableAreas : ( ) => [ ] ,
8283 _t : string => string ,
8384 } ,
@@ -1767,7 +1768,12 @@ export class OdooEditor extends EventTarget {
17671768 _createLinkWithUrlInTextNode ( textNode , url , index , length ) {
17681769 setCursor ( textNode , index , textNode , index + length ) ;
17691770 this . document . execCommand ( 'createLink' , false , url ) ;
1770- this . document . getSelection ( ) . collapseToEnd ( ) ;
1771+ const sel = this . document . getSelection ( ) ;
1772+ const link = closestElement ( sel . anchorNode , 'a' ) ;
1773+ for ( const [ param , value ] of Object . entries ( this . options . defaultLinkAttributes ) ) {
1774+ link . setAttribute ( param , `${ value } ` ) ;
1775+ }
1776+ sel . collapseToEnd ( ) ;
17711777 }
17721778
17731779 /**
@@ -1777,6 +1783,11 @@ export class OdooEditor extends EventTarget {
17771783 ev . preventDefault ( ) ;
17781784 const pastedText = ( ev . originalEvent || ev ) . clipboardData . getData ( 'text/plain' ) ;
17791785 const splitAroundUrl = pastedText . split ( URL_REGEX ) ;
1786+ const linkAttrs =
1787+ Object . entries ( this . options . defaultLinkAttributes )
1788+ . map ( entry => entry . join ( '="' ) )
1789+ . join ( '" ' ) + '" ' ;
1790+
17801791 for ( let i = 0 ; i < splitAroundUrl . length ; i ++ ) {
17811792 // Even indexes will always be plain text, and odd indexes will always be URL.
17821793 if ( i % 2 ) {
@@ -1785,7 +1796,7 @@ export class OdooEditor extends EventTarget {
17851796 : 'https://' + splitAroundUrl [ i ] ;
17861797 this . execCommand (
17871798 'insertHTML' ,
1788- ' <a href="' + url + '" >' + splitAroundUrl [ i ] + ' </a>' ,
1799+ ` <a href="${ url } " ${ linkAttrs } > ${ splitAroundUrl [ i ] } </a>` ,
17891800 ) ;
17901801 } else if ( splitAroundUrl [ i ] !== '' ) {
17911802 this . execCommand ( 'insertText' , splitAroundUrl [ i ] ) ;
0 commit comments