diff --git a/README.md b/README.md index 3f4be40..82f7679 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ A simple paragraph can contain **bold text**, `inline codeblocks` and *italic te or via reference to [a later defined url][massivedynamic], i we so desire. ``` -A simple paragraph can contain **bold text**, `inline codeblocks` and *italic text*. We can also link [with a direct url][https://google.com] *(i.e. to google)* +A simple paragraph can contain **bold text**, `inline codeblocks` and *italic text*. We can also link [with a direct url](https://google.com) *(i.e. to google)* or via reference to [a later defined url][massivedynamic], i we so desire. ### Images diff --git a/src/Parser.php b/src/Parser.php index 4cf06ea..5cea154 100644 --- a/src/Parser.php +++ b/src/Parser.php @@ -119,19 +119,19 @@ class Parser { $rbracket = $this->consume(); $consumption++; - if ($this->current()->type !== TokenType::LBRACKET) { + if ($this->current()->type !== TokenType::LBRACKET && $this->current()->type !== TokenType::LPAREN) { $this->pointer -= $consumption; return null; } - $lbracket = $this->consume(); + $lbracketOrParen = $this->consume(); $index = ""; - while (!($this->current()->type === TokenType::RBRACKET || $this->current()->type === TokenType::EOL)) + while (!($this->current()->type === TokenType::RBRACKET || $this->current()->type === TokenType::RPAREN || $this->current()->type === TokenType::EOL)) $index .= $this->consume()->data; $rbracket = $this->consume(); $elm = $this->document->createElement("a", $text); - $href = str_starts_with($index, "http") ? $index : + $href = $lbracketOrParen->type === TokenType::LPAREN ? $index : (array_key_exists($index, $this->references) ? $this->references[$index] : self::MAGIC_CHAR.$index.self::MAGIC_CHAR); $elm->setAttribute("href", $href);