mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-09-02 21:42:15 +08:00
Add output options
This commit is contained in:
parent
fe3c7ba393
commit
4bae994b4f
@ -2,7 +2,8 @@ import Command from '@ckeditor/ckeditor5-core/src/command';
|
|||||||
import { getSelectedMathModelWidget } from './utils';
|
import { getSelectedMathModelWidget } from './utils';
|
||||||
|
|
||||||
export default class MathCommand extends Command {
|
export default class MathCommand extends Command {
|
||||||
execute( equation, display ) {
|
execute( equation, display, outputType, forceOutputType ) {
|
||||||
|
console.log( 'execute', display, outputType, forceOutputType );
|
||||||
const model = this.editor.model;
|
const model = this.editor.model;
|
||||||
const selection = model.document.selection;
|
const selection = model.document.selection;
|
||||||
const selectedElement = selection.getSelectedElement();
|
const selectedElement = selection.getSelectedElement();
|
||||||
@ -11,11 +12,15 @@ export default class MathCommand extends Command {
|
|||||||
let mathtex;
|
let mathtex;
|
||||||
if ( selectedElement && selectedElement.is( 'mathtex' ) ) {
|
if ( selectedElement && selectedElement.is( 'mathtex' ) ) {
|
||||||
// Update selected element
|
// Update selected element
|
||||||
const mode = selectedElement.getAttribute( 'mode' );
|
const typeAttr = selectedElement.getAttribute( 'type' );
|
||||||
mathtex = writer.createElement( 'mathtex', { equation, mode, display } );
|
|
||||||
|
// Use already set type if found and is not forced
|
||||||
|
const type = forceOutputType ? outputType : typeAttr || outputType;
|
||||||
|
|
||||||
|
mathtex = writer.createElement( 'mathtex', { equation, type, display } );
|
||||||
} else {
|
} else {
|
||||||
// Create new model element
|
// Create new model element
|
||||||
mathtex = writer.createElement( 'mathtex', { equation, mode: 'script', display } );
|
mathtex = writer.createElement( 'mathtex', { equation, type: outputType, display } );
|
||||||
}
|
}
|
||||||
model.insertContent( mathtex );
|
model.insertContent( mathtex );
|
||||||
writer.setSelection( mathtex, 'on' );
|
writer.setSelection( mathtex, 'on' );
|
||||||
|
@ -54,7 +54,7 @@ export default class MathEditing extends Plugin {
|
|||||||
},
|
},
|
||||||
model: ( viewElement, modelWriter ) => {
|
model: ( viewElement, modelWriter ) => {
|
||||||
const equation = viewElement.getChild( 0 ).data.trim();
|
const equation = viewElement.getChild( 0 ).data.trim();
|
||||||
return modelWriter.createElement( 'mathtex', { equation, type: 'script', display: false } );
|
return modelWriter.createElement( 'mathtex', { equation, type: mathConfig.forceOutputType ? mathConfig.outputType : 'script', display: false } );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
// MathJax display way (e.g. <script type="math/tex; mode=display">\sqrt{\frac{a}{b}}</script>)
|
// MathJax display way (e.g. <script type="math/tex; mode=display">\sqrt{\frac{a}{b}}</script>)
|
||||||
@ -67,7 +67,7 @@ export default class MathEditing extends Plugin {
|
|||||||
},
|
},
|
||||||
model: ( viewElement, modelWriter ) => {
|
model: ( viewElement, modelWriter ) => {
|
||||||
const equation = viewElement.getChild( 0 ).data.trim();
|
const equation = viewElement.getChild( 0 ).data.trim();
|
||||||
return modelWriter.createElement( 'mathtex', { equation, type: 'script', display: true } );
|
return modelWriter.createElement( 'mathtex', { equation, type: mathConfig.forceOutputType ? mathConfig.outputType : 'script', display: true } );
|
||||||
}
|
}
|
||||||
} )
|
} )
|
||||||
// CKEditor 4 way (e.g. <span class="math-tex">\( \sqrt{\frac{a}{b}} \)</span>)
|
// CKEditor 4 way (e.g. <span class="math-tex">\( \sqrt{\frac{a}{b}} \)</span>)
|
||||||
@ -86,7 +86,7 @@ export default class MathEditing extends Plugin {
|
|||||||
equation = equation.substring( 2, equation.length - 2 ).trim();
|
equation = equation.substring( 2, equation.length - 2 ).trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
return modelWriter.createElement( 'mathtex', { equation, type: 'span', display: hasDisplayDelimiters } );
|
return modelWriter.createElement( 'mathtex', { equation, type: mathConfig.forceOutputType ? mathConfig.outputType : 'span', display: hasDisplayDelimiters } );
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ export default class MathUI extends Plugin {
|
|||||||
|
|
||||||
// Listen to submit button click
|
// Listen to submit button click
|
||||||
this.listenTo( formView, 'submit', () => {
|
this.listenTo( formView, 'submit', () => {
|
||||||
editor.execute( 'math', formView.equation, formView.displayButtonView.isOn );
|
editor.execute( 'math', formView.equation, formView.displayButtonView.isOn, mathConfig.outputType, mathConfig.forceOutputType );
|
||||||
this._closeFormView();
|
this._closeFormView();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -35,7 +35,12 @@ export function getSelectedMathModelWidget( selection ) {
|
|||||||
|
|
||||||
|
|
||||||
export const defaultConfig = {
|
export const defaultConfig = {
|
||||||
|
/*
|
||||||
|
engine: (equation, element, display) => {
|
||||||
|
console.log(equation, element, display);
|
||||||
|
},
|
||||||
|
*/
|
||||||
engine: 'mathjax',
|
engine: 'mathjax',
|
||||||
outputMode: 'script',
|
outputType: 'script',
|
||||||
forceOutputMode: false
|
forceOutputType: false
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user