# Splits the rst .html output in various .html files # Copyright (C) 2009 David Capello from xml.dom import Node from xml.dom.minidom import parse, parseString def getElementById(node, id): if node.hasAttribute("id") and node.getAttribute("id") == id: return node for child in node.childNodes: if child.nodeType == Node.ELEMENT_NODE: found = getElementById(child, id) if found: return found return None def remapAHref(node, old, new): if node.tagName == "a" and node.hasAttribute("href") and node.getAttribute("href") == old: node.setAttribute("href", new) for child in node.childNodes: if child.nodeType == Node.ELEMENT_NODE: remapAHref(child, old, new) def collectIdsInSection(node, ids, section): if section: if node.hasAttribute("id"): ids.append([ section, node.getAttribute("id") ]) elif node.tagName == "div" and \ ( node.hasAttribute("class") and node.getAttribute("class") == "section") or \ ( node.hasAttribute("id") and node.getAttribute("id") == "contents"): if node.getAttribute("id") == "contents": section = "index" else: section = node.getAttribute("id") for child in node.childNodes: if child.nodeType == Node.ELEMENT_NODE: collectIdsInSection(child, ids, section) def splitSection(doc, sectionId, removePrevs, outputFileName, idsToRemap): # clone the whole document doc2 = doc.cloneNode(True) # get the