/** * * 压缩文本 */ 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; }
/** * * tag start statement */ public function tagStartStatement() { $token = $this->currentToken; $tag = strtolower(Fl_Html_Static::getTagName($token['value'], $this)); if (Fl_Html_Static::isSingleTag($tag)) { return array("type" => FL_TOKEN_HTML_SINGLE_TAG, "value" => $this->getValue($token)); } $result = array(); $this->inTags[] = $tag; $comment = array(); while ($this->currentToken) { $this->getNextToken(); if (Fl_Html_Static::isTag($this->currentToken)) { if (Fl_Html_Static::optionalTagUntil($tag, $this->currentToken, $this)) { $this->peekToken = $this->currentToken; if ($this->currentToken['type'] === FL_TOKEN_HTML_TAG_END) { $tagEnd = $this->currentToken; if ($tag === Fl_Html_Static::getTagName($this->currentToken['value'], $this)) { $this->getNextToken(); } } break; } } $re = $this->statement(); if ($re) { $result[] = $re; } } array_pop($this->inTags); return array("type" => FL_TOKEN_HTML_TAG, "tag" => $tag, "value" => $this->getValue($token), "children" => $result, "end" => $this->getValue($tagEnd)); }