1
0
mirror of https://github.com/ezyang/htmlpurifier.git synced 2025-08-06 14:16:32 +02:00

Refactor MakeWellFormed/Injector for performance and as little code duplication as possible. Also, make AutoParagraph smarter about root nodes that don't like p tags.

git-svn-id: http://htmlpurifier.org/svnroot/htmlpurifier/trunk@1221 48356398-32a2-884e-a903-53898d9a118a
This commit is contained in:
Edward Z. Yang
2007-06-24 17:44:27 +00:00
parent 75e52a12a6
commit 5f0663cad7
5 changed files with 169 additions and 128 deletions

View File

@@ -9,28 +9,17 @@ class HTMLPurifier_Injector_Linkify extends HTMLPurifier_Injector
{
function handleText(&$token, $config, &$context) {
$current_nesting =& $context->get('CurrentNesting');
// this snippet could be factored out
$definition = $config->getHTMLDefinition();
if (!empty($current_nesting)) {
$parent_token = array_pop($current_nesting);
$current_nesting[] = $parent_token;
$parent = $definition->info[$parent_token->name];
} else {
$parent = $definition->info_parent_def;
}
if (!isset($parent->child->elements['a']) || isset($parent->excludes['a'])) {
// parent element does not allow link elements, don't bother
return;
}
if (!$this->allowsElement('a')) return;
if (strpos($token->data, '://') === false) {
// our really quick heuristic failed, abort
// this may not work so well if we want to match things like
// "google.com"
// "google.com", but then again, most people don't
return;
}
// there is/are URL(s). Let's split the string:
// Note: this regex is extremely permissive
$bits = preg_split('#((?:https?|ftp)://[^\s\'"<>()]+)#S', $token->data, -1, PREG_SPLIT_DELIM_CAPTURE);
$token = array();