Notes/src/utils.js

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2019-08-31 20:48:37 +03:00
export function renderEquation( equation, element, engine = 'katex', display = false ) {
if ( engine === 'mathjax' && typeof katex !== 'mathjax' ) {
if (display) {
element.innerHTML = '\\[' + equation + '\\]';
} else {
element.innerHTML = '\\(' + equation + '\\)';
}
/* eslint-disable */
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, element ] );
/* eslint-enable */
2019-09-17 16:19:35 +03:00
} else if ( engine === 'katex' && typeof katex !== 'undefined' ) {
2019-08-31 20:48:37 +03:00
/* eslint-disable */
katex.render( equation, element, {
throwOnError: false,
displayMode: display
} );
/* eslint-enable */
2019-09-17 16:19:35 +03:00
} else if ( typeof engine === 'function' ) {
engine(equation, element, display);
2019-08-31 20:48:37 +03:00
} else {
element.innerHTML = equation;
2019-09-17 16:19:35 +03:00
console.warn( `math-tex-typesetting-missing: Missing the mathematical typesetting engine (${engine}) for tex.` );
2019-08-31 20:48:37 +03:00
}
}
export function getSelectedMathModelWidget( selection ) {
const selectedElement = selection.getSelectedElement();
if ( selectedElement && selectedElement.is( 'mathtex' ) ) {
return selectedElement;
}
return null;
}