Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function getRenderers(options) {
if (!_renderers) {
_renderers = standardRendererFactories.filter(f => {
// filter out latex renderer if mathjax is unavailable
if (f.mimeTypes.indexOf("text/latex") >= 0) {
if (options.mathjaxUrl) {
return true;
} else {
console.log("MathJax unavailable");
return false;
}
} else {
return true;
}
});
}
return _renderers;
}
// rendering cells
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);
}
// Initialize the command registry with the bindings.
const commands = new CommandRegistry();
const useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener(
'keydown',
event => {
commands.processKeydownEvent(event);
},
useCapture
);
// Create the cell widget with a default rendermime instance.
const rendermime = new RenderMimeRegistry({ initialFactories });
const cellWidget = new CodeCell({
rendermime,
model: new CodeCellModel({})
}).initializeState();
// Handle the mimeType for the current kernel.
session.kernelChanged.connect(() => {
if (session.kernel) {
void session.kernel.ready.then(() => {
const lang = session.kernel!.info!.language_info;
const mimeType = mimeService.getMimeTypeByLanguage(lang);
cellWidget.model.mimeType = mimeType;
});
}
});
// Initialize the command registry with the bindings.
const commands = new CommandRegistry();
const useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener(
'keydown',
event => {
commands.processKeydownEvent(event);
},
useCapture
);
// Create the cell widget with a default rendermime instance.
const rendermime = new RenderMimeRegistry({ initialFactories });
const cellWidget = new CodeCell({
rendermime,
model: new CodeCellModel({})
});
// Handle the mimeType for the current kernel.
session.kernelChanged.connect(() => {
session.kernel.ready.then(() => {
const lang = session.kernel.info.language_info;
const mimeType = mimeService.getMimeTypeByLanguage(lang);
cellWidget.model.mimeType = mimeType;
});
});
// Start the default kernel.
function createApp(manager: ServiceManager.IManager): void {
// Initialize the command registry with the bindings.
let commands = new CommandRegistry();
let useCapture = true;
// Setup the keydown listener for the document.
document.addEventListener(
'keydown',
event => {
commands.processKeydownEvent(event);
},
useCapture
);
let rendermime = new RenderMimeRegistry({
initialFactories: initialFactories,
latexTypesetter: new MathJaxTypesetter({
url: PageConfig.getOption('mathjaxUrl'),
config: PageConfig.getOption('mathjaxConfig')
})
});
let opener = {
open: (widget: Widget) => {
// Do nothing for sibling widgets for now.
}
};
let docRegistry = new DocumentRegistry();
let docManager = new DocumentManager({
registry: docRegistry,