File tree Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Expand file tree Collapse file tree 3 files changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,9 @@ <h2>Add-ons</h2>
4848 < li >
4949 < strong > "clickableUrls"</ strong > - < span class ="hint "> Make URLs clickable (boolean). Default true</ span >
5050 </ li >
51+ < li >
52+ < strong > "wrapLinkWithAnchorTag"</ strong > - < span class ="hint "> Add URLs as anchor tag (boolean). Default false</ span >
53+ </ li >
5154 < li >
5255 < strong > "openLinksInNewWindow"</ strong > - < span class ="hint "> Open URLs in the same window/tab (boolean). Default true</ span >
5356 </ li >
Original file line number Diff line number Diff line change @@ -91,6 +91,14 @@ Highlighter.prototype = {
9191 elements . forEach ( function ( node ) {
9292 node . classList . add ( "cm-string-link" ) ;
9393 node . setAttribute ( "data-url" , decodedText ) ;
94+ if ( self . wrapLinkWithAnchorTag ( ) ) {
95+ var linkTag = document . createElement ( "a" ) ;
96+ linkTag . href = decodedText ;
97+ linkTag . setAttribute ( 'target' , '_blank' )
98+ linkTag . innerHTML = decodedText ;
99+ node . innerHTML = "" ;
100+ node . appendChild ( linkTag ) ;
101+ }
94102 } ) ;
95103 }
96104 } ) ;
@@ -200,6 +208,10 @@ Highlighter.prototype = {
200208 return this . options . addons . clickableUrls ;
201209 } ,
202210
211+ wrapLinkWithAnchorTag : function ( ) {
212+ return this . options . addons . wrapLinkWithAnchorTag ;
213+ } ,
214+
203215 openLinksInNewWindow : function ( ) {
204216 return this . options . addons . openLinksInNewWindow ;
205217 } ,
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ module.exports = {
77 alwaysRenderAllContent : false ,
88 sortKeys : false ,
99 clickableUrls : true ,
10+ wrapLinkWithAnchorTag : false ,
1011 openLinksInNewWindow : true ,
1112 autoHighlight : true
1213 } ,
You can’t perform that action at this time.
0 commit comments