'Main (private) function which converts Problem XML tree to HTML.
Calls itself recursively.
Returns Element tree of XHTML representation of problemtree.
Calls render_html of Response instances to render responses into XHTML.
Used by get_html.'

def _extract_html(self, problemtree):

    if (not isinstance(problemtree.tag, basestring)):
        return
    if ((problemtree.tag == 'script') and problemtree.get('type') and ('javascript' in problemtree.get('type'))):
        return deepcopy(problemtree)
    if (problemtree.tag in html_problem_semantics):
        return
    problemid = problemtree.get('id')
    if (problemtree.tag in inputtypes.registry.registered_tags()):
        response_data = self.problem_data[problemid]
        status = 'unsubmitted'
        msg = ''
        hint = ''
        hintmode = None
        input_id = problemtree.get('id')
        answervariable = None
        if (problemid in self.correct_map):
            pid = input_id
            if (not self.capa_module.correctness_available()):
                status = 'submitted'
            else:
                if (not self.has_saved_answers):
                    status = self.correct_map.get_correctness(pid)
                    msg = self.correct_map.get_msg(pid)
                hint = self.correct_map.get_hint(pid)
                hintmode = self.correct_map.get_hintmode(pid)
                answervariable = self.correct_map.get_property(pid, 'answervariable')
        value = ''
        if (self.student_answers and (problemid in self.student_answers)):
            value = self.student_answers[problemid]
        if (input_id not in self.input_state):
            self.input_state[input_id] = {}
        state = {'value': value, 'status': status, 'id': input_id, 'input_state': self.input_state[input_id], 'answervariable': answervariable, 'response_data': response_data, 'has_saved_answers': self.has_saved_answers, 'feedback': {'message': msg, 'hint': hint, 'hintmode': hintmode}}
        input_type_cls = inputtypes.registry.get_class_for_tag(problemtree.tag)
        self.inputs[input_id] = input_type_cls(self.capa_system, problemtree, state)
        return self.inputs[input_id].get_html()
    if (problemtree in self.responders):
        overall_msg = self.correct_map.get_overall_message()
        return self.responders[problemtree].render_html(self._extract_html, response_msg=overall_msg)
    if (problemtree.tag in customrender.registry.registered_tags()):
        renderer_class = customrender.registry.get_class_for_tag(problemtree.tag)
        renderer = renderer_class(self.capa_system, problemtree)
        return renderer.get_html()
    tree = etree.Element(problemtree.tag)
    for item in problemtree:
        item_xhtml = self._extract_html(item)
        if (item_xhtml is not None):
            tree.append(item_xhtml)
    if (tree.tag in html_transforms):
        tree.tag = html_transforms[problemtree.tag]['tag']
    else:
        for (key, value) in problemtree.items():
            tree.set(key, value)
    tree.text = problemtree.text
    tree.tail = problemtree.tail
    return tree
