@@ -294,13 +294,13 @@ function inline_autolink(s, i, no_links, replacements, result,
294
294
s = substr (s, i)
295
295
296
296
if (match (s, /^ <([a -zA -Z ][a -zA -Z0 -0 + . - ]+ :[^ > [:space :] ]+ )> /, x)) {
297
- # A URL
297
+ # A URL: "...:..."
298
298
299
299
if (no_links) t = esc_html(x[ 1 ] )
300
300
else t = " <a href=\" " esc_html(esc_url(x[ 1 ] )) " \" >" esc_html(x[ 1 ] ) " </a>"
301
301
302
302
} else if (match (s, /^ <([a -zA -Z0 -9 . !# $%&' *+ /= ? ^_`{ | }~- ]+ @[a -zA -Z0 -9 ]([a -zA -Z0 -9- ]{0 ,61 } [a -zA -Z0 -9 ])? (\. [a -zA -Z0 -9 ]([a -zA -Z0 -9- ]{0 ,61 } [a -zA -Z0 -9 ])? )* )> /, x)) {
303
- # An email address
303
+ # An email address: "...@..."
304
304
305
305
if (no_links) t = esc_html(x[ 1 ] )
306
306
else t = " <a href=\" mailto:" esc_html(x[ 1 ] ) " \" >" esc_html(x[ 1 ] ) " </a>"
@@ -374,8 +374,7 @@ function inline_link_or_image(s, i, no_links, replacements, result,
374
374
# replacements: a stack of HTML fragments. (Passed by reference.)
375
375
#
376
376
# result: an array in which the function returns the result of
377
- # parsing the link and the remaining text of s after the
378
- # autolink.
377
+ # parsing the link and the remaining text of s after the link.
379
378
#
380
379
# Returns 1 for success, 0 for failure.
381
380
@@ -403,9 +402,14 @@ function inline_link_or_image(s, i, no_links, replacements, result,
403
402
t = t substr (s, 1 , j); s = substr (s, j + 1 )
404
403
} else if (x[ 0 ] ~ /^ [`< ] /) {
405
404
if (inline_code_span(s, j, replacements, result1) ||
406
- inline_autolink(s, j, no_links, replacements, result1) ||
407
405
inline_html_tag(s, j, replacements, result1)) {
408
406
t = t substr (s, 1 , j - 1 ) result1[ " html" ] ; s = result1[ " rest" ]
407
+ } else if (inline_autolink(s, j, 1 , replacements, result1)) {
408
+ if (! is_image) {
409
+ return 0 # Nested link, so the outer link isn't one
410
+ } else { # Allowed in image alt text (but as text)
411
+ t = t substr (s, 1 , j - 1 ) result1[ " html" ] ; s = result1[ " rest" ]
412
+ }
409
413
} else { # delimiter that does not start anything
410
414
t = t substr (s, 1 , i- 1 ) " \002 " push(replacements, esc_html(x[ 0 ] )) " \003 "
411
415
s = substr (s, i + length (x[ 0 ] ))
@@ -420,18 +424,14 @@ function inline_link_or_image(s, i, no_links, replacements, result,
420
424
s = substr (s, i + length (x[ 0 ] ))
421
425
}
422
426
} else if (x[ 0 ] == " [" ) {
423
- if (! is_image) { # We're inside a link "[...](...)"
424
- if (inline_link_or_image(s, j)) {
425
- return 0
426
- } else { # "[" that does not start a link
427
- n++ ; t = t substr (s, i, j); s = substr (s, j + 1 )
428
- }
429
- } else { # We're inside an image ""
430
- if (inline_link_or_image(s, j, 1 , replacements, result1)) {
427
+ if (inline_link_or_image(s, j, 1 , replacements, result1)) {
428
+ if (! is_image) { # We're inside a link "[...](...)"
429
+ return 0 # Nested link, so the outer link isn't a link
430
+ } else { # We're inside an image ""
431
431
t = t substr (s, 1 , j - 1 ) result1[ " html" ] ; s = result1[ " rest" ]
432
- } else { # "[" that does not start a link
433
- n++ ; t = t substr (s, i, j); s = substr (s, j + 1 )
434
432
}
433
+ } else { # "[" that does not start a link
434
+ n++ ; t = t substr (s, i, j); s = substr (s, j + 1 )
435
435
}
436
436
} else if (n != 0 ) { # Balanced "]"
437
437
n-- ; t = t substr (s, i, j); s = substr (s, j + 1 )
0 commit comments