def getFirstAncestorWithSectionHeader(entry): """Go up ancestors until one with at least one <h2> is found, then return the <h2> nodes""" for a in domhelpers.getParents(entry)[1:]: headers = domhelpers.findNodesNamed(a, "h2") if len(headers) > 0: return headers return []
def test_getParents(self): doc1=microdom.parseString('<a><b><c><d/></c><e/></b><f/></a>') node_list=domhelpers.getParents(doc1.childNodes[0].childNodes[0].childNodes[0]) actual=''.join([node.tagName for node in node_list if hasattr(node, 'tagName')]) expected='cba' assert actual==expected, 'expected %s, got %s' % (expected, actual)
def test_getParents(self): doc1 = self.dom.parseString('<a><b><c><d/></c><e/></b><f/></a>') node_list = domhelpers.getParents( doc1.childNodes[0].childNodes[0].childNodes[0]) actual = ''.join( [node.tagName for node in node_list if hasattr(node, 'tagName')]) self.assertEqual(actual, 'cba')
def test_getParents(self): doc1 = self.dom.parseString('<a><b><c><d/></c><e/></b><f/></a>') node_list = domhelpers.getParents( doc1.childNodes[0].childNodes[0].childNodes[0]) actual = ''.join([node.tagName for node in node_list if hasattr(node, 'tagName')]) self.assertEqual(actual, 'cba')
def makeBook(dom, d): body = microdom.Element('body') body.appendChild(domhelpers.findNodesNamed(dom, 'h1')[0]) toc = domhelpers.findElementsWithAttribute(dom, 'class', 'toc')[0] toc = domhelpers.findNodesNamed(toc, 'li') for node in toc: if (node.hasAttribute('class') and node.getAttribute('class')=='tocignore'): continue parents = domhelpers.getParents(node) nodeLevel = len([1 for parent in parents if hasattr(parent, 'tagName') and parent.tagName in ('ol', 'ul')]) data = node.childNodes[0].data != '' if not data: node = node.childNodes[1] newNode = lowerDocument(node.getAttribute('href'), d, nodeLevel) for child in newNode.childNodes: body.appendChild(child) else: text = microdom.Text(node.childNodes[0].data) newNode = microdom.Element('h'+str(nodeLevel)) newNode.appendChild(text) body.appendChild(newNode) origBody = domhelpers.findNodesNamed(dom, 'body')[0] origBody.parentNode.replaceChild(body, origBody)
def test_getParents(self): doc1 = microdom.parseString('<a><b><c><d/></c><e/></b><f/></a>') node_list = domhelpers.getParents( doc1.childNodes[0].childNodes[0].childNodes[0]) actual = ''.join( [node.tagName for node in node_list if hasattr(node, 'tagName')]) expected = 'cba' assert actual == expected, 'expected %s, got %s' % (expected, actual)
def visitNode_title(self, node): self.writer('@node ') self.visitNodeDefault(node) self.writer('\n') self.writer('@section ') self.visitNodeDefault(node) self.writer('\n') headers = tree.getHeaders(domhelpers.getParents(node)[-1]) if not headers: return self.writer('@menu\n') for header in headers: self.writer('* %s::\n' % domhelpers.getNodeText(header)) self.writer('@end menu\n')
def getFirstAncestorWithSectionHeader(entry): """ Visit the ancestors of C{entry} until one with at least one C{h2} child node is found, then return all of that node's C{h2} child nodes. @type entry: A DOM Node @param entry: The node from which to begin traversal. This node itself is excluded from consideration. @rtype: C{list} of DOM Nodes @return: All C{h2} nodes of the ultimately selected parent node. """ for a in domhelpers.getParents(entry)[1:]: headers = domhelpers.findNodesNamed(a, "h2") if len(headers) > 0: return headers return []
def matcher(node): return ('"' in getattr(node, 'data', '') and not isinstance(node, dom.Comment) and not [ 1 for n in domhelpers.getParents(node)[1:-1] if n.tagName in ('pre', 'code') ])
def matcher(node): return ('"' in getattr(node, 'data', '') and not isinstance(node, microdom.Comment) and not [1 for n in domhelpers.getParents(node)[1:-1] if n.tagName in ('pre', 'code')])
def matcher(node): return ( '"' in getattr(node, "data", "") and not isinstance(node, dom.Comment) and not [1 for n in domhelpers.getParents(node)[1:-1] if n.tagName in ("pre", "code")] )