Created
May 31, 2011 00:15
-
-
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)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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