Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
private _updateRenderedInput(): Promise {
let model = this.model;
let text = model && model.value.text || DEFAULT_MARKDOWN_TEXT;
// Do not re-render if the text has not changed.
if (text !== this._prevText) {
let mimeModel = new MimeModel({ data: { 'text/markdown': text }});
if (!this._renderer) {
this._renderer = this._rendermime.createRenderer('text/markdown');
this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
}
this._prevText = text;
return this._renderer.renderModel(mimeModel);
}
return Promise.resolve(void 0);
}
if (this._isRendering) {
this._renderRequested = true;
return;
}
// Set up for this rendering pass.
this._renderRequested = false;
const { context } = this;
const { model } = context;
const source = model.toString();
const data: JSONObject = {};
// If `hideFrontMatter`is true remove front matter.
data[MIMETYPE] = this._config.hideFrontMatter
? Private.removeFrontMatter(source)
: source;
const mimeModel = new MimeModel({
data,
metadata: { fragment: this._fragment }
});
try {
// Do the rendering asynchronously.
this._isRendering = true;
await this.renderer.renderModel(mimeModel);
this._isRendering = false;
// If there is an outstanding request to render, go ahead and render
if (this._renderRequested) {
return this._render();
}
} catch (reason) {
// Dispose the document if rendering fails.
private _render(): DocumentRegistry.IReadyWidget {
let context = this._context;
let model = context.model;
let layout = this.layout as PanelLayout;
let data = { 'text/markdown': model.toString() };
let mimeModel = new MimeModel({ data, trusted: false });
let widget = this._rendermime.render(mimeModel);
if (layout.widgets.length === 2) {
// The toolbar is layout.widgets[0]
layout.widgets[1].dispose();
}
layout.addWidget(widget);
return widget;
}
private _updateRenderedInput(): Promise {
let model = this.model;
let text = (model && model.value.text) || DEFAULT_MARKDOWN_TEXT;
// Do not re-render if the text has not changed.
if (text !== this._prevText) {
let mimeModel = new MimeModel({ data: { 'text/markdown': text } });
if (!this._renderer) {
this._renderer = this._rendermime.createRenderer('text/markdown');
this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
}
this._prevText = text;
return this._renderer.renderModel(mimeModel);
}
return Promise.resolve(void 0);
}
private _updateRenderedInput(): Promise {
let model = this.model;
let text = (model && model.value.text) || DEFAULT_MARKDOWN_TEXT;
// Do not re-render if the text has not changed.
if (text !== this._prevText) {
let mimeModel = new MimeModel({ data: { 'text/markdown': text } });
if (!this._renderer) {
this._renderer = this._rendermime.createRenderer('text/markdown');
this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
}
this._prevText = text;
return this._renderer.renderModel(mimeModel);
}
return Promise.resolve(void 0);
}
private _updateRenderedInput(): Promise {
let model = this.model;
let text = (model && model.value.text) || DEFAULT_MARKDOWN_TEXT;
// Do not re-render if the text has not changed.
if (text !== this._prevText) {
let mimeModel = new MimeModel({ data: { 'text/markdown': text } });
if (!this._renderer) {
this._renderer = this._rendermime.createRenderer('text/markdown');
this._renderer.addClass(MARKDOWN_OUTPUT_CLASS);
}
this._prevText = text;
return this._renderer.renderModel(mimeModel);
}
return Promise.resolve(void 0);
}
it('should create a new mime model', () => {
let model = new MimeModel();
expect(model).to.be.a(MimeModel);
});
function createModel(data: JSONObject): IRenderMime.IMimeModel {
return new MimeModel({ data });
}
function createModel(
mimeType: string,
source: JSONValue,
trusted = false
): IRenderMime.IMimeModel {
const data: JSONObject = {};
data[mimeType] = source;
return new MimeModel({ data, trusted });
}