public static function filterOutElements($children, $lookup)
    {
        if (!is_array($lookup)) {
            $lookup = array($lookup => true);
        }

        // backward compatibility - ensure provided array is a lookup
        foreach ($lookup as $key => $value) {
            if (!is_string($key)) {
                unset($lookup[$key]);
                $lookup[$value] = true;
            }
        }

        $result = array();
        foreach ((array) $children as $child) {
            if ($child instanceof HTMLPurifier_Node_Element) {
                $filteredChildren = self::filterOutElements($child->children, $lookup);
                if (isset($lookup[$child->name])) {
                    // don't add removed element, only its children
                    foreach ($filteredChildren as $c) {
                        $result[] = $c;
                    }
                    continue;
                }
                $child->children = $filteredChildren;
            }
            $result[] = $child;
        }

        return $result;
    }