def walk_tree(self, node): if node.tag == 'a': self.inurl = True if is_inner(node.get('href')): node.set('href', clean_inner(node.get('href'))) else: node.set('rel', 'nofollow') if node.tag == 'img': if is_inner(node.get('src')): node.set('src', '%s' % clean_inner(node.get('src'))) try: if self.inurl and node.text and is_url(node.text) and is_inner(node.text): node.text = clean_inner(node.text)[1:] except TypeError: pass for i in node: self.walk_tree(i) self.inurl = False
def parse_link(matchobj): link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matchobj.group(0).strip())) if href: if is_inner(href): clean = clean_inner(href) return self.markdown.htmlStash.store('<a href="%s">%s</a>' % (clean, clean[1:]), safe=True) else: return self.markdown.htmlStash.store('<a href="%(href)s" rel="nofollow">%(href)s</a>' % {'href': href}, safe=True) else: return matchobj.group(0)
def handleMatch(self, m): img_src = m.groups()[2].strip() if is_inner(img_src): img_src = self.sanitize_url(clean_inner(img_src)) if img_src: a = etree.Element("a") a.set('href', img_src) a.set('rel', 'nofollow') a.set('target', '_blank') img = etree.SubElement(a, "img") img.set('src', img_src) img.set('alt', img_src) return a
def handleMatch(self, m): img_src = m.groups()[2].strip() if is_inner(img_src): img_src = self.sanitize_url(clean_inner(img_src)) if img_src: a = etree.Element("a") a.set("href", img_src) a.set("rel", "nofollow") a.set("target", "_blank") img = etree.SubElement(a, "img") img.set("src", img_src) img.set("alt", img_src) return a
def walk_tree(self, node): if node.tag == "a": self.inurl = True if is_inner(node.get("href")): node.set("href", clean_inner(node.get("href"))) else: node.set("href", clean_outer(node.get("href"))) node.set("rel", "nofollow") if node.tag == "img": if is_inner(node.get("src")): node.set("src", "%s" % clean_inner(node.get("src"))) else: node.set("src", "%s" % clean_outer(node.get("src"))) try: if self.inurl and node.text and is_url(node.text) and is_inner(node.text): node.text = clean_inner(node.text)[1:] except TypeError: pass for i in node: self.walk_tree(i) self.inurl = False
def parse_link(matchobj): link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matchobj.group(0).strip())) if href: if is_inner(href): clean = clean_inner(href) return self.markdown.htmlStash.store( '<a href="%s">%s</a>' % (clean, clean[1:]), safe=True) else: return self.markdown.htmlStash.store( '<a href="%(href)s" rel="nofollow">%(href)s</a>' % {'href': href}, safe=True) else: return matchobj.group(0)
def parse_link(matchobj): matched_link = matchobj.group(0).strip() if matched_link[0] == '<': matched_link = matched_link[1:] if matched_link[-1] == '>': matched_link = matched_link[:-1] link = LinkPattern(MAGICLINKS_RE, self.markdown) href = link.sanitize_url(link.unescape(matched_link)) if href: if is_inner(href): clean = clean_inner(href) return self.markdown.htmlStash.store('<a href="%s">%s</a>' % (clean, clean[1:]), safe=True) else: clean = clean_outer(href) return self.markdown.htmlStash.store('<a href="%s" rel="nofollow">%s</a>' % (clean, href), safe=True) else: return matchobj.group(0)