def visit_Text(self, node: nodes.Text) -> None: if isinstance(node.parent, nodes.comment): return if self.current_cell.cell_type == "markdown": self.append(node.astext()) return source = node.astext() if ">>>" not in source: self.append(source) return pattern = re.compile("^(>>>|\\.\\.\\.) ?") def clean_line(line): return pattern.sub("", line) cleaned_source = "\n".join([ clean_line(line) for line in source.split("\n") if pattern.match(line) ]) self.append(cleaned_source)
def visit_Text(self, node: nodes.Text) -> None: source = node.astext() self.source += textwrap.indent(source, "# " * self.is_code)