def parseAutolink(self, block): """Attempt to parse an autolink (URL or email in pointy brackets).""" m = self.match(reEmailAutolink) if m: # email dest = m[1:-1] node = Node('link', None) node.destination = normalize_uri('mailto:' + dest) node.title = '' node.append_child(text(dest)) block.append_child(node) return True else: m = self.match(reAutolink) if m: # link dest = m[1:-1] node = Node('link', None) node.destination = normalize_uri(dest) node.title = '' node.append_child(text(dest)) block.append_child(node) return True return False
def parseAutolink(self, block): """Attempt to parse an autolink (URL or email in pointy brackets).""" m = self.match(reEmailAutolink) if m: # email dest = m[1:-1] node = Node('link', None) node.destination = normalize_uri('mailto:' + dest) node.title = '' node.append_child(text(dest)) block.append_child(node) return True else: m = self.match(reAutolink) if m: # link dest = m[1:-1] node = Node('link', None) node.destination = normalize_uri(dest) node.title = '' node.append_child(text(dest)) block.append_child(node) return True return False
def parseLinkDestination(self): """ Attempt to parse link destination, returning the string or None if no match. """ res = self.match(reLinkDestinationBraces) if res is None: # TODO handrolled parser; res should be None or the string savepos = self.pos openparens = 0 c = self.peek() while c is not None: if c == '\\': self.pos += 1 if self.peek() is not None: self.pos += 1 elif c == '(': self.pos += 1 openparens += 1 elif c == ')': if openparens < 1: break else: self.pos += 1 openparens -= 1 elif re.search(reWhitespaceChar, c): break else: self.pos += 1 c = self.peek() res = self.subject[savepos:self.pos] return normalize_uri(unescape_string(res)) else: # chop off surrounding <..>: return normalize_uri(unescape_string(res[1:-1]))
def parseLinkDestination(self): """ Attempt to parse link destination, returning the string or None if no match. """ res = self.match(reLinkDestinationBraces) if res is None: if self.peek() == '<': return None # TODO handrolled parser; res should be None or the string savepos = self.pos openparens = 0 while True: c = self.peek() if c is None: break if c == '\\' and re.search( reEscapable, self.subject[self.pos+1:self.pos+2]): self.pos += 1 if self.peek() is not None: self.pos += 1 elif c == '(': self.pos += 1 openparens += 1 elif c == ')': if openparens < 1: break else: self.pos += 1 openparens -= 1 elif re.search(reWhitespaceChar, c): break else: self.pos += 1 if self.pos == savepos and c != ')': return None res = self.subject[savepos:self.pos] return normalize_uri(unescape_string(res)) else: # chop off surrounding <..>: return normalize_uri(unescape_string(res[1:-1]))
def fixed_normalize_uri(uri): return common.normalize_uri(uri).replace("%7B", "{").replace("%7D", "}")