|
|
|
|
@ -211,7 +211,7 @@ define([
|
|
|
|
|
var content = msg.content;
|
|
|
|
|
if (msg_type === "stream") {
|
|
|
|
|
json.text = content.text;
|
|
|
|
|
json.stream = content.name;
|
|
|
|
|
json.name = content.name;
|
|
|
|
|
} else if (msg_type === "display_data") {
|
|
|
|
|
json = content.data;
|
|
|
|
|
json.output_type = msg_type;
|
|
|
|
|
@ -234,6 +234,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputArea.prototype.rename_keys = function (data, key_map) {
|
|
|
|
|
// TODO: This is now unused, should it be removed?
|
|
|
|
|
var remapped = {};
|
|
|
|
|
for (var key in data) {
|
|
|
|
|
var new_key = key_map[key] || key;
|
|
|
|
|
@ -260,7 +261,10 @@ define([
|
|
|
|
|
// TODO: right now everything is a string, but JSON really shouldn't be.
|
|
|
|
|
// nbformat 4 will fix that.
|
|
|
|
|
$.map(OutputArea.output_types, function(key){
|
|
|
|
|
if (json[key] !== undefined && typeof json[key] !== 'string') {
|
|
|
|
|
if (key !== 'application/json' &&
|
|
|
|
|
json[key] !== undefined &&
|
|
|
|
|
typeof json[key] !== 'string'
|
|
|
|
|
) {
|
|
|
|
|
console.log("Invalid type for " + key, json[key]);
|
|
|
|
|
delete json[key];
|
|
|
|
|
}
|
|
|
|
|
@ -449,23 +453,18 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputArea.prototype.append_stream = function (json) {
|
|
|
|
|
// temporary fix: if stream undefined (json file written prior to this patch),
|
|
|
|
|
// default to most likely stdout:
|
|
|
|
|
if (json.stream === undefined){
|
|
|
|
|
json.stream = 'stdout';
|
|
|
|
|
}
|
|
|
|
|
var text = json.text;
|
|
|
|
|
var subclass = "output_"+json.stream;
|
|
|
|
|
var text = json.data;
|
|
|
|
|
var subclass = "output_"+json.name;
|
|
|
|
|
if (this.outputs.length > 0){
|
|
|
|
|
// have at least one output to consider
|
|
|
|
|
var last = this.outputs[this.outputs.length-1];
|
|
|
|
|
if (last.output_type == 'stream' && json.stream == last.stream){
|
|
|
|
|
if (last.output_type == 'stream' && json.name == last.name){
|
|
|
|
|
// latest output was in the same stream,
|
|
|
|
|
// so append directly into its pre tag
|
|
|
|
|
// escape ANSI & HTML specials:
|
|
|
|
|
last.text = utils.fixCarriageReturn(last.text + json.text);
|
|
|
|
|
last.data = utils.fixCarriageReturn(last.data + json.data);
|
|
|
|
|
var pre = this.element.find('div.'+subclass).last().find('pre');
|
|
|
|
|
var html = utils.fixConsole(last.text);
|
|
|
|
|
var html = utils.fixConsole(last.data);
|
|
|
|
|
// The only user content injected with this HTML call is
|
|
|
|
|
// escaped by the fixConsole() method.
|
|
|
|
|
pre.html(html);
|
|
|
|
|
@ -852,70 +851,33 @@ define([
|
|
|
|
|
|
|
|
|
|
// JSON serialization
|
|
|
|
|
|
|
|
|
|
OutputArea.prototype.fromJSON = function (outputs) {
|
|
|
|
|
OutputArea.prototype.fromJSON = function (outputs, metadata) {
|
|
|
|
|
var len = outputs.length;
|
|
|
|
|
var data;
|
|
|
|
|
metadata = metadata || {};
|
|
|
|
|
|
|
|
|
|
for (var i=0; i<len; i++) {
|
|
|
|
|
data = outputs[i];
|
|
|
|
|
var msg_type = data.output_type;
|
|
|
|
|
if (msg_type == "pyout") {
|
|
|
|
|
// pyout message has been renamed to execute_result,
|
|
|
|
|
// but the nbformat has not been updated,
|
|
|
|
|
// so transform back to pyout for json.
|
|
|
|
|
msg_type = data.output_type = "execute_result";
|
|
|
|
|
} else if (msg_type == "pyerr") {
|
|
|
|
|
// pyerr message has been renamed to error,
|
|
|
|
|
// but the nbformat has not been updated,
|
|
|
|
|
// so transform back to pyerr for json.
|
|
|
|
|
msg_type = data.output_type = "error";
|
|
|
|
|
this.append_output(outputs[i]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (metadata.collapsed !== undefined) {
|
|
|
|
|
this.collapsed = metadata.collapsed;
|
|
|
|
|
if (metadata.collapsed) {
|
|
|
|
|
this.collapse_output();
|
|
|
|
|
}
|
|
|
|
|
if (msg_type === "display_data" || msg_type === "execute_result") {
|
|
|
|
|
// convert short keys to mime keys
|
|
|
|
|
// TODO: remove mapping of short keys when we update to nbformat 4
|
|
|
|
|
data = this.rename_keys(data, OutputArea.mime_map_r);
|
|
|
|
|
data.metadata = this.rename_keys(data.metadata, OutputArea.mime_map_r);
|
|
|
|
|
// msg spec JSON is an object, nbformat v3 JSON is a JSON string
|
|
|
|
|
if (data["application/json"] !== undefined && typeof data["application/json"] === 'string') {
|
|
|
|
|
data["application/json"] = JSON.parse(data["application/json"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (metadata.autoscroll !== undefined) {
|
|
|
|
|
this.collapsed = metadata.collapsed;
|
|
|
|
|
if (metadata.collapsed) {
|
|
|
|
|
this.collapse_output();
|
|
|
|
|
} else {
|
|
|
|
|
this.expand_output();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.append_output(data);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputArea.prototype.toJSON = function () {
|
|
|
|
|
var outputs = [];
|
|
|
|
|
var len = this.outputs.length;
|
|
|
|
|
var data;
|
|
|
|
|
for (var i=0; i<len; i++) {
|
|
|
|
|
data = this.outputs[i];
|
|
|
|
|
var msg_type = data.output_type;
|
|
|
|
|
if (msg_type === "display_data" || msg_type === "execute_result") {
|
|
|
|
|
// convert mime keys to short keys
|
|
|
|
|
data = this.rename_keys(data, OutputArea.mime_map);
|
|
|
|
|
data.metadata = this.rename_keys(data.metadata, OutputArea.mime_map);
|
|
|
|
|
// msg spec JSON is an object, nbformat v3 JSON is a JSON string
|
|
|
|
|
if (data.json !== undefined && typeof data.json !== 'string') {
|
|
|
|
|
data.json = JSON.stringify(data.json);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (msg_type == "execute_result") {
|
|
|
|
|
// pyout message has been renamed to execute_result,
|
|
|
|
|
// but the nbformat has not been updated,
|
|
|
|
|
// so transform back to pyout for json.
|
|
|
|
|
data.output_type = "pyout";
|
|
|
|
|
} else if (msg_type == "error") {
|
|
|
|
|
// pyerr message has been renamed to error,
|
|
|
|
|
// but the nbformat has not been updated,
|
|
|
|
|
// so transform back to pyerr for json.
|
|
|
|
|
data.output_type = "pyerr";
|
|
|
|
|
}
|
|
|
|
|
outputs[i] = data;
|
|
|
|
|
}
|
|
|
|
|
return outputs;
|
|
|
|
|
return this.outputs;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -948,29 +910,6 @@ define([
|
|
|
|
|
OutputArea.minimum_scroll_threshold = 20;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
OutputArea.mime_map = {
|
|
|
|
|
"text/plain" : "text",
|
|
|
|
|
"text/html" : "html",
|
|
|
|
|
"image/svg+xml" : "svg",
|
|
|
|
|
"image/png" : "png",
|
|
|
|
|
"image/jpeg" : "jpeg",
|
|
|
|
|
"text/latex" : "latex",
|
|
|
|
|
"application/json" : "json",
|
|
|
|
|
"application/javascript" : "javascript",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OutputArea.mime_map_r = {
|
|
|
|
|
"text" : "text/plain",
|
|
|
|
|
"html" : "text/html",
|
|
|
|
|
"svg" : "image/svg+xml",
|
|
|
|
|
"png" : "image/png",
|
|
|
|
|
"jpeg" : "image/jpeg",
|
|
|
|
|
"latex" : "text/latex",
|
|
|
|
|
"json" : "application/json",
|
|
|
|
|
"javascript" : "application/javascript",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OutputArea.display_order = [
|
|
|
|
|
'application/javascript',
|
|
|
|
|
'text/html',
|
|
|
|
|
|