forked from voila-dashboards/voila
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate jupyter widgets manager extension
- Loading branch information
1 parent
f1722f4
commit 7d13a63
Showing
22 changed files
with
399 additions
and
209 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/*************************************************************************** | ||
* Copyright (c) 2018, Voilà contributors * | ||
* Copyright (c) 2018, QuantStack * | ||
* * | ||
* Distributed under the terms of the BSD 3-Clause License. * | ||
* * | ||
* The full license is in the file LICENSE, distributed with this software. * | ||
****************************************************************************/ | ||
|
||
import { | ||
JupyterFrontEnd, | ||
JupyterFrontEndPlugin | ||
} from '@jupyterlab/application'; | ||
|
||
import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; | ||
|
||
import { Widget } from '@lumino/widgets'; | ||
import { RenderedCells } from './renderedcells'; | ||
|
||
/** | ||
* The plugin that renders outputs. | ||
*/ | ||
export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = { | ||
id: '@voila-dashboards/voila:render-outputs', | ||
autoStart: true, | ||
requires: [IRenderMimeRegistry], | ||
activate: (app: JupyterFrontEnd, rendermime: IRenderMimeRegistry): void => { | ||
// This "app.started.then" is a trick to make sure we render the output only when all plugins are loaded | ||
// Not using await here because we want this function to return immediately | ||
// Otherwise it prevents the application to start and resolve the "started" promise... | ||
app.started.then(async () => { | ||
// TODO: Typeset a fake element to get MathJax loaded, remove this hack once | ||
// MathJax 2 is removed. | ||
await rendermime.latexTypesetter?.typeset(document.createElement('div')); | ||
|
||
// Render latex in markdown cells | ||
const mdOutput = document.body.querySelectorAll('div.jp-MarkdownOutput'); | ||
mdOutput.forEach((md) => { | ||
rendermime.latexTypesetter?.typeset(md as HTMLElement); | ||
}); | ||
// Render outputs | ||
const cellOutputs = document.body.querySelectorAll( | ||
'script[type="application/vnd.voila.cell-output+json"]' | ||
); | ||
cellOutputs.forEach(async (cellOutput) => { | ||
const model = JSON.parse(cellOutput.innerHTML); | ||
|
||
const mimeType = rendermime.preferredMimeType(model.data, 'any'); | ||
|
||
if (!mimeType) { | ||
return null; | ||
} | ||
const output = rendermime.createRenderer(mimeType); | ||
output.renderModel(model).catch((error) => { | ||
// Manually append error message to output | ||
const pre = document.createElement('pre'); | ||
pre.textContent = `Javascript Error: ${error.message}`; | ||
output.node.appendChild(pre); | ||
|
||
// Remove mime-type-specific CSS classes | ||
pre.className = 'lm-Widget jp-RenderedText'; | ||
pre.setAttribute('data-mime-type', 'application/vnd.jupyter.stderr'); | ||
}); | ||
|
||
output.addClass('jp-OutputArea-output'); | ||
|
||
if (cellOutput.parentElement) { | ||
const container = cellOutput.parentElement; | ||
|
||
container.removeChild(cellOutput); | ||
|
||
// Attach output | ||
Widget.attach(output, container); | ||
} | ||
}); | ||
const node = document.getElementById('rendered_cells'); | ||
if (node) { | ||
const cells = new RenderedCells({ node }); | ||
app.shell.add(cells, 'main'); | ||
} | ||
}); | ||
} | ||
}; |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.