How to use the @jupyterlab/rendermime.OutputModel.getData 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 jupyter / nbdime / packages / nbdime / src / diff / widget / output.ts View on Github external
// Add trust button:
    let btnTrust = document.createElement('button');
    btnTrust.innerText = 'Trust';
    btnTrust.onclick = (ev: MouseEvent) => {
      // Triggers change event:
      this.model.trusted = !this.model.trusted;
    };
    w = new Widget({node: btnTrust});
    w.addClass(TRUST_BUTTON_CLASS);
    this.menu.addWidget(w);

    // Add mimetype select:
    let mimetypes: string[] = [];
    for (let output of this.model.contents) {
      let bundle = OutputModel.getData(output);
      mimetypes = mimetypes.concat(Object.keys(bundle));
    }
    mimetypes = mimetypes.filter(unique);
    if (mimetypes.length > 1) {
      let cboMimetype = buildSelect(mimetypes);
      let selectedMimetype = this.selectedMimetype;
      if (selectedMimetype) {
        cboMimetype.selectedIndex = mimetypes.indexOf(selectedMimetype);
      }
      cboMimetype.onchange = (ev: Event) => {
        this.selectedMimetype = mimetypes[cboMimetype.selectedIndex];
      };
      w = new Widget({node: cboMimetype});
      w.addClass(MIMETYPE_SELECT_CLASS);
      this.menu.addWidget(w);
    } else if (mimetypes.length === 1) {
github jupyterlab / jupyterlab / tests / test-rendermime / src / outputmodel.spec.ts View on Github external
it('should handle all bundle types', () => {
        for (let i = 0; i < NBTestUtils.DEFAULT_OUTPUTS.length; i++) {
          const output = NBTestUtils.DEFAULT_OUTPUTS[i];
          const bundle = OutputModel.getData(output);
          expect(Object.keys(bundle).length).to.not.equal(0);
        }
      });
    });
github jupyter / nbdime / packages / nbdime / src / diff / widget / output.ts View on Github external
protected get selectedMimetype(): string | null {
    if (this._mimetype !== null) {
      return this._mimetype;
    }
    let data = OutputModel.getData(this.model.base || this.model.remote!);
    let mt = this.rendermime.preferredMimeType(
      data,
      this.model.trusted ? 'any' : 'ensure'
    );
    return mt === undefined ? null : mt;
  }
github jupyter / nbdime / packages / nbdime / src / diff / widget / output.ts View on Github external
protected createRenderer(output: nbformat.IOutput, trusted: boolean, mimetype: string): IRenderMime.IRenderer {
    let model = new OutputModel({value: output, trusted});
    let widget = this.rendermime.createRenderer(mimetype);
    widget.renderModel(model);
    widget.addClass(RENDERED_OUTPUT_CLASS);
    let bundle = OutputModel.getData(output);
    if (isBase64(bundle[mimetype] as string)) {
      widget.addClass(DATA_IS_BASE64_CLASS);
    }
    return widget;
  }
github jupyter / nbdime / packages / nbdime / src / diff / widget / output.ts View on Github external
static canRender(model: OutputDiffModel, rendermime: IRenderMimeRegistry): boolean {
    let toTest = model.contents;
    for (let o of toTest) {
      let bundle = OutputModel.getData(o);
      let mimetype = rendermime.preferredMimeType(
        bundle,
        model.trusted ? 'any' : 'ensure'
      );
      if (!mimetype) {
        return false;
      }
    }
    return true;
  }
}