@@ -9,21 +9,19 @@ var safe = require('../util/safe')
9
9
function link ( node , _ , context ) {
10
10
var quote = checkQuote ( context )
11
11
var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
12
- var url = node . url || ''
13
- var title = node . title || ''
14
12
var exit
15
- var value
16
13
var subexit
17
- var currentStack
14
+ var value
15
+ var stack
18
16
19
17
if ( formatLinkAsAutolink ( node ) ) {
20
18
// Hide the fact that we’re in phrasing, because escapes don’t work.
21
- currentStack = context . stack
19
+ stack = context . stack
22
20
context . stack = [ ]
23
21
exit = context . enter ( 'autolink' )
24
22
value = '<' + phrasing ( node , context , { before : '<' , after : '>' } ) + '>'
25
23
exit ( )
26
- context . stack = currentStack
24
+ context . stack = stack
27
25
return value
28
26
}
29
27
@@ -34,24 +32,30 @@ function link(node, _, context) {
34
32
35
33
if (
36
34
// If there’s no url but there is a title…
37
- ( ! url && title ) ||
35
+ ( ! node . url && node . title ) ||
38
36
// Or if there’s markdown whitespace or an eol, enclose.
39
- / [ \t \r \n ] / . test ( url )
37
+ / [ \t \r \n ] / . test ( node . url )
40
38
) {
41
39
subexit = context . enter ( 'destinationLiteral' )
42
- value += '<' + safe ( context , url , { before : '<' , after : '>' } ) + '>'
40
+ value += '<' + safe ( context , node . url , { before : '<' , after : '>' } ) + '>'
43
41
} else {
44
42
// No whitespace, raw is prettier.
45
43
subexit = context . enter ( 'destinationRaw' )
46
- value += safe ( context , url , { before : ' ' , after : ' ' } )
44
+ value += safe ( context , node . url , {
45
+ before : '(' ,
46
+ after : node . title ? ' ' : ')'
47
+ } )
47
48
}
48
49
49
50
subexit ( )
50
51
51
- if ( title ) {
52
+ if ( node . title ) {
52
53
subexit = context . enter ( 'title' + suffix )
53
54
value +=
54
- ' ' + quote + safe ( context , title , { before : quote , after : quote } ) + quote
55
+ ' ' +
56
+ quote +
57
+ safe ( context , node . title , { before : quote , after : quote } ) +
58
+ quote
55
59
subexit ( )
56
60
}
57
61
0 commit comments