# HG changeset patch # User souliane # Date 1452857254 -3600 # Node ID 07390a9d1c098f0a54c9aa0a0ac49587d6911e19 # Parent 5f4d688d8b6eb5ad9788de2c92e36967fe155df4 tools (strings): add method fixXHTMLLinks to add a scheme if missing, and force opening in new tab diff -r 5f4d688d8b6e -r 07390a9d1c09 frontends/src/tools/strings.py --- a/frontends/src/tools/strings.py Wed Jan 13 22:10:06 2016 +0100 +++ b/frontends/src/tools/strings.py Fri Jan 15 12:27:34 2016 +0100 @@ -18,6 +18,7 @@ # along with this program. If not, see . import re +from feed.atom import Content def getURLParams(url): @@ -72,3 +73,24 @@ return '%s' % (url, match.group(0)) pattern = r"""]* src="([^"]+)"[^>]*>""" return re.sub(pattern, repl, string) + + +def fixXHTMLLinks(xhtml): + """Add http:// if the scheme is missing and force opening in a new window. + + @param string (unicode): XHTML Content + """ + subs = [] + for match in re.finditer(r'', xhtml): + tag = match.group(0) + url = re.search(r'href="([^"]*)"', tag) + if url: + if not re.search(r'target="([^"]*)"', tag): # no target + subs.append((tag, '