Skip to content

Commit

Permalink
Load mathjax manually
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Oct 30, 2023
1 parent 5555c21 commit ca53840
Show file tree
Hide file tree
Showing 4 changed files with 4,164 additions and 2,700 deletions.
1 change: 1 addition & 0 deletions packages/voila/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ export * from './tools';
export * from './plugins/tree/browser';
export * from './plugins/tree/listing';
export * from './plugins/themes/thememanager';
export * from './plugins/widget/renderedcells';
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import {
IWidgetRegistryData
} from '@jupyter-widgets/base';

import { VoilaApp } from '../app';
import { VoilaApp } from '../../app';

import { Widget } from '@lumino/widgets';
import { RenderedCells } from './renderedcells';

const WIDGET_MIMETYPE = 'application/vnd.jupyter.widget-view+json';

Expand Down Expand Up @@ -112,6 +113,10 @@ export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = {
app: JupyterFrontEnd,
rendermime: IRenderMimeRegistry
): Promise<void> => {
// 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) => {
Expand Down Expand Up @@ -154,7 +159,7 @@ export const renderOutputsPlugin: JupyterFrontEndPlugin<void> = {
});
const node = document.getElementById('rendered_cells');
if (node) {
const cells = new Widget({ node });
const cells = new RenderedCells({ node });
app.shell.add(cells, 'main');
}
}
Expand Down
22 changes: 22 additions & 0 deletions packages/voila/src/plugins/widget/renderedcells.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Message } from '@lumino/messaging';
import { Widget } from '@lumino/widgets';

/**
* Wrapper widget of rendered cells, this class converts the Lumino resize
* message to a window event. It helps fix the zero-heigh issue of some
* widgets
*
*/
export class RenderedCells extends Widget {
processMessage(msg: Message): void {
super.processMessage(msg);
switch (msg.type) {
case 'resize':
window.dispatchEvent(new Event('resize'));
break;

default:
break;
}
}
}

0 comments on commit ca53840

Please sign in to comment.