@@ -601,25 +601,69 @@ function translateLinkNode(params) {
601601
602602 const linkMark = node . marks . find ( ( m ) => m . type === 'link' ) ;
603603 const link = linkMark . attrs . href ;
604+
604605 let rId = linkMark . attrs . rId ;
605606 if ( ! rId ) {
606607 rId = addNewLinkRelationship ( params , link ) ;
607608 }
608609
609610 node . marks = node . marks . filter ( ( m ) => m . type !== 'link' ) ;
611+
610612 const outputNode = exportSchemaToJson ( { ...params , node } ) ;
613+ const contentNode = processLinkContentNode ( outputNode ) ;
614+
611615 const newNode = {
612616 name : 'w:hyperlink' ,
613617 type : 'element' ,
614618 attributes : {
615619 'r:id' : rId ,
616620 } ,
617- elements : [ outputNode ] ,
621+ elements : [ contentNode ] ,
618622 } ;
619623
620624 return newNode ;
621625}
622626
627+ function processLinkContentNode ( node ) {
628+ if ( ! node ) return node ;
629+
630+ const contentNode = carbonCopy ( node ) ;
631+ if ( ! contentNode ) return contentNode ;
632+
633+ const hyperlinkStyle = {
634+ name : 'w:rStyle' ,
635+ attributes : { 'w:val' : 'Hyperlink' } ,
636+ } ;
637+ const color = {
638+ name : 'w:color' ,
639+ attributes : { 'w:val' : '467886' } ,
640+ } ;
641+
642+ if ( contentNode . name === 'w:r' ) {
643+ const runProps = contentNode . elements . find ( ( el ) => el . name === 'w:rPr' ) ;
644+
645+ if ( runProps ) {
646+ const foundColor = runProps . elements . find ( ( el ) => el . name === 'w:color' ) ;
647+ const foundHyperlinkStyle = runProps . elements . find ( ( el ) => el . name === 'w:rStyle' ) ;
648+ if ( ! foundColor ) runProps . elements . unshift ( color ) ;
649+ if ( ! foundHyperlinkStyle ) runProps . elements . unshift ( hyperlinkStyle ) ;
650+ } else {
651+ // we don't add underline by default
652+ const runProps = {
653+ name : 'w:rPr' ,
654+ elements : [
655+ hyperlinkStyle ,
656+ color ,
657+ ] ,
658+ } ;
659+
660+ contentNode . elements . unshift ( runProps ) ;
661+ }
662+ }
663+
664+ return contentNode ;
665+ }
666+
623667/**
624668 * Create a new link relationship and add it to the relationships array
625669 *
@@ -630,7 +674,10 @@ function translateLinkNode(params) {
630674function addNewLinkRelationship ( params , link ) {
631675 const newId = 'rId' + generateDocxRandomId ( ) ;
632676
633- if ( ! params . relationships || ! Array . isArray ( params . relationships ) ) params . relationships = [ ] ;
677+ if ( ! params . relationships || ! Array . isArray ( params . relationships ) ) {
678+ params . relationships = [ ] ;
679+ }
680+
634681 params . relationships . push ( {
635682 type : 'element' ,
636683 name : 'Relationship' ,
@@ -641,6 +688,7 @@ function addNewLinkRelationship(params, link) {
641688 TargetMode : 'External' ,
642689 } ,
643690 } ) ;
691+
644692 return newId ;
645693}
646694
@@ -1817,6 +1865,7 @@ function prepareUrlAnnotation(params) {
18171865 const newId = addNewLinkRelationship ( params , attrs . linkUrl ) ;
18181866
18191867 const linkTextNode = getTextNodeForExport ( attrs . linkUrl , marks , params ) ;
1868+ const contentNode = processLinkContentNode ( linkTextNode ) ;
18201869
18211870 return {
18221871 name : 'w:hyperlink' ,
@@ -1825,7 +1874,7 @@ function prepareUrlAnnotation(params) {
18251874 'r:id' : newId ,
18261875 'w:history' : 1 ,
18271876 } ,
1828- elements : [ linkTextNode ] ,
1877+ elements : [ contentNode ] ,
18291878 } ;
18301879}
18311880
0 commit comments