Beispiel #1
0
 /**
  * @param Collection $headerCells
  * @param Collection $bodyRows
  *
  * @return Text
  */
 protected function createView(Collection $headerCells, Collection $bodyRows)
 {
     $tHeadRow = new Tag('tr');
     $tHeadRow->setText("\n" . $headerCells->join("\n") . "\n");
     $tHead = new Tag('thead');
     $tHead->setText("\n" . $tHeadRow . "\n");
     $tBody = new Tag('tbody');
     $bodyRows->apply(function (Collection $row) use(&$options) {
         $tr = new Tag('tr');
         $tr->setText("\n" . $row->join("\n") . "\n");
         return $tr;
     });
     $tBody->setText("\n" . $bodyRows->join("\n") . "\n");
     $table = new Tag('table');
     $table->setAttributes(array('class' => 'table'));
     $table->setText("\n" . $tHead . "\n" . $tBody . "\n");
     return new Text($table->render());
 }
 /**
  * Make links out of things like `<http://example.com/>`
  *
  * @param Text $text
  */
 public function processAutoLink(Text $text)
 {
     if (!$text->contains('<')) {
         return;
     }
     $text->replace('{<((?:https?|ftp):[^\'">\\s]+)>}', function (Text $w, Text $url) {
         $this->markdown->emit('escape.special_chars', [$url->replace('/(?<!\\\\)_/', '\\\\_')]);
         return $this->getRenderer()->renderLink($url, ['href' => $url->getString()]);
     });
     /** @noinspection PhpUnusedParameterInspection */
     $text->replace('{
         <
         (?:mailto:)?
         (
             [-.\\w]+
             \\@
             [-a-z0-9]+(\\.[-a-z0-9]+)*\\.[a-z]+
         )
         >
     }ix', function (Text $w, Text $address) {
         $address = "mailto:" . $address;
         $encode = array(function ($char) {
             return '&#' . ord($char) . ';';
         }, function ($char) {
             return '&#x' . dechex(ord($char)) . ';';
         }, function ($char) {
             return $char;
         });
         $chars = new Collection(str_split($address));
         $chars->apply(function ($char) use($encode) {
             if ($char == '@') {
                 return $encode[rand(0, 1)]($char);
             } elseif ($char != ':') {
                 $rand = rand(0, 100);
                 $key = $rand > 90 ? 2 : ($rand < 45 ? 0 : 1);
                 return $encode[$key]($char);
             }
             return $char;
         });
         $address = $chars->join();
         $text = $chars->slice(7)->join();
         return $this->getRenderer()->renderLink($text, ['href' => $address]);
     });
 }