mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
PY-21447 Jupyter Notebook fails to properly handle IPython.display Markdown
This commit is contained in:
@@ -142,7 +142,7 @@ public class IpnbCodePanel extends IpnbEditablePanel<JComponent, IpnbCodeCell> {
|
||||
outputPanel.setBackground(IpnbEditorUtil.getBackground());
|
||||
|
||||
for (IpnbOutputCell outputCell : myCell.getCellOutputs()) {
|
||||
addOutputPanel(outputPanel, outputCell, true);
|
||||
addOutputPanel(outputPanel, outputCell, outputCell instanceof IpnbOutOutputCell);
|
||||
}
|
||||
|
||||
return outputPanel;
|
||||
|
||||
@@ -353,7 +353,12 @@ public class IpnbParser {
|
||||
if (nbformat == 4) {
|
||||
final OutputDataRaw dataRaw = new OutputDataRaw();
|
||||
dataRaw.text = outputCell.getText();
|
||||
dataRaw.latex = ((IpnbLatexOutputCell)outputCell).getLatex();
|
||||
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 = "execute_result";
|
||||
@@ -430,7 +435,10 @@ public class IpnbParser {
|
||||
outputCell = new IpnbHtmlOutputCell(html == null ? data.html : html, text, prompt, metadata);
|
||||
}
|
||||
else if (latex != null || (data != null && data.latex != null)) {
|
||||
outputCell = new IpnbLatexOutputCell(latex == null ? data.latex : latex, prompt, text, metadata);
|
||||
outputCell = new IpnbLatexOutputCell(latex == null ? data.latex : latex, false, prompt, text, metadata);
|
||||
}
|
||||
else if (data != null && data.markdown != null) {
|
||||
outputCell = new IpnbLatexOutputCell(data.markdown, true, prompt, text, metadata);
|
||||
}
|
||||
else if (stream != null || name != null) {
|
||||
outputCell = new IpnbStreamOutputCell(stream == null ? name : stream, text, prompt, metadata);
|
||||
@@ -461,6 +469,7 @@ public class IpnbParser {
|
||||
@SerializedName("image/jpeg") List<String> jpeg;
|
||||
@SerializedName("text/latex") List<String> latex;
|
||||
@SerializedName("text/plain") List<String> text;
|
||||
@SerializedName("text/markdown") List<String> markdown;
|
||||
}
|
||||
|
||||
static class RawCellAdapter implements JsonSerializer<IpnbCellRaw> {
|
||||
@@ -591,6 +600,7 @@ public class IpnbParser {
|
||||
dataRaw.svg = getStringOrArray("image/svg+xml", object);
|
||||
dataRaw.jpeg = getStringOrArray("image/jpeg", object);
|
||||
dataRaw.latex = getStringOrArray("text/latex", object);
|
||||
dataRaw.markdown = getStringOrArray("text/markdown", object);
|
||||
dataRaw.text = getStringOrArray("text/plain", object);
|
||||
return dataRaw;
|
||||
}
|
||||
@@ -770,6 +780,10 @@ public class IpnbParser {
|
||||
final JsonElement latex = gson.toJsonTree(cellRaw.latex);
|
||||
jsonObject.add("text/latex", latex);
|
||||
}
|
||||
if (cellRaw.markdown != null) {
|
||||
final JsonElement markdown = gson.toJsonTree(cellRaw.markdown);
|
||||
jsonObject.add("text/markdown", markdown);
|
||||
}
|
||||
if (cellRaw.text != null) {
|
||||
final JsonElement text = gson.toJsonTree(cellRaw.text);
|
||||
jsonObject.add("text/plain", text);
|
||||
|
||||
+8
-4
@@ -8,17 +8,21 @@ import java.util.Map;
|
||||
|
||||
public class IpnbLatexOutputCell extends IpnbOutputCell {
|
||||
@NotNull private final List<String> myLatex;
|
||||
private final boolean isMarkdown;
|
||||
|
||||
public IpnbLatexOutputCell(@NotNull final List<String> latex,
|
||||
Integer promptNumber,
|
||||
@NotNull final List<String> text,
|
||||
@Nullable Map<String, Object> metadata) {
|
||||
public IpnbLatexOutputCell(@NotNull final List<String> latex, final boolean markdown, Integer promptNumber,
|
||||
@NotNull final List<String> text, @Nullable Map<String, Object> metadata) {
|
||||
super(text, promptNumber, metadata);
|
||||
myLatex = latex;
|
||||
isMarkdown = markdown;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<String> getLatex() {
|
||||
return myLatex;
|
||||
}
|
||||
|
||||
public boolean isMarkdown() {
|
||||
return isMarkdown;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,7 +300,11 @@ public class IpnbConnection {
|
||||
final String plainText = (String)data.get("text/plain");
|
||||
if (data.containsKey("text/latex")) {
|
||||
final String text = (String)data.get("text/latex");
|
||||
myOutput = new IpnbLatexOutputCell(Lists.newArrayList(text), null, Lists.newArrayList(plainText), null);
|
||||
myOutput = new IpnbLatexOutputCell(Lists.newArrayList(text), false, null, Lists.newArrayList(plainText), null);
|
||||
}
|
||||
else if (data.containsKey("text/markdown")) {
|
||||
final String text = (String)data.get("text/markdown");
|
||||
myOutput = new IpnbLatexOutputCell(Lists.newArrayList(text), true, null, Lists.newArrayList(plainText), null);
|
||||
}
|
||||
else if (data.containsKey("text/html")) {
|
||||
final String html = (String)data.get("text/html");
|
||||
|
||||
Reference in New Issue
Block a user