public function setupContext($context = null) {
        $this->fragment = true;
        if ($context) {
            $context = $this->dom->createElementNS(self::NS_HTML, $context);
            /* 4.1. Set the HTML parser's tokenization  stage's content model
             * flag according to the context element, as follows: */
            switch ($context->tagName) {
                case 'title': case 'textarea':
                    $this->content_model = HTML5_Tokenizer::RCDATA;
                    break;
                case 'style': case 'script': case 'xmp': case 'iframe':
                case 'noembed': case 'noframes':
                    $this->content_model = HTML5_Tokenizer::CDATA;
                    break;
                case 'noscript':
                    // XSCRIPT: assuming scripting is enabled
                    $this->content_model = HTML5_Tokenizer::CDATA;
                    break;
                case 'plaintext':
                    $this->content_model = HTML5_Tokenizer::PLAINTEXT;
                    break;
            }
            /* 4.2. Let root be a new html element with no attributes. */
            $root = $this->dom->createElementNS(self::NS_HTML, 'html');
            $this->root = $root;
            /* 4.3 Append the element root to the Document node created above. */
            $this->dom->appendChild($root);
            /* 4.4 Set up the parser's stack of open elements so that it
             * contains just the single element root. */
            $this->stack = array($root);
            /* 4.5 Reset the parser's insertion mode appropriately. */
            $this->resetInsertionMode($context);
            /* 4.6 Set the parser's form element pointer  to the nearest node
             * to the context element that is a form element (going straight up
             * the ancestor chain, and including the element itself, if it is a
             * form element), or, if there is no such form element, to null. */
            $node = $context;
            do {
                if ($node->tagName === 'form') {
                    $this->form_pointer = $node;
                    break;
                }
            } while ($node = $node->parentNode);
        }
    }