Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
def highlight_ansi_and_escape(self, text):
return self.escape(filters.strip_ansi(text))
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"):
def highlight_ansi_and_escape(self, text):
return self.escape(filters.strip_ansi(text))
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