Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initialize(attributes, options) {
super.initialize(attributes, options)
// The output area model is trusted since widgets are
// only rendered in trusted contexts.
this._outputs = new OutputAreaModel({trusted: true});
this.listenTo(this, 'change:msg_id', this.onMsgIdChange);
this.onMsgIdChange();
}
it('should create an output area widget', () => {
let factory = new CodeCellWidget.ContentFactory({ editorFactory });
let model = new OutputAreaModel();
let output = factory.createOutputArea({
model,
rendermime,
contentFactory: OutputAreaWidget.defaultContentFactory
});
expect(output).to.be.an(OutputAreaWidget);
});
it('should accept options', () => {
const contentFactory = new OutputAreaModel.ContentFactory();
model = new OutputAreaModel({
values: NBTestUtils.DEFAULT_OUTPUTS,
contentFactory,
trusted: true
});
expect(model.contentFactory).to.equal(contentFactory);
expect(model.trusted).to.equal(true);
});
});
it('should accept options', () => {
let contentFactory = new OutputAreaModel.ContentFactory();
model = new OutputAreaModel({
values: DEFAULT_OUTPUTS,
contentFactory,
trusted: true
});
expect(model.contentFactory).to.be(contentFactory);
expect(model.trusted).to.be(true);
});
beforeEach(() => {
model = new OutputAreaModel();
});
beforeEach(() => {
model = new OutputAreaModel({ values: DEFAULT_OUTPUTS, trusted: true });
widget = new LogOutputAreaWidget({ rendermime, model });
});
renderCell($element) {
const outputArea = new OutputArea({
model: new OutputAreaModel({ trusted: true }),
rendermime: new RenderMimeRegistry({
initialFactories: this.getRenderers()
})
});
const $cell = this._$('div', this.classNames.cell);
$element.replaceWith($cell);
const $input = this._$('div', this.classNames.input);
$cell.appendChild($input);
const $button = this._$('button', this.classNames.button, 'run');
$cell.appendChild($button);
const $output = this._$('div', this.classNames.output);
$cell.appendChild($output);
Widget.attach(outputArea, $output);
const cm = new CodeMirror($input, {
componentDidMount() {
this.setState({ content: this.props.children })
const renderers = standardRendererFactories.filter(factory =>
factory.mimeTypes.includes('text/latex') ? window.MathJax : true
)
const outputArea = new OutputArea({
model: new OutputAreaModel({ trusted: true }),
rendermime: new RenderMimeRegistry({ initialFactories: renderers }),
})
const cm = new CodeMirror(this.inputRef, {
value: this.props.children.trim(),
mode: this.props.lang,
theme: this.props.theme,
})
this.setState({ cm })
const runCode = wrapper => {
const value = cm.getValue()
this.execute(outputArea, wrapper ? wrapper(value) : value)
}
const setValue = value => cm.setValue(value)
cm.setOption('extraKeys', { 'Shift-Enter': runCode })
});
}
let renderMime = new RenderMimeRegistry(renderers);
let manager = options.manager;
renderMime.addFactory(
{
safe: false,
mimeTypes: [WIDGET_MIMETYPE],
createRenderer: options => new WidgetRenderer(options, manager),
},
1
);
let model = new OutputAreaModel({ trusted: true });
let outputArea = new OutputArea({
model: model,
rendermime: renderMime,
});
$element.replaceWith($cell);
let $cm_element = $("<div class="thebelab-input">");
$cell.append($cm_element);
$cell.append(
$("<button class="thebelab-button thebelab-run-button">")
.text("run")
.attr("title", "run this cell")
.click(execute)
);</button></div>