def apply(self, **kwargs) -> None: for node in self.document.traverse(addnodes.linebreak): self.document.reporter.warning( "A hard line break detected, ignored.", source=node.parent.source, line=node.parent.line) node.replace_self(addnodes.SparseText('\n', 0, 1))
def run(self, reader: TextReader, document: Element) -> bool: if not isinstance(document, nodes.paragraph): return False else: reader.consume(self.pattern) # skip over a space at tail document += addnodes.SparseText(reader.subject, reader.position, reader.position) return True
def run(self, reader: TextReader, document: Element) -> bool: marker = reader.consume(self.pattern).group(0) pattern = re.compile(marker + r"([^`]|$)") text = addnodes.SparseText(reader.remain, 0, 0) while reader.remain: if pattern.match(reader.remain): code = re.sub(r'[\r\n]', ' ', str(text), re.S) code = self.trim_single_space(code) document += nodes.literal(code, code) reader.step(len(marker)) return True elif reader.remain[0] == '`': while reader.remain and reader.remain[0] == '`': text.spread(end=1) reader.step() else: text.spread(end=1) reader.step() else: raise UnmatchedTokenError(marker)
def run(self, reader: TextReader, document: Element) -> bool: document += addnodes.SparseText(reader.subject, reader.position + 1, reader.position + 2) reader.step(2) return True