How to use the @jupyterlab/rendermime.imageRendererFactory.mimeTypes function in @jupyterlab/rendermime

To help you get started, we’ve selected a few @jupyterlab/rendermime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jupyterlab / jupyterlab / packages / attachments / src / model.ts View on Github external
getDownloadUrl(path: string): Promise {
    if (this._parent && !path.startsWith('attachment:')) {
      return this._parent.getDownloadUrl(path);
    }
    // Return a data URL with the data of the url
    const key = path.slice('attachment:'.length);
    if (!this._model.has(key)) {
      // Resolve with unprocessed path, to show as broken image
      return Promise.resolve(path);
    }
    const { data } = this._model.get(key);
    const mimeType = Object.keys(data)[0];
    // Only support known safe types:
    if (imageRendererFactory.mimeTypes.indexOf(mimeType) === -1) {
      return Promise.reject(
        `Cannot render unknown image mime type "${mimeType}".`
      );
    }
    const dataUrl = `data:${mimeType};base64,${data[mimeType]}`;
    return Promise.resolve(dataUrl);
  }
github jupyterlab / jupyterlab / packages / attachments / src / data.ts View on Github external
return this._parent.getDownloadUrl(path);
    }
    // Return a data URL with the data of the url
    const key = path.slice('attachment:'.length);
    const attachment = DatastoreExt.getField(this._data.datastore, {
      ...this._data.record,
      field: 'attachments'
    });
    if (!attachment || !attachment[key]) {
      // Resolve with unprocessed path, to show as broken image
      return Promise.resolve(path);
    }
    const data = AttachmentsData.getData(attachment[key]);
    const mimeType = Object.keys(data)[0];
    // Only support known safe types:
    if (imageRendererFactory.mimeTypes.indexOf(mimeType) === -1) {
      return Promise.reject(
        `Cannot render unknown image mime type "${mimeType}".`
      );
    }
    const dataUrl = `data:${mimeType};base64,${data[mimeType]}`;
    return Promise.resolve(dataUrl);
  }
github jupyterlab / jupyterlab / tests / test-rendermime / src / factories.spec.ts View on Github external
it('should support multiple mimeTypes', () => {
        expect(imageRendererFactory.mimeTypes).to.deep.equal([
          'image/bmp',
          'image/png',
          'image/jpeg',
          'image/gif'
        ]);
      });
    });
github jupyterlab / jupyterlab-data-explorer / tests / test-rendermime / src / factories.spec.ts View on Github external
it('should support multiple mimeTypes', () => {
        expect(imageRendererFactory.mimeTypes).to.deep.equal([
          'image/bmp',
          'image/png',
          'image/jpeg',
          'image/gif'
        ]);
      });
    });