Skip to content

Instantly share code, notes, and snippets.

@bemasher
Created May 31, 2011 00:15
Show Gist options
  • Save bemasher/999663 to your computer and use it in GitHub Desktop.
Save bemasher/999663 to your computer and use it in GitHub Desktop.
Determines if an lxml element is between parenthesis (in text) or is italic (html)
def isValidLink(node):
parenth_re = re.compile("\([^\)]*?{}[^\(]*?\)".format(node.text), re.S)
parent_text = ''.join(map(lambda x: (x.text or "") + (x.tail or ""), node.getparent().getchildren()))
return parenth_re.search(parent_text) is not None and node.getparent().tag != "i"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment