Comments (6)
Sorry for the delayed response, i somehow missed the notification.
This issue occurs even without loading the plugin. Tested with a fresh install of ckeditor5 v16. I will open an issue in official ckeditor5.
It is remarkable that the issue occurs only during editor initialization. The following code works normally:
ck5editor = ClassicEditor
.create( editorDiv )
.then( (editor) => {
//do nothing in here
})
....
//after editor is rendered
ck5editor.setData("\\[a+b\\]")
from ckeditor5-math-preview.
The block of code below needs to be adjusted to not add the text twice when setData is called when containing a latex formula (even when its prefilled in a textarea).
this.editor.editing.model.change( writer => {
if (!modelRng.isCollapsed){
writer.remove(modelRng);
}
const txt = writer.createText(newmath)
writer.insert(txt, modelPos0);
writer.setSelection(modelPos0.getShiftedBy(2));
} );
from ckeditor5-math-preview.
(copied from here ckeditor/ckeditor5#5906)
I can confirm that a plain Ckeditor 5 version works correctly: https://jsfiddle.net/Lvywge37/4/
The error seems to be related to the ckeditor5-math-preview plugin: https://github.com/centaur54dev/ckeditor5-math-preview#readme
An example which envisions the wrong behavior can be seen here: https://jsfiddle.net/ub472vq6/
from ckeditor5-math-preview.
I think you need to come back to the original code block above and play around with the .change and use inside it (or change it) to enqueueChange ao you can make the order right.
.change(...
. enqueueChange(..
Have no access to test it on your plugin though.
model.change( writer => {
console.log( 1 );
model.enqueueChange( writer => {
console.log( 2 );
} );
console.log( 3 );
} );
// Will log: 1, 3, 2.
from ckeditor5-math-preview.
After some more testing it seems that the problem is caused by the MathJax library, that typesets the early document. So you need to prevent MathJax from automatically rendering the page at startup. This can be done with the skipStartupTypeset
directive. A quick example on custom MathJax loading:
<script async src='https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS_HTML'></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
skipStartupTypeset:true
});
</script>
Alternatively, you may delay the setData command until MathJax has finished rendering. Just push the setData command in the MathJax queue:
MathJax.Hub.Queue(function () {
editor.setData("<p>\\[x=0\\]</p>");
});
Make sure though to run the above code after MathJax is initialised. A working jsffidle is here.
@nexterday , the code block you refer to, executes only when the user clicks an option on the popup window. I can't figure out how this interferes with realtime rendering of the ckeditor model.
from ckeditor5-math-preview.
Thanks! This works for me. Issue can be closed.
from ckeditor5-math-preview.
Related Issues (7)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ckeditor5-math-preview.