45 $this->_scriptFix =
$config->get(
'Output.CommentScriptContents');
46 $this->_sortAttr =
$config->get(
'Output.SortAttr');
47 $this->_def =
$config->getHTMLDefinition();
48 $this->_xhtml = $this->_def->doctype->xml;
58 if (!$tokens)
return '';
62 for ($i = 0, $size = count($tokens); $i < $size; $i++) {
63 if ($this->_scriptFix && $tokens[$i]->name ===
'script'
75 if (extension_loaded(
'tidy') && $this->config->get(
'Output.TidyFormat')) {
77 $tidy->parseString($html, array(
79 'output-xhtml' => $this->_xhtml,
80 'show-body-only' =>
true,
85 $html = (string)
$tidy;
89 $nl = $this->config->get(
'Output.Newline');
90 if ($nl === null) $nl = PHP_EOL;
91 if ($nl !==
"\n") $html = str_replace(
"\n", $nl, $html);
102 trigger_error(
'Cannot generate HTML from non-HTMLPurifier_Token object', E_USER_WARNING);
107 return '<' . $token->name . ($attr ?
' ' :
'') . $attr .
'>';
110 return '</' . $token->name .
'>';
114 return '<' . $token->name . ($attr ?
' ' :
'') . $attr .
115 ( $this->_xhtml ?
' /':
'' )
119 return $this->
escape($token->data, ENT_NOQUOTES);
122 return '<!--' . $token->data .
'-->';
137 $data = preg_replace(
'#//\s*$#',
'', $token->data);
138 return '<!--//--><![CDATA[//><!--' .
"\n" . trim(
$data) .
"\n" .
'//--><!]]>';
151 if ($this->_sortAttr) ksort($assoc_array_of_attributes);
152 foreach ($assoc_array_of_attributes as $key => $value) {
153 if (!$this->_xhtml) {
155 if (strpos($key,
':') !==
false)
continue;
157 if ($element && !empty($this->_def->info[$element]->attr[$key]->minimized)) {
162 $html .= $key.
'="'.$this->
escape($value).
'" ';
177 public function escape($string, $quote = ENT_COMPAT) {
178 return htmlspecialchars($string, $quote,
'UTF-8');