in src/org/jetbrains/plugins/ipnb/format/IpnbParser.java [308:422]
public static CellOutputRaw fromOutput(@NotNull final IpnbOutputCell outputCell, int nbformat) {
final CellOutputRaw raw = new CellOutputRaw();
raw.metadata = outputCell.getMetadata();
if (raw.metadata == null && !(outputCell instanceof IpnbStreamOutputCell) && !(outputCell instanceof IpnbErrorOutputCell)) {
raw.metadata = new HashMap<>();
}
if (outputCell instanceof IpnbPngOutputCell) {
if (nbformat == 4) {
final OutputDataRaw dataRaw = new OutputDataRaw();
dataRaw.png = ((IpnbPngOutputCell)outputCell).getBase64String();
dataRaw.text = outputCell.getText();
raw.data = dataRaw;
raw.execution_count = outputCell.getPromptNumber();
raw.output_type = outputCell.getPromptNumber() != null ? "execute_result" : "display_data";
}
else {
raw.png = ((IpnbPngOutputCell)outputCell).getBase64String();
raw.text = outputCell.getText();
}
}
else if (outputCell instanceof IpnbSvgOutputCell) {
if (nbformat == 4) {
final OutputDataRaw dataRaw = new OutputDataRaw();
dataRaw.text = outputCell.getText();
dataRaw.svg = ((IpnbSvgOutputCell)outputCell).getSvg();
raw.data = dataRaw;
raw.execution_count = outputCell.getPromptNumber();
raw.output_type = outputCell.getPromptNumber() != null ? "execute_result" : "display_data";
}
else {
raw.svg = ((IpnbSvgOutputCell)outputCell).getSvg();
raw.text = outputCell.getText();
}
}
else if (outputCell instanceof IpnbJpegOutputCell) {
if (nbformat == 4) {
final OutputDataRaw dataRaw = new OutputDataRaw();
dataRaw.text = outputCell.getText();
dataRaw.jpeg = Lists.newArrayList(((IpnbJpegOutputCell)outputCell).getBase64String());
raw.data = dataRaw;
}
else {
raw.jpeg = ((IpnbJpegOutputCell)outputCell).getBase64String();
raw.text = outputCell.getText();
}
}
else if (outputCell instanceof IpnbLatexOutputCell) {
if (nbformat == 4) {
final OutputDataRaw dataRaw = new OutputDataRaw();
dataRaw.text = outputCell.getText();
if (((IpnbLatexOutputCell)outputCell).isMarkdown()) {
dataRaw.markdown = ((IpnbLatexOutputCell)outputCell).getLatex();
}
else {
dataRaw.latex = ((IpnbLatexOutputCell)outputCell).getLatex();
}
raw.data = dataRaw;
raw.execution_count = outputCell.getPromptNumber();
raw.output_type = outputCell.getPromptNumber() != null ? "execute_result" : "display_data";
}
else {
raw.latex = ((IpnbLatexOutputCell)outputCell).getLatex();
raw.text = outputCell.getText();
raw.prompt_number = outputCell.getPromptNumber();
}
}
else if (outputCell instanceof IpnbStreamOutputCell) {
if (nbformat == 4) {
raw.name = ((IpnbStreamOutputCell)outputCell).getStream();
}
else {
raw.stream = ((IpnbStreamOutputCell)outputCell).getStream();
}
raw.text = outputCell.getText();
raw.output_type = "stream";
}
else if (outputCell instanceof IpnbHtmlOutputCell) {
if (nbformat == 4) {
final OutputDataRaw dataRaw = new OutputDataRaw();
dataRaw.html = ((IpnbHtmlOutputCell)outputCell).getHtmls();
dataRaw.text = outputCell.getText();
raw.data = dataRaw;
raw.execution_count = outputCell.getPromptNumber();
}
else {
raw.html = ((IpnbHtmlOutputCell)outputCell).getHtmls();
}
raw.output_type = nbformat == 4 ? "execute_result" : "pyout";
}
else if (outputCell instanceof IpnbErrorOutputCell) {
raw.output_type = nbformat == 4 ? "error" : "pyerr";
raw.evalue = ((IpnbErrorOutputCell)outputCell).getEvalue();
raw.ename = ((IpnbErrorOutputCell)outputCell).getEname();
raw.traceback = outputCell.getText();
}
else if (outputCell instanceof IpnbOutOutputCell) {
if (nbformat == 4) {
raw.execution_count = outputCell.getPromptNumber();
raw.output_type = "execute_result";
final OutputDataRaw dataRaw = new OutputDataRaw();
dataRaw.text = outputCell.getText();
raw.data = dataRaw;
}
else {
raw.output_type = "pyout";
raw.prompt_number = outputCell.getPromptNumber();
raw.text = outputCell.getText();
}
}
else {
raw.text = outputCell.getText();
}
return raw;
}