Esempio n. 1
0
 /**
  * 
  * 压缩文本
  */
 public function compressText($token)
 {
     $value = $token['value'];
     //如果文本中含有//,则不去除换行等,主要是一些异步接口(JS环境)会被识别成HTML环境,如果有JS的//注释就要注意了
     if (strpos($value, '//') !== false) {
         return $value;
     }
     if ($this->options['remove_newline']) {
         $value = str_replace(FL_NEWLINE, '', $value);
     } else {
         if ($this->options['newline_to_space']) {
             $value = str_replace(FL_NEWLINE, FL_SPACE, $value);
         }
     }
     $value = str_replace("\t", " ", $value);
     if ($this->options['replace_multi_space'] !== false) {
         $value = preg_replace(FL_SPACE_PATTERN, $this->options['replace_multi_space'], $value);
     }
     if ($this->options['remove_inter_tag_space']) {
         $value = rtrim($value);
     } elseif (Fl_Html_Static::isTag($this->nextToken)) {
         if (Fl_Html_Static::isSafeTag($this->nextToken['lowerTag'])) {
             $value = rtrim($value);
         } else {
             if ($this->options['remove_inter_block_tag_space'] && Fl_Html_Static::isBlockTag($this->nextToken['lowerTag'])) {
                 $value = rtrim($value);
             }
         }
     }
     return $value;
 }
Esempio n. 2
0
 /**
  * 
  * 判断当前的text是否可删除
  * @param string $text
  * @param array $nextToken
  */
 public function textCanRemove($text, $preToken = array(), $nextToken = array())
 {
     if ($this->options['removeBlockBlank'] && preg_match('/^\\s+$/', $text)) {
         $pregTag = $pregToken['lowerTag'];
         $nextTag = $nextToken['lowerTag'];
         if ($pregTag && Fl_Html_Static::isBlockTag($pregTag, $this->options['blockBlankList'])) {
             return true;
         }
         if ($nextTag && Fl_Html_Static::isBlockTag($nextTag, $this->options['blockBlankList'])) {
             return true;
         }
     }
     return false;
 }
Esempio n. 3
0
 /**
  * 
  * statement
  */
 public function statement()
 {
     if (empty($this->currentToken)) {
         return false;
     }
     switch ($this->currentToken['type']) {
         case FL_TOKEN_HTML_TAG_START:
             return $this->tagStartStatement();
         case FL_TOKEN_HTML_TAG_END:
             return false;
         case FL_TOKEN_HTML_PRE_TAG:
         case FL_TOKEN_HTML_SCRIPT_TAG:
         case FL_TOKEN_HTML_STYLE_TAG:
         case FL_TOKEN_HTML_TEXTAREA_TAG:
             return $this->specialStatement();
         case FL_TOKEN_HTML_TEXT:
             if (preg_match(FL_SPACE_ALL_PATTERN, $this->currentToken['value'])) {
                 if ($this->options['remove_blank_text']) {
                     return false;
                 }
                 if (count($this->inTags) && $this->options['remove_blank_text_in_block_tag']) {
                     $inTag = $this->inTags[count($this->inTags) - 1];
                     if (Fl_Html_Static::isBlockTag($inTag)) {
                         return false;
                     }
                 }
             }
             return array("type" => FL_TOKEN_HTML_TEXT, "value" => $this->getValue($this->currentToken));
         default:
             return array("type" => $this->currentToken['type'], "value" => $this->getValue($this->currentToken));
     }
 }