Add engine option

This commit is contained in:
Sauli Anto 2019-09-17 16:19:35 +03:00
parent a89cadeac5
commit dbaaa96ae9
6 changed files with 23 additions and 15 deletions

View File

@ -30,7 +30,6 @@ export default class MathCommand extends Command {
this.isEnabled = isAllowed;
const selectedEquation = getSelectedMathModelWidget( selection );
console.log(selectedEquation);
this.value = selectedEquation ? selectedEquation.getAttribute( 'equation' ) : null;
this.display = selectedEquation ? selectedEquation.getAttribute( 'display' ) : null;
}

View File

@ -37,7 +37,9 @@ export default class MathEditing extends Plugin {
_defineConverters() {
const conversion = this.editor.conversion;
const mathConfig = this.editor.config.get( 'math' );
// Todo: better checks
const engine = typeof mathConfig !== 'undefined' && typeof mathConfig.engine !== 'undefined' ? mathConfig.engine : 'mathjax';
// View -> Model
conversion.for( 'upcast' )
@ -120,7 +122,7 @@ export default class MathEditing extends Plugin {
const uiElement = viewWriter.createUIElement( 'div', null, function( domDocument ) {
const domElement = this.toDomElement( domDocument );
renderEquation( equation, domElement, 'mathjax', display );
renderEquation( equation, domElement, engine, display );
return domElement;
} );

View File

@ -57,7 +57,10 @@ export default class MathUI extends Plugin {
_createFormView() {
const editor = this.editor;
const mathCommand = editor.commands.get( 'math' );
const engine = 'mathjax';
const mathConfig = editor.config.get( 'math' );
// Todo: better checks
const engine = typeof mathConfig !== 'undefined' && typeof mathConfig.engine !== 'undefined' ? mathConfig.engine : 'mathjax';
const formView = new MainFormView( editor.locale, engine );

View File

@ -6,7 +6,7 @@ export default class MathView extends View {
super( locale );
this.engine = engine;
this.set( 'value', '' );
this.set( 'display', false);

View File

@ -8,17 +8,18 @@ export function renderEquation( equation, element, engine = 'katex', display = f
/* eslint-disable */
MathJax.Hub.Queue( [ 'Typeset', MathJax.Hub, element ] );
/* eslint-enable */
}
else if ( engine === 'katex' && typeof katex !== 'undefined' ) {
} else if ( engine === 'katex' && typeof katex !== 'undefined' ) {
/* eslint-disable */
katex.render( equation, element, {
throwOnError: false,
displayMode: display
} );
/* eslint-enable */
} else if ( typeof engine === 'function' ) {
engine(equation, element, display);
} else {
element.innerHTML = equation;
console.warn( 'math-tex-typesetting-missing: Missing the mathematical typesetting engine for tex.' );
console.warn( `math-tex-typesetting-missing: Missing the mathematical typesetting engine (${engine}) for tex.` );
}
}

View File

@ -6,6 +6,16 @@
flex-direction: row;
flex-wrap: nowrap;
& .ck.ck-math-preview {
user-select: none;
}
/* FIXME: mathjax isn't working with .ck.ck-reset_all * without this fix*/
& .ck.ck-math-preview * {
vertical-align: initial;
text-align: center;
}
@mixin ck-media-phone {
flex-wrap: wrap;
@ -25,11 +35,4 @@
flex-basis: 50%;
}
}
}
/* FIXME: mathjax isn't working with .ck.ck-reset_all * without this fix*/
.ck.ck-math-preview * {
vertical-align: initial;
text-align: center;
}