Beispiel #1
0
 /**
  * Helper function for BLOCKQUOTE body conversion.
  *
  * @param string $text HTML content
  */
 protected function convertBlockquotes(&$text)
 {
     if (preg_match_all('/<\\/*blockquote[^>]*>/i', $text, $matches, PREG_OFFSET_CAPTURE)) {
         // init
         $start = 0;
         $taglen = 0;
         $level = 0;
         $diff = 0;
         // convert preg offsets from bytes to characters
         foreach ($matches[0] as $index => $m) {
             $matches[0][$index][1] = UTF8::strlen(substr($text, 0, $m[1]));
         }
         foreach ($matches[0] as $m) {
             if ($m[0][0] == '<' && $m[0][1] == '/') {
                 $level--;
                 if ($level < 0) {
                     // malformed HTML: go to next blockquote
                     $level = 0;
                 } elseif ($level > 0) {
                     // skip inner blockquote
                 } else {
                     $end = $m[1];
                     $len = $end - $taglen - $start;
                     // get blockquote content
                     $body = UTF8::substr($text, $start + $taglen - $diff, $len);
                     // set text width
                     $pWidth = $this->options['width'];
                     if ($this->options['width'] > 0) {
                         $this->options['width'] -= 2;
                     }
                     // convert blockquote content
                     $this->converter($body);
                     // add citation markers
                     $body = preg_replace('/((^|\\n)>*)/', '\\1> ', UTF8::trim($body));
                     // create PRE block
                     $body = '<pre>' . UTF8::htmlspecialchars($body) . '</pre>';
                     // re-set text width
                     $this->options['width'] = $pWidth;
                     // replace content
                     $text = UTF8::substr($text, 0, $start - $diff) . $body . UTF8::substr($text, $end + UTF8::strlen($m[0]) - $diff);
                     $diff += $len + $taglen + UTF8::strlen($m[0]) - UTF8::strlen($body);
                     unset($body);
                 }
             } else {
                 if ($level == 0) {
                     $start = $m[1];
                     $taglen = UTF8::strlen($m[0]);
                 }
                 $level++;
             }
         }
     }
 }
Beispiel #2
0
 /**
  * escape html
  *
  * @return Stringy
  */
 public function escape()
 {
     $str = UTF8::htmlspecialchars($this->str, ENT_QUOTES | ENT_SUBSTITUTE, $this->encoding);
     return static::create($str, $this->encoding);
 }