Beispiel #1
0
    def parse_link_title(self, reader: MultiLineReader, node: Element) -> str:
        try:
            # try parsing link destination on following line
            if reader.eol():
                reader.readline()

            matched = reader.consume(self.title_pattern)
            if not matched:
                return None

            title = matched.group(1)
            quote = title[0]
            following_pattern = re.compile(r"^((" + ESCAPED_CHARS +
                                           r"|[^%s])*(?:\%s|$))" %
                                           (quote, quote))

            while not matched.group(1).endswith(quote):
                # link title on multiple line
                reader.readline()
                matched = reader.consume(following_pattern)
                if not matched:
                    return None
                elif matched.group(1) == '\n':  # empty line
                    return None
                else:
                    title += matched.group(1)

            return unescape(entitytrans._unescape(title[1:-1]))
        except IOError:
            return None
Beispiel #2
0
    def run(self, reader: LineReader, document: Element) -> bool:
        location = reader.get_source_and_line(incr=1)

        indent, marker, info = self.pattern.match(reader.readline()).groups()
        code = ''.join(FencedCodeBlockReader(reader, len(indent), marker))

        literal_block = nodes.literal_block(code, code, classes=['code'])
        location.set_source_info(literal_block)
        if info.strip():
            language = unescape(entitytrans._unescape(info.split()[0].strip()))
            literal_block['language'] = language
            literal_block['classes'].append('language-%s' %
                                            language.split()[0])
        document += literal_block

        return True
Beispiel #3
0
 def parse(self, reader: TextReader, document: Element) -> str:
     matched = reader.consume(self.pattern)
     if matched:
         return unescape(entitytrans._unescape(matched.group(1)[1:-1]))
     else:
         return None
Beispiel #4
0
 def normalize_link_destination(self, s: str) -> str:
     s = entitytrans._unescape(s)
     s = unescape(s)
     s = normalize_uri(s)
     return s
Beispiel #5
0
 def run(self, reader: TextReader, document: Element) -> bool:
     text = reader.consume(self.pattern).group(0)
     document += Text(entitytrans._unescape(text))
     return True