Prechádzať zdrojové kódy

Merge pull request #4230 from minrk/ansi-up-up

update ansi_up to 3.0
Afshin Darian 7 rokov pred
rodič
commit
1d841404c7

+ 1 - 1
dev_mode/package.json

@@ -82,7 +82,7 @@
     "@phosphor/virtualdom": "^1.1.2",
     "@phosphor/widgets": "^1.5.0",
     "ajv": "~5.1.6",
-    "ansi_up": "~1.3.0",
+    "ansi_up": "^3.0.0",
     "codemirror": "~5.35.0",
     "comment-json": "^1.1.3",
     "es6-promise": "~4.1.1",

+ 1 - 1
docs/source/developer/adding_content.rst

@@ -15,7 +15,7 @@ As an example: Add a leaflet viewer plugin for geoJSON files.
 
 -  If there are no typings, we must create our own. An example typings
    file that exports functions is
-   `ansi_up <https://github.com/jupyterlab/jupyterlab/blob/master/packages/rendermime/typings/ansi_up/ansi_up.d.ts>`__.
+   `path-posix <https://github.com/jupyterlab/jupyterlab/blob/master/packages/coreutils/typings/path-posix/path-posix.d.ts>`__.
    An example with a class is
    `xterm <https://github.com/jupyterlab/jupyterlab/blob/master/packages/terminal/typings/xterm/xterm.d.ts>`__.
 

+ 1 - 1
jupyterlab/staging/package.json

@@ -82,7 +82,7 @@
     "@phosphor/virtualdom": "^1.1.2",
     "@phosphor/widgets": "^1.5.0",
     "ajv": "~5.1.6",
-    "ansi_up": "~1.3.0",
+    "ansi_up": "^3.0.0",
     "codemirror": "~5.35.0",
     "comment-json": "^1.1.3",
     "es6-promise": "~4.1.1",

+ 0 - 1
packages/metapackage/src/typings.d.ts

@@ -4,6 +4,5 @@
 /// <reference path="../../codemirror/typings/codemirror/codemirror.d.ts"/>
 /// <reference path="../../coreutils/typings/path-posix/path-posix.d.ts"/>
 /// <reference path="../../coreutils/typings/url-parse/url-parse.d.ts"/>
-/// <reference path="../../rendermime/typings/ansi_up/ansi_up.d.ts"/>
 /// <reference path="../../terminal/typings/xterm/xterm.d.ts"/>
 /// <reference path="../../vdom-extension/src/transform-vdom.d.ts"/>

+ 1 - 1
packages/rendermime/package.json

@@ -40,7 +40,7 @@
     "@phosphor/messaging": "^1.2.2",
     "@phosphor/signaling": "^1.2.2",
     "@phosphor/widgets": "^1.5.0",
-    "ansi_up": "~1.3.0",
+    "ansi_up": "^3.0.0",
     "marked": "~0.3.9"
   },
   "devDependencies": {

+ 6 - 4
packages/rendermime/src/renderers.ts

@@ -2,8 +2,9 @@
 | Copyright (c) Jupyter Development Team.
 | Distributed under the terms of the Modified BSD License.
 |----------------------------------------------------------------------------*/
+
 import {
-  ansi_to_html, escape_for_html
+  default as AnsiUp
 } from 'ansi_up';
 
 import * as marked
@@ -500,11 +501,12 @@ function renderText(options: renderText.IRenderOptions): Promise<void> {
   // Unpack the options.
   let { host, source } = options;
 
-  // Escape the terminal codes and HTML tags.
-  let data = escape_for_html(source);
+  const ansiUp = new AnsiUp();
+  ansiUp.escape_for_html = true;
+  ansiUp.use_classes = true;
 
   // Create the HTML content.
-  let content = ansi_to_html(data, { use_classes: true });
+  let content = ansiUp.ansi_to_html(source);
 
   // Set the inner HTML for the host node.
   host.innerHTML = `<pre>${content}</pre>`;

+ 0 - 5
packages/rendermime/src/typings.d.ts

@@ -1,5 +0,0 @@
-/*-----------------------------------------------------------------------------
-| Copyright (c) Jupyter Development Team.
-| Distributed under the terms of the Modified BSD License.
-|----------------------------------------------------------------------------*/
-/// <reference path="../typings/ansi_up/ansi_up.d.ts"/>

+ 0 - 19
packages/rendermime/typings/ansi_up/ansi_up.d.ts

@@ -1,19 +0,0 @@
-// Type definitions for ansi-to-html v.0.4.1
-// Project: https://github.com/rburns/ansi-to-html
-// Definitions by: Steven Silvester <https://github.com/blink1073>
-
-
-declare module "ansi_up" {
-    export
-    function escape_for_html(txt: string): string;
-
-    export
-    function linkify(txt: string): string;
-
-    export
-    function ansi_to_html(txt: string, options?: any): string;
-
-    export
-    function ansi_to_text(txt: string): string;
-}
-

+ 2 - 2
tests/test-rendermime/src/factories.spec.ts

@@ -81,7 +81,7 @@ describe('rendermime/factories', () => {
         let model = createModel(mimeType, source);
         let w = f.createRenderer({ mimeType, ...defaultOptions });
         return w.renderModel(model).then(() => {
-          expect(w.node.innerHTML).to.be('<pre>There is no text but <span class="ansi-bright-green-fg ansi-red-bg">text</span>.\nWoo.</pre>');
+          expect(w.node.innerHTML).to.be('<pre>There is no text but <span style="font-weight:bold" class="ansi-green-fg ansi-red-bg">text</span>.\nWoo.</pre>');
         });
       });
 
@@ -92,7 +92,7 @@ describe('rendermime/factories', () => {
         let model = createModel(mimeType, source);
         let w = f.createRenderer({ mimeType, ...defaultOptions });
         return w.renderModel(model).then(() => {
-          expect(w.node.innerHTML).to.be('<pre>There is no text &lt;script&gt;window.x=1&lt;/script&gt; but <span class="ansi-bright-green-fg ansi-red-bg">text</span>.\nWoo.</pre>');
+          expect(w.node.innerHTML).to.be('<pre>There is no text &lt;script&gt;window.x=1&lt;/script&gt; but <span style="font-weight:bold" class="ansi-green-fg ansi-red-bg">text</span>.\nWoo.</pre>');
         });
       });
 

+ 3 - 3
yarn.lock

@@ -532,9 +532,9 @@ ansi-styles@^3.2.0, ansi-styles@^3.2.1:
   dependencies:
     color-convert "^1.9.0"
 
-ansi_up@~1.3.0:
-  version "1.3.0"
-  resolved "https://registry.npmjs.org/ansi_up/-/ansi_up-1.3.0.tgz#c9c946bfc0b9bb5eaa060684bf2abaafe68bbd44"
+ansi_up@^3.0.0:
+  version "3.0.0"
+  resolved "https://registry.npmjs.org/ansi_up/-/ansi_up-3.0.0.tgz#27f45d8f457d9ceff59e4ea03c8e6f13c1a303e8"
 
 anymatch@^1.3.0:
   version "1.3.2"