Merge pull request #1206 from minrk/fixConsole

The notebook js transforms ANSI-escaped text to HTML.  The transformed HTML was previously persisted to ipynb files, rather than the true output.  This has been fixed, and notebooks with ANSI-colored output will need to be re-run for colored output (tracebacks) to be displayed correctly after this change.
This commit is contained in:
Min RK 2012-01-26 17:14:29 -08:00
commit 125dc8cb74
2 changed files with 13 additions and 13 deletions

View File

@ -15,7 +15,7 @@ var IPython = (function (IPython) {
var CodeCell = function (notebook) {
this.code_mirror = null;
this.input_prompt_number = ' ';
this.input_prompt_number = null;
this.is_completing = false;
this.completion_cursor = null;
this.outputs = [];
@ -611,7 +611,9 @@ var IPython = (function (IPython) {
if (last.output_type == 'stream' && json.stream == last.stream){
// latest output was in the same stream,
// so append directly into its pre tag
this.element.find('div.'+subclass).last().find('pre').append(json.text);
// escape ANSI & HTML specials:
var text = utils.fixConsole(json.text);
this.element.find('div.'+subclass).last().find('pre').append(text);
return;
}
}
@ -660,6 +662,8 @@ var IPython = (function (IPython) {
CodeCell.prototype.append_text = function (data, element, extra_class) {
var toinsert = $("<div/>").addClass("box_flex1 output_subarea output_text");
// escape ANSI & HTML specials in plaintext:
data = utils.fixConsole(data);
if (extra_class){
toinsert.addClass(extra_class);
}
@ -766,9 +770,9 @@ var IPython = (function (IPython) {
};
CodeCell.prototype.set_input_prompt = function (number) {
var n = number || '&nbsp;';
this.input_prompt_number = n;
this.element.find('div.input_prompt').html('In&nbsp;[' + n + ']:');
this.input_prompt_number = number;
var ns = number || "&nbsp;";
this.element.find('div.input_prompt').html('In&nbsp;[' + ns + ']:');
};
@ -829,7 +833,7 @@ var IPython = (function (IPython) {
var data = {};
data.input = this.get_text();
data.cell_type = 'code';
if (this.input_prompt_number !== ' ') {
if (this.input_prompt_number) {
data.prompt_number = this.input_prompt_number;
};
var outputs = [];

View File

@ -922,7 +922,7 @@ var IPython = (function (IPython) {
var json = {};
json.output_type = msg_type;
if (msg_type === "stream") {
json.text = utils.fixConsole(content.data);
json.text = content.data;
json.stream = content.name;
} else if (msg_type === "display_data") {
json = this.convert_mime_types(json, content.data);
@ -932,11 +932,7 @@ var IPython = (function (IPython) {
} else if (msg_type === "pyerr") {
json.ename = content.ename;
json.evalue = content.evalue;
var traceback = [];
for (var i=0; i<content.traceback.length; i++) {
traceback.push(utils.fixConsole(content.traceback[i]));
}
json.traceback = traceback;
json.traceback = content.traceback;
};
cell.append_output(json);
this.dirty = true;
@ -945,7 +941,7 @@ var IPython = (function (IPython) {
Notebook.prototype.convert_mime_types = function (json, data) {
if (data['text/plain'] !== undefined) {
json.text = utils.fixConsole(data['text/plain']);
json.text = data['text/plain'];
};
if (data['text/html'] !== undefined) {
json.html = data['text/html'];