text = $text; $this->url = $url; $this->width = $width; } /** * @param Excerpt $Excerpt * @param State $State * @return static|null */ public static function build(Excerpt $Excerpt, State $State) { $hostnameLabel = '[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?'; $commonMarkEmail = '[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]++@' . $hostnameLabel . '(?:\.' . $hostnameLabel . ')*'; if (\preg_match("/^<((mailto:)?$commonMarkEmail)>/i", $Excerpt->text(), $matches)) { $url = $matches[1]; if (! isset($matches[2])) { $url = "mailto:$url"; } return new self($matches[1], $url, \strlen($matches[0])); } } /** @return string */ public function text() { return $this->text; } /** @return string */ public function url() { return $this->url; } /** * @return Element */ public function stateRenderable() { return new Element('a', ['href' => $this->url()], [new Text($this->text())]); } /** * @return Text */ public function bestPlaintext() { return new Text($this->text()); } }