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]))
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]))
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])
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