mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-11-09 23:28:42 +00:00
Convert injector to use arrays.
git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1214 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
parent
e5191b3ada
commit
389fcc9a5d
@ -5,6 +5,7 @@ require_once 'HTMLPurifier/Injector.php';
|
||||
/**
|
||||
* Injector that auto paragraphs text in the root node based on
|
||||
* double-spacing.
|
||||
* @todo Don't assume that root node means paragraphing is alright
|
||||
*/
|
||||
class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector
|
||||
{
|
||||
|
@ -40,11 +40,12 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
||||
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
||||
$auto_paragraph = $config->get('Core', 'AutoParagraph');
|
||||
|
||||
$auto_paragraph_skip = 0;
|
||||
$auto_paragraph_disabled = false;
|
||||
$context->register('AutoParagraphSkip', $auto_paragraph_skip);
|
||||
$injector = array();
|
||||
$injector['AutoParagraph'] = new HTMLPurifier_Injector_AutoParagraph();
|
||||
$injector_skip['AutoParagraph'] = 0;
|
||||
$injector_disabled['AutoParagraph'] = false;
|
||||
|
||||
$injector = new HTMLPurifier_Injector_AutoParagraph();
|
||||
$context->register('InjectorSkip', $injector_skip);
|
||||
|
||||
for ($tokens_index = 0; isset($tokens[$tokens_index]); $tokens_index++) {
|
||||
|
||||
@ -52,19 +53,19 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
||||
$token = $tokens[$tokens_index];
|
||||
|
||||
// this will be more complicated
|
||||
if ($auto_paragraph_skip > 0) {
|
||||
$auto_paragraph_skip--;
|
||||
$auto_paragraph_disabled = true;
|
||||
if ($injector_skip['AutoParagraph'] > 0) {
|
||||
$injector_skip['AutoParagraph']--;
|
||||
$injector_disabled['AutoParagraph'] = true;
|
||||
} else {
|
||||
$auto_paragraph_disabled = false;
|
||||
$injector_disabled['AutoParagraph'] = false;
|
||||
}
|
||||
|
||||
// quick-check: if it's not a tag, no need to process
|
||||
if (empty( $token->is_tag )) {
|
||||
|
||||
if ($token->type === 'text') {
|
||||
if ($auto_paragraph && !$auto_paragraph_disabled) {
|
||||
$injector->handleText($token, $config, $context);
|
||||
if ($auto_paragraph && !$injector_disabled['AutoParagraph']) {
|
||||
$injector['AutoParagraph']->handleText($token, $config, $context);
|
||||
}
|
||||
}
|
||||
|
||||
@ -116,8 +117,8 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
||||
$current_nesting[] = $parent; // undo the pop
|
||||
}
|
||||
|
||||
if ($auto_paragraph && !$auto_paragraph_disabled) {
|
||||
$injector->handleStart($token, $config, $context);
|
||||
if ($auto_paragraph && !$injector_disabled['AutoParagraph']) {
|
||||
$injector['AutoParagraph']->handleStart($token, $config, $context);
|
||||
}
|
||||
|
||||
$this->processToken($token, $config, $context);
|
||||
@ -213,8 +214,8 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
||||
|
||||
// this will be a bit more complicated when we add more formatters
|
||||
// we need to prevent the same formatter from running twice on it
|
||||
$auto_paragraph_skip =& $context->get('AutoParagraphSkip');
|
||||
$auto_paragraph_skip = count($token);
|
||||
$injector_skip =& $context->get('InjectorSkip');
|
||||
$injector_skip['AutoParagraph'] = count($token);
|
||||
|
||||
} elseif ($token) {
|
||||
// regular case
|
||||
|
Loading…
Reference in New Issue
Block a user