Mercurial > libervia-backend
comparison frontends/src/tools/strings.py @ 1879:b43ee22eac98
frontends (tools/strings): fixXHTMLLinks skips internal anchors (links starting with "#")
fix bug 126
author | souliane <souliane@mailoo.org> |
---|---|
date | Sat, 05 Mar 2016 13:58:02 +0100 |
parents | 07390a9d1c09 |
children | 2daf7b4c6756 |
comparison
equal
deleted
inserted
replaced
1878:7a07f232e7cb | 1879:b43ee22eac98 |
---|---|
82 """ | 82 """ |
83 subs = [] | 83 subs = [] |
84 for match in re.finditer(r'<a( \w+="[^"]*")* ?/?>', xhtml): | 84 for match in re.finditer(r'<a( \w+="[^"]*")* ?/?>', xhtml): |
85 tag = match.group(0) | 85 tag = match.group(0) |
86 url = re.search(r'href="([^"]*)"', tag) | 86 url = re.search(r'href="([^"]*)"', tag) |
87 if url: | 87 if url and not url.group(1).startswith("#"): # skip internal anchor |
88 if not re.search(r'target="([^"]*)"', tag): # no target | 88 if not re.search(r'target="([^"]*)"', tag): # no target |
89 subs.append((tag, '<a target="_blank"%s' % tag[2:])) | 89 subs.append((tag, '<a target="_blank"%s' % tag[2:])) |
90 if not re.match(r"^\w+://", url.group(1)): # no scheme | 90 if not re.match(r"^\w+://", url.group(1)): # no scheme |
91 subs.append((url.group(0), 'href="http://%s"' % url.group(1))) | 91 subs.append((url.group(0), 'href="http://%s"' % url.group(1))) |
92 | 92 |