瀏覽代碼

Remove dependency on ansi-to-html and use console text widget.

A. Darian 8 年之前
父節點
當前提交
1018e73abc
共有 5 個文件被更改,包括 110 次插入30 次删除
  1. 0 1
      package.json
  2. 13 11
      src/notebook/console/model.ts
  3. 97 0
      src/notebook/theme.css
  4. 0 1
      src/notebook/typings.d.ts
  5. 0 17
      typings/ansi-to-html/ansi-to-html.d.ts

+ 0 - 1
package.json

@@ -5,7 +5,6 @@
   "main": "lib/index.js",
   "typings": "lib/index.d.ts",
   "dependencies": {
-    "ansi-to-html": "^0.4.1",
     "codemirror": "^5.11.0",
     "diff-match-patch": "^1.0.0",
     "file-loader": "^0.8.5",

+ 13 - 11
src/notebook/console/model.ts

@@ -50,9 +50,6 @@ import {
   MimeBundle
 } from '../notebook';
 
-declare var require: any;
-const Filter = require('ansi-to-html');
-
 
 /**
  * The default console kernelspec metadata.
@@ -452,7 +449,7 @@ class ConsoleModel implements IConsoleModel {
       this.tooltip = {
         change: args,
         currentLine: currentLine,
-        bundle: Private.formatInspectReply(value.data)
+        bundle: Private.processInspectReply(value.data)
       };
     });
   }
@@ -577,16 +574,21 @@ namespace Private {
   }
 
   /**
-   * Format the IInspectReply plain text data.
+   * Process the IInspectReply plain text data.
+   *
+   * @param bundle - The MIME bundle of an API inspect reply.
+   *
+   * #### Notes
+   * The `text/plain` value sent by the API in inspect replies contains ANSI
+   * terminal escape sequences. In order for these sequences to be parsed into
+   * usable data in the client, they must have the MIME type that the console
+   * text renderer expects: `application/vnd.jupyter.console-text`.
    */
   export
-  function formatInspectReply(bundle: MimeBundle): MimeBundle {
+  function processInspectReply(bundle: MimeBundle): MimeBundle {
     let textMime = 'text/plain';
-    let textHTML = 'text/html';
-    if (!bundle[textMime]) return bundle;
-    // Add a 'text/html' formatted version of the plain text.
-    let filter = new Filter();
-    bundle[textHTML] = `<pre>${filter.toHtml(bundle[textMime])}</pre>`;
+    let consoleMime = 'application/vnd.jupyter.console-text';
+    bundle[consoleMime] = bundle[consoleMime] || bundle[textMime];
     return bundle;
   }
 

+ 97 - 0
src/notebook/theme.css

@@ -371,3 +371,100 @@
   margin: 0;
   padding: 2px;
 }
+
+
+/* ansi_up creates classed spans for console foregrounds and backgrounds. */
+.jp-ConsoleTooltip pre .ansi-black-fg { color: #3A3A3A; }
+
+
+.jp-ConsoleTooltip pre .ansi-red-fg { color: #DD948E; }
+
+
+.jp-ConsoleTooltip pre .ansi-green-fg { color: #B6D1AA; }
+
+
+.jp-ConsoleTooltip pre .ansi-yellow-fg { color: #F3D57C; }
+
+
+.jp-ConsoleTooltip pre .ansi-blue-fg { color: #8AA9D5; }
+
+
+.jp-ConsoleTooltip pre .ansi-magenta-fg { color: #CBAFD5; }
+
+
+.jp-ConsoleTooltip pre .ansi-cyan-fg { color: #9AD1D4; }
+
+
+.jp-ConsoleTooltip pre .ansi-white-fg { color: #EFEFEF; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-black-fg { color: #5E5D5E; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-red-fg { color: #E69B94; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-green-fg { color: #D1F0C3; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-yellow-fg { color: #F4D799; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-blue-fg { color: #A6CBFE; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-magenta-fg { color: #E7C7F2; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-cyan-fg { color: #B0F0F5; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-white-fg { color: #FFF; }
+
+
+.jp-ConsoleTooltip pre .ansi-black-bg { background-color: #3A3A3A; }
+
+
+.jp-ConsoleTooltip pre .ansi-red-bg { background-color: #DD948E; }
+
+
+.jp-ConsoleTooltip pre .ansi-green-bg { background-color: #B6D1AA; }
+
+
+.jp-ConsoleTooltip pre .ansi-yellow-bg { background-color: #F3D57C; }
+
+
+.jp-ConsoleTooltip pre .ansi-blue-bg { background-color: #8AA9D5; }
+
+
+.jp-ConsoleTooltip pre .ansi-magenta-bg { background-color: #CBAFD5; }
+
+
+.jp-ConsoleTooltip pre .ansi-cyan-bg { background-color: #9AD1D4; }
+
+
+.jp-ConsoleTooltip pre .ansi-white-bg { background-color: #EFEFEF; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-black-bg { background-color: #5E5D5E; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-red-bg { background-color: #E69B94; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-green-bg { background-color: #D1F0C3; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-yellow-bg { background-color: #F4D799; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-blue-bg { background-color: #A6CBFE; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-magenta-bg { background-color: #E7C7F2; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-cyan-bg { background-color: #B0F0F5; }
+
+
+.jp-ConsoleTooltip pre .ansi-bright-white-bg { background-color: #FFF; }

+ 0 - 1
src/notebook/typings.d.ts

@@ -3,4 +3,3 @@
 /// <reference path="../typings/codemirror/codemirror.d.ts"/>
 /// <reference path="../typings/diff-match-patch/diff-match-patch.d.ts"/>
 /// <reference path="../typings/mathjax/mathjax.d.ts"/>
-/// <reference path="../typings/ansi-to-html/ansi-to-html.d.ts"/>

+ 0 - 17
typings/ansi-to-html/ansi-to-html.d.ts

@@ -1,17 +0,0 @@
-// Type definitions for ansi-to-html
-// Project: https://github.com/rburns/ansi-to-html
-
-declare class Filter {
-  constructor(options?: {
-    fg?: string;
-    bg?: string;
-    newline?: boolean;
-    escapeXML?: boolean;
-    stream?: boolean;
-  });
-  toHtml(input: string): string;
-}
-
-declare module "ansi-to-html" {
-    export = Filter;
-}