Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export async function renderEquation(
previewClassName: Array<string> = [],
katexRenderOptions: KatexOptions = {}
): Promise<void> {
if ( engine == 'mathjax' ) {
if ( engine == 'mathjax' && window.MathJax !== undefined ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be global.window.MathJax

if ( isMathJaxVersion3( MathJax ) ) {
selectRenderMode(
element,
Expand Down Expand Up @@ -129,7 +129,7 @@ export async function renderEquation(
);
}
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
} else if ( engine === 'katex' ) {
} else if ( engine === 'katex' && window.katex !== undefined ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be global.window.katex

selectRenderMode(
element,
preview,
Expand Down
49 changes: 49 additions & 0 deletions tests/lazyload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import ClassicEditor from '@ckeditor/ckeditor5-editor-classic/src/classiceditor';
import MathUI from '../src/mathui';
import type { EditorConfig } from '@ckeditor/ckeditor5-core/src/editor/editorconfig';
import { expect } from 'chai';

describe( 'Lazy load', () => {
let editorElement: HTMLDivElement;
let editor: ClassicEditor;
let lazyLoadInvoked: boolean;
let mathUIFeature: MathUI;

function buildEditor( config: EditorConfig ) {
return ClassicEditor
.create( editorElement, {
...config,
plugins: [ MathUI ]
} )
.then( newEditor => {
editor = newEditor;
mathUIFeature = editor.plugins.get( MathUI );
} );
}

beforeEach( () => {
editorElement = document.createElement( 'div' );
document.body.appendChild( editorElement );

lazyLoadInvoked = false;
} );

afterEach( () => {
editorElement.remove();
return editor.destroy();
} );

it( 'initializes lazy load for KaTeX', async () => {
await buildEditor( {
math: {
engine: 'katex',
lazyLoad: async () => {
lazyLoadInvoked = true;
}
}
} );

mathUIFeature._showUI();
expect( lazyLoadInvoked ).to.be.true;
} );
} );