@@ -9,21 +9,19 @@ var safe = require('../util/safe')
99function link ( node , _ , context ) {
1010 var quote = checkQuote ( context )
1111 var suffix = quote === '"' ? 'Quote' : 'Apostrophe'
12- var url = node . url || ''
13- var title = node . title || ''
1412 var exit
15- var value
1613 var subexit
17- var currentStack
14+ var value
15+ var stack
1816
1917 if ( formatLinkAsAutolink ( node ) ) {
2018 // Hide the fact that we’re in phrasing, because escapes don’t work.
21- currentStack = context . stack
19+ stack = context . stack
2220 context . stack = [ ]
2321 exit = context . enter ( 'autolink' )
2422 value = '<' + phrasing ( node , context , { before : '<' , after : '>' } ) + '>'
2523 exit ( )
26- context . stack = currentStack
24+ context . stack = stack
2725 return value
2826 }
2927
@@ -34,24 +32,30 @@ function link(node, _, context) {
3432
3533 if (
3634 // If there’s no url but there is a title…
37- ( ! url && title ) ||
35+ ( ! node . url && node . title ) ||
3836 // Or if there’s markdown whitespace or an eol, enclose.
39- / [ \t \r \n ] / . test ( url )
37+ / [ \t \r \n ] / . test ( node . url )
4038 ) {
4139 subexit = context . enter ( 'destinationLiteral' )
42- value += '<' + safe ( context , url , { before : '<' , after : '>' } ) + '>'
40+ value += '<' + safe ( context , node . url , { before : '<' , after : '>' } ) + '>'
4341 } else {
4442 // No whitespace, raw is prettier.
4543 subexit = context . enter ( 'destinationRaw' )
46- value += safe ( context , url , { before : ' ' , after : ' ' } )
44+ value += safe ( context , node . url , {
45+ before : '(' ,
46+ after : node . title ? ' ' : ')'
47+ } )
4748 }
4849
4950 subexit ( )
5051
51- if ( title ) {
52+ if ( node . title ) {
5253 subexit = context . enter ( 'title' + suffix )
5354 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
5559 subexit ( )
5660 }
5761
0 commit comments