mirror of
https://github.com/ezyang/htmlpurifier.git
synced 2024-12-22 16:31:53 +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
|
* Injector that auto paragraphs text in the root node based on
|
||||||
* double-spacing.
|
* double-spacing.
|
||||||
|
* @todo Don't assume that root node means paragraphing is alright
|
||||||
*/
|
*/
|
||||||
class HTMLPurifier_Injector_AutoParagraph extends HTMLPurifier_Injector
|
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');
|
$escape_invalid_tags = $config->get('Core', 'EscapeInvalidTags');
|
||||||
$auto_paragraph = $config->get('Core', 'AutoParagraph');
|
$auto_paragraph = $config->get('Core', 'AutoParagraph');
|
||||||
|
|
||||||
$auto_paragraph_skip = 0;
|
$injector = array();
|
||||||
$auto_paragraph_disabled = false;
|
$injector['AutoParagraph'] = new HTMLPurifier_Injector_AutoParagraph();
|
||||||
$context->register('AutoParagraphSkip', $auto_paragraph_skip);
|
$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++) {
|
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];
|
$token = $tokens[$tokens_index];
|
||||||
|
|
||||||
// this will be more complicated
|
// this will be more complicated
|
||||||
if ($auto_paragraph_skip > 0) {
|
if ($injector_skip['AutoParagraph'] > 0) {
|
||||||
$auto_paragraph_skip--;
|
$injector_skip['AutoParagraph']--;
|
||||||
$auto_paragraph_disabled = true;
|
$injector_disabled['AutoParagraph'] = true;
|
||||||
} else {
|
} else {
|
||||||
$auto_paragraph_disabled = false;
|
$injector_disabled['AutoParagraph'] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// quick-check: if it's not a tag, no need to process
|
// quick-check: if it's not a tag, no need to process
|
||||||
if (empty( $token->is_tag )) {
|
if (empty( $token->is_tag )) {
|
||||||
|
|
||||||
if ($token->type === 'text') {
|
if ($token->type === 'text') {
|
||||||
if ($auto_paragraph && !$auto_paragraph_disabled) {
|
if ($auto_paragraph && !$injector_disabled['AutoParagraph']) {
|
||||||
$injector->handleText($token, $config, $context);
|
$injector['AutoParagraph']->handleText($token, $config, $context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,8 +117,8 @@ class HTMLPurifier_Strategy_MakeWellFormed extends HTMLPurifier_Strategy
|
|||||||
$current_nesting[] = $parent; // undo the pop
|
$current_nesting[] = $parent; // undo the pop
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($auto_paragraph && !$auto_paragraph_disabled) {
|
if ($auto_paragraph && !$injector_disabled['AutoParagraph']) {
|
||||||
$injector->handleStart($token, $config, $context);
|
$injector['AutoParagraph']->handleStart($token, $config, $context);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->processToken($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
|
// this will be a bit more complicated when we add more formatters
|
||||||
// we need to prevent the same formatter from running twice on it
|
// we need to prevent the same formatter from running twice on it
|
||||||
$auto_paragraph_skip =& $context->get('AutoParagraphSkip');
|
$injector_skip =& $context->get('InjectorSkip');
|
||||||
$auto_paragraph_skip = count($token);
|
$injector_skip['AutoParagraph'] = count($token);
|
||||||
|
|
||||||
} elseif ($token) {
|
} elseif ($token) {
|
||||||
// regular case
|
// regular case
|
||||||
|
Loading…
Reference in New Issue
Block a user