Quellcode durchsuchen

Merge pull request #874 from rgbkrk/relax-source-type

Relax type of mimebundle data to allow for Object
S. Chris Colbert vor 8 Jahren
Ursprung
Commit
8f8123c8f3
2 geänderte Dateien mit 11 neuen und 7 gelöschten Zeilen
  1. 6 6
      src/renderers/widget.ts
  2. 5 1
      src/rendermime/index.ts

+ 6 - 6
src/renderers/widget.ts

@@ -149,7 +149,7 @@ class RenderedHTML extends RenderedHTMLCommon {
   constructor(options: RenderMime.IRenderOptions) {
     super(options);
     this.addClass(HTML_CLASS);
-    let source = options.source;
+    let source = options.source as string;
     if (options.sanitizer) {
       source = options.sanitizer.sanitize(source);
     }
@@ -179,7 +179,7 @@ class RenderedMarkdown extends RenderedHTMLCommon {
   constructor(options: RenderMime.IRenderOptions) {
     super(options);
     this.addClass(MARKDOWN_CLASS);
-    let parts = removeMath(options.source);
+    let parts = removeMath(options.source as string);
     // Add the markdown content asynchronously.
     marked(parts['text'], (err, content) => {
       if (err) {
@@ -225,7 +225,7 @@ class RenderedLatex extends Widget {
    */
   constructor(options: RenderMime.IRenderOptions) {
     super();
-    this.node.textContent = options.source;
+    this.node.textContent = options.source as string;
     this.addClass(LATEX_CLASS);
   }
 
@@ -256,7 +256,7 @@ class RenderedText extends Widget {
 
   constructor(options: RenderMime.IRenderOptions) {
     super();
-    let data = escape_for_html(options.source);
+    let data = escape_for_html(options.source as string);
     let pre = document.createElement('pre');
     pre.innerHTML = ansi_to_html(data);
     this.node.appendChild(pre);
@@ -272,7 +272,7 @@ class RenderedJavascript extends Widget {
     super();
     let s = document.createElement('script');
     s.type = options.mimetype;
-    s.textContent = options.source;
+    s.textContent = options.source as string;
     this.node.appendChild(s);
     this.addClass(JAVASCRIPT_CLASS);
   }
@@ -284,7 +284,7 @@ class RenderedSVG extends Widget {
 
   constructor(options: RenderMime.IRenderOptions) {
     super();
-    let source = options.source;
+    let source = options.source as string;
     if (options.sanitizer) {
       source = options.sanitizer.sanitize(source);
     }

+ 5 - 1
src/rendermime/index.ts

@@ -1,6 +1,10 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
+import {
+  JSONObject
+} from 'phosphor/lib/algorithm/json';
+
 import {
   Token
 } from 'phosphor/lib/core/token';
@@ -276,7 +280,7 @@ namespace RenderMime {
     /**
      * The source data.
      */
-    source: string;
+    source: string | JSONObject;
 
     /**
      * An optional url resolver.