@@ -12,41 +12,37 @@ export const linkCompiler = ({
12
12
const attrs = [ ] ;
13
13
const text = this . parser . parseInline ( tokens ) || '' ;
14
14
const { str, config } = getAndRemoveConfig ( title ) ;
15
+ const isAbsolute = isAbsolutePath ( href ) ;
16
+ const isNotCompilable = compiler . _matchNotCompileLink ( href ) ;
17
+ const isMailto = href . startsWith ( 'mailto:' ) ;
18
+
15
19
linkTarget = config . target || linkTarget ;
16
20
linkRel =
17
21
linkTarget === '_blank'
18
22
? compiler . config . externalLinkRel || 'noopener'
19
23
: '' ;
20
24
title = str ;
21
25
22
- if (
23
- ! isAbsolutePath ( href ) &&
24
- ! compiler . _matchNotCompileLink ( href ) &&
25
- ! config . ignore
26
- ) {
26
+ if ( ! isAbsolute && ! isNotCompilable && ! config . ignore ) {
27
27
if ( href === compiler . config . homepage ) {
28
28
href = 'README' ;
29
29
}
30
-
31
30
href = router . toURL ( href , null , router . getCurrentPath ( ) ) ;
32
31
33
- if ( config . target ) {
34
- href . indexOf ( 'mailto:' ) !== 0 && attrs . push ( `target="${ linkTarget } "` ) ;
32
+ if ( config . target && ! isMailto ) {
33
+ attrs . push ( `target="${ linkTarget } "` ) ;
35
34
}
36
35
} else {
37
- if ( ! isAbsolutePath ( href ) && href . startsWith ( './' ) ) {
38
- href = router
39
- . toURL ( href , null , router . getCurrentPath ( ) )
40
- . replace ( / ^ # \/ / , '/' ) ;
36
+ if ( ! isAbsolute && ! isNotCompilable && href . startsWith ( './' ) ) {
37
+ href = router . toURL ( href , null , router . getCurrentPath ( ) ) . replace ( / ^ # \/ / , '/' ) ;
38
+ }
39
+
40
+ if ( ! isMailto ) {
41
+ attrs . push ( `target="${ linkTarget } "` ) ;
42
+ if ( linkRel !== '' ) {
43
+ attrs . push ( `rel="${ linkRel } "` ) ;
44
+ }
41
45
}
42
- attrs . push ( href . indexOf ( 'mailto:' ) === 0 ? '' : `target="${ linkTarget } "` ) ;
43
- attrs . push (
44
- href . indexOf ( 'mailto:' ) === 0
45
- ? ''
46
- : linkRel !== ''
47
- ? ` rel="${ linkRel } "`
48
- : '' ,
49
- ) ;
50
46
}
51
47
52
48
if ( config . disabled ) {
0 commit comments