70 $this->_scriptFix =
$config->get(
'Output.CommentScriptContents');
71 $this->_innerHTMLFix =
$config->get(
'Output.FixInnerHTML');
72 $this->_sortAttr =
$config->get(
'Output.SortAttr');
73 $this->_flashCompat =
$config->get(
'Output.FlashCompat');
74 $this->_def =
$config->getHTMLDefinition();
75 $this->_xhtml = $this->_def->doctype->xml;
91 for ($i = 0,
$size = count($tokens); $i <
$size; $i++) {
92 if ($this->_scriptFix && $tokens[$i]->name ===
'script'
104 if (extension_loaded(
'tidy') && $this->config->get(
'Output.TidyFormat')) {
110 'output-xhtml' => $this->_xhtml,
111 'show-body-only' =>
true,
112 'indent-spaces' => 2,
117 $tidy->cleanRepair();
118 $html = (string) $tidy;
122 if ($this->config->get(
'Core.NormalizeNewlines')) {
123 $nl = $this->config->get(
'Output.Newline');
128 $html = str_replace(
"\n", $nl, $html);
142 trigger_error(
'Cannot generate HTML from non-HTMLPurifier_Token object', E_USER_WARNING);
147 if ($this->_flashCompat) {
148 if ($token->name ==
"object") {
149 $flash =
new stdclass();
150 $flash->attr = $token->attr;
151 $flash->param = array();
152 $this->_flashStack[] = $flash;
155 return '<' . $token->name . ($attr ?
' ' :
'') . $attr .
'>';
159 if ($this->_flashCompat) {
160 if ($token->name ==
"object" && !empty($this->_flashStack)) {
164 return $_extra .
'</' . $token->name .
'>';
167 if ($this->_flashCompat && $token->name ==
"param" && !empty($this->_flashStack)) {
168 $this->_flashStack[count($this->_flashStack)-1]->param[$token->attr[
'name']] = $token->attr[
'value'];
171 return '<' . $token->name . ($attr ?
' ' :
'') . $attr .
172 ( $this->_xhtml ?
' /':
'' )
176 return $this->
escape($token->data, ENT_NOQUOTES);
179 return '<!--' . $token->data .
'-->';
199 $data = preg_replace(
'#//\s*$#',
'', $token->data);
200 return '<!--//--><![CDATA[//><!--' .
"\n" . trim($data) .
"\n" .
'//--><!]]>';
214 if ($this->_sortAttr) {
215 ksort($assoc_array_of_attributes);
217 foreach ($assoc_array_of_attributes as $key => $value) {
218 if (!$this->_xhtml) {
220 if (strpos($key,
':') !==
false) {
224 if ($element && !empty($this->_def->info[$element]->attr[$key]->minimized)) {
250 if ($this->_innerHTMLFix) {
251 if (strpos($value,
'`') !==
false) {
254 if (strcspn($value,
'"\' <>') === strlen($value)) {
260 $html .= $key.
'="'.$this->
escape($value).
'" ';
275 public function escape($string, $quote = null)
279 if ($quote === null) {
282 return htmlspecialchars($string, $quote,
'UTF-8');