61 $this->_scriptFix =
$config->get(
'Output.CommentScriptContents');
62 $this->_innerHTMLFix =
$config->get(
'Output.FixInnerHTML');
63 $this->_sortAttr =
$config->get(
'Output.SortAttr');
64 $this->_flashCompat =
$config->get(
'Output.FlashCompat');
65 $this->_def =
$config->getHTMLDefinition();
66 $this->_xhtml = $this->_def->doctype->xml;
76 if (!$tokens)
return '';
80 for ($i = 0,
$size = count($tokens); $i <
$size; $i++) {
81 if ($this->_scriptFix && $tokens[$i]->name ===
'script'
93 if (extension_loaded(
'tidy') && $this->config->get(
'Output.TidyFormat')) {
95 $tidy->parseString($html, array(
97 'output-xhtml' => $this->_xhtml,
98 'show-body-only' =>
true,
102 $tidy->cleanRepair();
103 $html = (string) $tidy;
107 if ($this->config->get(
'Core.NormalizeNewlines')) {
108 $nl = $this->config->get(
'Output.Newline');
109 if ($nl === null) $nl = PHP_EOL;
110 if ($nl !==
"\n") $html = str_replace(
"\n", $nl, $html);
122 trigger_error(
'Cannot generate HTML from non-HTMLPurifier_Token object', E_USER_WARNING);
127 if ($this->_flashCompat) {
128 if ($token->name ==
"object") {
129 $flash =
new stdclass();
130 $flash->attr = $token->attr;
131 $flash->param = array();
132 $this->_flashStack[] = $flash;
135 return '<' . $token->name . ($attr ?
' ' :
'') . $attr .
'>';
139 if ($this->_flashCompat) {
140 if ($token->name ==
"object" && !empty($this->_flashStack)) {
144 return $_extra .
'</' . $token->name .
'>';
147 if ($this->_flashCompat && $token->name ==
"param" && !empty($this->_flashStack)) {
148 $this->_flashStack[count($this->_flashStack)-1]->param[$token->attr[
'name']] = $token->attr[
'value'];
151 return '<' . $token->name . ($attr ?
' ' :
'') . $attr .
152 ( $this->_xhtml ?
' /':
'' )
156 return $this->
escape($token->data, ENT_NOQUOTES);
159 return '<!--' . $token->data .
'-->';
174 $data = preg_replace(
'#//\s*$#',
'', $token->data);
175 return '<!--//--><![CDATA[//><!--' .
"\n" . trim(
$data) .
"\n" .
'//--><!]]>';
188 if ($this->_sortAttr) ksort($assoc_array_of_attributes);
189 foreach ($assoc_array_of_attributes as $key => $value) {
190 if (!$this->_xhtml) {
192 if (strpos($key,
':') !==
false)
continue;
194 if ($element && !empty($this->_def->info[$element]->attr[$key]->minimized)) {
220 if ($this->_innerHTMLFix) {
221 if (strpos($value,
'`') !==
false) {
224 if (strcspn($value,
'"\' <>') === strlen($value)) {
230 $html .= $key.
'="'.$this->
escape($value).
'" ';
245 public function escape($string, $quote = null) {
248 if ($quote === null) $quote = ENT_COMPAT;
249 return htmlspecialchars($string, $quote,
'UTF-8');