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');
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)) {
275 public function escape($string, $quote =
null)
279 if ($quote ===
null) {
282 return htmlspecialchars($string, $quote,
'UTF-8');
Generates HTML from tokens.
$_scriptFix
:HACK: Whether or not generator should comment the insides of <script> tags.
generateScriptFromToken($token)
Special case processor for the contents of script tags.
$_innerHTMLFix
Cache of Output.FixInnerHTML.
$config
Configuration for the generator @type HTMLPurifier_Config.
$_sortAttr
Cache of Output.SortAttr.
generateFromToken($token)
Generates HTML from a single token.
generateFromTokens($tokens)
Generates HTML from an array of tokens.
generateAttributes($assoc_array_of_attributes, $element='')
Generates attribute declarations from attribute array.
escape($string, $quote=null)
Escapes raw text data.
$_xhtml
Whether or not generator should produce XML output.
$_flashStack
Stack for keeping track of object information when outputting IE compatibility code.
__construct($config, $context)
$_flashCompat
Cache of Output.FlashCompat.
$_def
Cache of HTMLDefinition during HTML output to determine whether or not attributes should be minimized...
Concrete empty token class.
Concrete end token class.
Concrete start token class.
Concrete text token class.
Abstract base token class that all others inherit from.