diff --git a/src/Inline/Parser/CloseBracketParser.php b/src/Inline/Parser/CloseBracketParser.php index 6e6c24491f..4fe08bd685 100644 --- a/src/Inline/Parser/CloseBracketParser.php +++ b/src/Inline/Parser/CloseBracketParser.php @@ -123,12 +123,18 @@ public function setEnvironment(Environment $environment) protected function tryParseLink(Cursor $cursor, ReferenceMap $referenceMap, Delimiter $opener, $startPos) { // Check to see if we have a link/image + $previousState = $cursor->saveState(); + // Inline link? if ($cursor->getCharacter() === '(') { if ($result = $this->tryParseInlineLinkAndTitle($cursor)) { return $result; + } else { + $cursor->restoreState($previousState); } - } elseif ($link = $this->tryParseReference($cursor, $referenceMap, $opener, $startPos)) { + } + + if ($link = $this->tryParseReference($cursor, $referenceMap, $opener, $startPos)) { return ['url' => $link->getDestination(), 'title' => $link->getTitle()]; }