File tree 1 file changed +18
-0
lines changed
1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -2,10 +2,28 @@ import { marked } from "marked";
2
2
import { markedHighlight } from "marked-highlight" ;
3
3
import hljs from "highlight.js" ;
4
4
5
+ // Create custom renderer
6
+ const renderer = new marked . Renderer ( ) ;
7
+
8
+ interface MarkedLink {
9
+ href : string ;
10
+ title ?: string | null ;
11
+ text : string ;
12
+ }
13
+
14
+ // Override link rendering to open external links in new tabs
15
+ renderer . link = ( { href, title, text } : MarkedLink ) => {
16
+ const isExternal = href && ( href . startsWith ( 'http://' ) || href . startsWith ( 'https://' ) ) ;
17
+ const attrs = isExternal ? ' target="_blank" rel="noopener noreferrer"' : '' ;
18
+ const titleAttr = title ? ` title="${ title } "` : '' ;
19
+ return `<a href="${ href } "${ attrs } ${ titleAttr } >${ text } </a>` ;
20
+ } ;
21
+
5
22
marked . setOptions ( {
6
23
gfm : true ,
7
24
breaks : true ,
8
25
silent : true ,
26
+ renderer : renderer ,
9
27
} ) ;
10
28
11
29
marked . use (
You can’t perform that action at this time.
0 commit comments