@@ -440,16 +440,9 @@ private Node wrapBracket(Bracket opener, Node wrapperNode, boolean includeMarker
440440 opener .bracketNode .unlink ();
441441 removeLastBracket ();
442442
443- // Links within links are not allowed. We found this link, so there can be no other link around it.
443+ // Links within links are not allowed. We found this link, so there can be no other links around it.
444444 if (opener .markerNode == null ) {
445- Bracket bracket = lastBracket ;
446- while (bracket != null ) {
447- if (bracket .markerNode == null ) {
448- // Disallow link opener. It will still get matched, but will not result in a link.
449- bracket .allowed = false ;
450- }
451- bracket = bracket .previous ;
452- }
445+ disallowPreviousLinks ();
453446 }
454447
455448 return wrapperNode ;
@@ -475,6 +468,15 @@ private Node replaceBracket(Bracket opener, Node node, boolean includeMarker) {
475468 n .unlink ();
476469 n = next ;
477470 }
471+
472+ // Links within links are not allowed. We found this link, so there can be no other links around it.
473+ // Note that this makes any syntax like `[foo]` behave the same as built-in links, which is probably a good
474+ // default (it works for footnotes). It might be useful for a `LinkProcessor` to be able to specify the
475+ // behavior; something we could add to `LinkResult` in the future if requested.
476+ if (opener .markerNode == null || !includeMarker ) {
477+ disallowPreviousLinks ();
478+ }
479+
478480 return node ;
479481 }
480482
@@ -489,6 +491,17 @@ private void removeLastBracket() {
489491 lastBracket = lastBracket .previous ;
490492 }
491493
494+ private void disallowPreviousLinks () {
495+ Bracket bracket = lastBracket ;
496+ while (bracket != null ) {
497+ if (bracket .markerNode == null ) {
498+ // Disallow link opener. It will still get matched, but will not result in a link.
499+ bracket .allowed = false ;
500+ }
501+ bracket = bracket .previous ;
502+ }
503+ }
504+
492505 /**
493506 * Try to parse the destination and an optional title for an inline link/image.
494507 */
0 commit comments