How to use the nbconvert.filters.strip_ansi function in nbconvert

To help you get started, we’ve selected a few nbconvert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyter / nbgrader / nbgrader / validator.py View on Github external
def _indent(self, val: str) -> str:
        lines = val.split("\n")
        new_lines = []
        for line in lines:
            new_line = self.indent + strip_ansi(line)
            if len(new_line) > (self.width - 3):
                new_line = new_line[:(self.width - 3)] + "..."
            new_lines.append(new_line)
        return "\n".join(new_lines)
github mpastell / Pweave / pweave / formatters / base.py View on Github external
def highlight_ansi_and_escape(self, text):
        return self.escape(filters.strip_ansi(text))
github jupyter / jupyter-sphinx / jupyter_sphinx / ast.py View on Github external
classes=["stderr"],
                        )
                    )
                    to_add.append(container)
            else:
                to_add.append(
                    docutils.nodes.literal_block(
                        text=output["text"],
                        rawsource=output["text"],
                        language="none",
                        classes=["output", "stream"],
                    )
                )
        elif output_type == "error":
            traceback = "\n".join(output["traceback"])
            text = nbconvert.filters.strip_ansi(traceback)
            to_add.append(
                docutils.nodes.literal_block(
                    text=text,
                    rawsource=text,
                    language="ipythontb",
                    classes=["output", "traceback"],
                )
            )
        elif output_type in ("display_data", "execute_result"):
            try:
                # First mime_type by priority that occurs in output.
                mime_type = next(x for x in data_priority if x in output["data"])
            except StopIteration:
                continue
            data = output["data"][mime_type]
            if mime_type.startswith("image"):
github mpastell / Pweave / pweave / formatters / _Python2 / base.py View on Github external
def highlight_ansi_and_escape(self, text):
        return self.escape(filters.strip_ansi(text))
github mpastell / Pweave / pweave / processors / jupyter.py View on Github external
def load_inline_string(self, code_string):
        from nbconvert import filters
        outputs = self.loadstring(code_string)
        result = ""
        for out in outputs:
            if out["output_type"] == "stream":
                result += out["text"]
            elif out["output_type"] == "error":
                result += filters.strip_ansi("".join(out["traceback"]))
            elif "text/plain" in out["data"]:
                result += out["data"]["text/plain"]
            else:
                result = ""
        return result