git push fixed link handling

feature/tests
Michael Ochmann 3 years ago
parent 98b72d96c1
commit 2c00ed8b4a
  1. 2
      README.md
  2. 8
      src/Parser.php

@ -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. 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. or via reference to [a later defined url][massivedynamic], i we so desire.
### Images ### Images

@ -119,19 +119,19 @@ class Parser {
$rbracket = $this->consume(); $rbracket = $this->consume();
$consumption++; $consumption++;
if ($this->current()->type !== TokenType::LBRACKET) { if ($this->current()->type !== TokenType::LBRACKET && $this->current()->type !== TokenType::LPAREN) {
$this->pointer -= $consumption; $this->pointer -= $consumption;
return null; return null;
} }
$lbracket = $this->consume(); $lbracketOrParen = $this->consume();
$index = ""; $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; $index .= $this->consume()->data;
$rbracket = $this->consume(); $rbracket = $this->consume();
$elm = $this->document->createElement("a", $text); $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); (array_key_exists($index, $this->references) ? $this->references[$index] : self::MAGIC_CHAR.$index.self::MAGIC_CHAR);
$elm->setAttribute("href", $href); $elm->setAttribute("href", $href);

Loading…
Cancel
Save