Example #1
0
    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
Example #2
0
    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
Example #3
0
 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.match(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]))
Example #4
0
 def parseLinkDestination(self):
     """
     Attempt to parse link destination, returning the string or
     None if no match.
     """
     res = self.match(reLinkDestinationBraces)
     if res is None:
         res = self.match(reLinkDestination)
         if res is None:
             return None
         else:
             return normalize_uri(unescape_string(res))
     else:
         # chop off surrounding <..>:
         return normalize_uri(unescape_string(res[1:-1]))
Example #5
0
 def parseLinkDestination(self):
     """
     Attempt to parse link destination, returning the string or
     None if no match.
     """
     res = self.match(reLinkDestinationBraces)
     if res is None:
         res = self.match(reLinkDestination)
         if res is None:
             return None
         else:
             return normalize_uri(unescape_string(res))
     else:
         # chop off surrounding <..>:
         return normalize_uri(unescape_string(res[1:-1]))