mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-07-12 02:06:18 +02:00
Add HTML_Generator class and associated unit tests.
git-svn-id: http://htmlpurifier.org/svnroot/html_purifier/trunk@32 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
37
HTML_Generator.php
Normal file
37
HTML_Generator.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
class HTML_Generator
|
||||
{
|
||||
|
||||
function generateFromToken($token) {
|
||||
if (is_a($token, 'MF_StartTag')) {
|
||||
$attr = $this->generateAttributes($token->attributes);
|
||||
return '<' . $token->name . ' ' . $attr . '>';
|
||||
|
||||
} elseif (is_a($token, 'MF_EndTag')) {
|
||||
return '</' . $token->name . '>';
|
||||
|
||||
} elseif (is_a($token, 'MF_EmptyTag')) {
|
||||
$attr = $this->generateAttributes($token->attributes);
|
||||
return '<' . $token->name . ' ' . $attr . ' />';
|
||||
|
||||
} elseif (is_a($token, 'MF_Text')) {
|
||||
return htmlentities($token->data, ENT_COMPAT, 'UTF-8');
|
||||
|
||||
} else {
|
||||
return '';
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function generateAttributes($assoc_array_of_attributes) {
|
||||
$html = '';
|
||||
foreach ($assoc_array_of_attributes as $key => $value) {
|
||||
$html .= $key.'="'.htmlentities($value, ENT_COMPAT, 'UTF-8').'" ';
|
||||
}
|
||||
return rtrim($html);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user