mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2025-08-05 13:47:24 +02:00
Rename Lexer, separate files. Also augmented benchmarks and benchmarker,
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@79 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
Forgivingly lexes SGML style documents, aka HTML, XML, XHMTML, you name it.
|
||||
|
||||
TODO:
|
||||
* Reread the XML spec and make sure I got everything right
|
||||
@@ -12,9 +11,9 @@ TODO:
|
||||
|
||||
*/
|
||||
|
||||
require_once 'HTMLPurifier/Token.php';
|
||||
require_once 'HTMLPurifier/Lexer.php';
|
||||
|
||||
class HTMLPurifier_Lexer
|
||||
class HTMLPurifier_Lexer_DirectLex extends HTMLPurifier_Lexer
|
||||
{
|
||||
|
||||
// does this version of PHP support utf8 as entity function charset?
|
||||
@@ -94,7 +93,7 @@ class HTMLPurifier_Lexer
|
||||
function tokenizeHTML($string) {
|
||||
|
||||
// some quick checking (if empty, return empty)
|
||||
$string = (string) $string;
|
||||
$string = @ (string) $string;
|
||||
if ($string == '') return array();
|
||||
|
||||
$cursor = 0; // our location in the text
|
||||
@@ -343,57 +342,4 @@ class HTMLPurifier_Lexer
|
||||
|
||||
}
|
||||
|
||||
// uses the PEAR class XML_HTMLSax3 to parse XML
|
||||
// only shares the tokenizeHTML() function
|
||||
class HTMLPurifier_Lexer_Sax extends HTMLPurifier_Lexer
|
||||
{
|
||||
|
||||
var $tokens = array();
|
||||
|
||||
function tokenizeHTML($html) {
|
||||
$this->tokens = array();
|
||||
$parser=& new XML_HTMLSax3();
|
||||
$parser->set_object($this);
|
||||
$parser->set_element_handler('openHandler','closeHandler');
|
||||
$parser->set_data_handler('dataHandler');
|
||||
$parser->set_escape_handler('escapeHandler');
|
||||
$parser->set_option('XML_OPTION_ENTITIES_PARSED', 1);
|
||||
$parser->parse($html);
|
||||
return $this->tokens;
|
||||
}
|
||||
|
||||
function openHandler(&$parser, $name, $attrs, $closed) {
|
||||
if ($closed) {
|
||||
$this->tokens[] = new HTMLPurifier_Token_Empty($name, $attrs);
|
||||
} else {
|
||||
$this->tokens[] = new HTMLPurifier_Token_Start($name, $attrs);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
function closeHandler(&$parser, $name) {
|
||||
// HTMLSax3 seems to always send empty tags an extra close tag
|
||||
// check and ignore if you see it:
|
||||
// [TESTME] to make sure it doesn't overreach
|
||||
if ($this->tokens[count($this->tokens)-1]->type == 'empty') {
|
||||
return true;
|
||||
}
|
||||
$this->tokens[] = new HTMLPurifier_Token_End($name);
|
||||
return true;
|
||||
}
|
||||
|
||||
function dataHandler(&$parser, $data) {
|
||||
$this->tokens[] = new HTMLPurifier_Token_Text($data);
|
||||
return true;
|
||||
}
|
||||
|
||||
function escapeHandler(&$parser, $data) {
|
||||
if (strpos($data, '-') === 0) {
|
||||
$this->tokens[] = new HTMLPurifier_Token_Comment($data);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Reference in New Issue
Block a user