def add_node(self, node, toc, ancestor_map): from calibre.ebooks.chm.reader import match_string if match_string(node.attrib.get('type', ''), 'text/sitemap'): p = node.xpath('ancestor::ul[1]/ancestor::li[1]/object[1]') parent = p[0] if p else None toc = ancestor_map.get(parent, toc) title = href = '' for param in node.xpath('./param'): if match_string(param.attrib['name'], 'name'): title = param.attrib['value'] elif match_string(param.attrib['name'], 'local'): href = param.attrib['value'] child = toc.add(title or _('Unknown'), href) ancestor_map[node] = child
def add_node(self, node, toc, ancestor_map): from calibre.ebooks.chm.reader import match_string if match_string(node.attrib['type'], 'text/sitemap'): p = node.xpath('ancestor::ul[1]/ancestor::li[1]/object[1]') parent = p[0] if p else None toc = ancestor_map.get(parent, toc) title = href = u'' for param in node.xpath('./param'): if match_string(param.attrib['name'], 'name'): title = param.attrib['value'] elif match_string(param.attrib['name'], 'local'): href = param.attrib['value'] child = toc.add(title or _('Unknown'), href) ancestor_map[node] = child
def _visit_node(self, node, chapters, depth): # check that node is a normal node (not a comment, DOCTYPE, etc.) # (normal nodes have string tags) if isinstance(node.tag, basestring): from calibre.ebooks.chm.reader import match_string chapter_path = None if match_string(node.tag, 'object') and match_string(node.attrib['type'], 'text/sitemap'): chapter_title = None for child in node: if match_string(child.tag,'param') and match_string(child.attrib['name'], 'name'): chapter_title = child.attrib['value'] if match_string(child.tag,'param') and match_string(child.attrib['name'],'local'): chapter_path = child.attrib['value'] if chapter_title is not None and chapter_path is not None: chapter = [chapter_title, chapter_path, depth] chapters.append(chapter) if node.tag=="UL": depth = depth + 1 if node.tag=="/UL": depth = depth - 1
def _visit_node(self, node, chapters, depth): # check that node is a normal node (not a comment, DOCTYPE, etc.) # (normal nodes have string tags) if isinstance(node.tag, basestring): from calibre.ebooks.chm.reader import match_string chapter_path = None if match_string(node.tag, 'object') and match_string( node.attrib['type'], 'text/sitemap'): chapter_title = None for child in node: if match_string(child.tag, 'param') and match_string( child.attrib['name'], 'name'): chapter_title = child.attrib['value'] if match_string(child.tag, 'param') and match_string( child.attrib['name'], 'local'): chapter_path = child.attrib['value'] if chapter_title is not None and chapter_path is not None: chapter = [chapter_title, chapter_path, depth] chapters.append(chapter) if node.tag == "UL": depth = depth + 1 if node.tag == "/UL": depth = depth - 1