@@ -12,40 +12,39 @@ 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 . slice ( 0 , 2 ) === './' ) {
38
- href =
39
- document . URL . replace ( / \/ (? ! .* \/ ) .* / , '/' ) . replace ( '#/./' , '' ) + href ;
36
+ if ( ! isAbsolute && ! isNotCompilable && href . startsWith ( './' ) ) {
37
+ href = router
38
+ . toURL ( href , null , router . getCurrentPath ( ) )
39
+ . replace ( / ^ # \/ / , '/' ) ;
40
+ }
41
+
42
+ if ( ! isMailto ) {
43
+ attrs . push ( `target="${ linkTarget } "` ) ;
44
+ if ( linkRel !== '' ) {
45
+ attrs . push ( `rel="${ linkRel } "` ) ;
46
+ }
40
47
}
41
- attrs . push ( href . indexOf ( 'mailto:' ) === 0 ? '' : `target="${ linkTarget } "` ) ;
42
- attrs . push (
43
- href . indexOf ( 'mailto:' ) === 0
44
- ? ''
45
- : linkRel !== ''
46
- ? ` rel="${ linkRel } "`
47
- : '' ,
48
- ) ;
49
48
}
50
49
51
50
if ( config . disabled ) {
0 commit comments