Ejemplo n.º 1
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.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]))
Ejemplo n.º 2
0
 def parseLinkTitle(self):
     """
     Attempt to parse link title (sans quotes), returning the string
     or None if no match.
     """
     title = self.match(reLinkTitle)
     if title is None:
         return None
     else:
         # chop off quotes from title and unescape:
         return unescape_string(title[1:-1])
Ejemplo n.º 3
0
 def parseLinkTitle(self):
     """
     Attempt to parse link title (sans quotes), returning the string
     or None if no match.
     """
     title = self.match(reLinkTitle)
     if title is None:
         return None
     else:
         # chop off quotes from title and unescape:
         return unescape_string(title[1:-1])
Ejemplo n.º 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:
         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]))
Ejemplo n.º 5
0
    def finalize(parser=None, block=None):
        if block.is_fenced:
            # first line becomes info string
            content = block.string_content
            newline_pos = content.index('\n')
            first_line = content[0:newline_pos]
            rest = content[newline_pos + 1:]
            block.info = unescape_string(first_line.strip())
            block.literal = rest
        else:
            # indented
            block.literal = re.sub(r'(\n *)+$', '\n', block.string_content)

        block.string_content = None
Ejemplo n.º 6
0
    def finalize(parser=None, block=None):
        if block.is_fenced:
            # first line becomes info string
            content = block.string_content
            newline_pos = content.index('\n')
            first_line = content[0:newline_pos]
            rest = content[newline_pos + 1:]
            block.info = unescape_string(first_line.strip())
            block.literal = rest
        else:
            # indented
            block.literal = re.sub(r'(\n *)+$', '\n', block.string_content)

        block.string_content = None