def split_row(text: str) -> Generator[str, None, None]: i = 0 while i < len(text): if text[i] == '|': yield unescape(text[0:i].strip()) text = text[i + 1:] i = 0 elif text[i] == '\\': i += 2 else: i += 1 if text: yield unescape(text.strip())
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
def run(self, reader: TextReader, document: Element) -> bool: brackets = list(n for n in document.children if isinstance(n, bracket)) openers = list(d for d in brackets if d['can_open']) if openers == []: return False matched = reader.consume(self.pattern) rubytext = unescape(matched.group(0)[2:-1]) ruby = addnodes.ruby(rubytext=rubytext) document += ruby # transplant ruby base text to ruby node transplant_nodes(document, ruby, start=openers[-1], end=ruby) document.remove(openers[-1]) return True
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
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
def normalize_link_destination(self, s: str) -> str: s = entitytrans._unescape(s) s = unescape(s) s = normalize_uri(s) return s