[xwiki-devs] Crafting method to add a plugin to the CKEditor?
Hello fellow developers, is there some hint to add a plugin (with a button) to the CKEditor? I've met /xwiki/bin/edit/CKEditor/EditSheet?editor=object which is probably the place to start with. I tried adding the extraConfigs variable within the configuration but it seems like this cannot load my plugin. It would be cool to have an extension mechanism for that. thanks in advance. Paul
Hi Paul, On Tue, Aug 2, 2016 at 11:41 PM, Paul Libbrecht <[email protected]> wrote:
Hello fellow developers,
is there some hint to add a plugin (with a button) to the CKEditor?
I've met /xwiki/bin/edit/CKEditor/EditSheet?editor=object which is probably the place to start with.
Yes, but you can also do it without touching CKEditor.EditSheet (if you want to write an extension for instance). See http://jira.xwiki.org/browse/CKEDITOR-46?focusedCommentId=90672&page=com.atl... .
I tried adding the extraConfigs variable within the configuration but it seems like this cannot load my plugin.
I don't know what you mean by "extraConfigs" but you can checkout https://github.com/xwiki-contrib/application-ckeditor/blob/application-ckedi... to see how to use an external plugin (in the first version of the CKEditor integration the Source plugin was defined in a wiki page as a proof of concept). It would be cool to have an extension mechanism for that.
See http://jira.xwiki.org/browse/CKEDITOR-16 . Hope this helps, Marius
thanks in advance.
Paul _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Cool, thanks Marius, I was able to add something that adds a button to the CKEditor by using approximately the following snippet: require(['jquery'], function($) {$(document).ready(function() { if(XWiki.contextaction=='edit') { require(['deferred!ckeditor'], function(ckeditorPromise) { ckeditorPromise.done(function(ckeditor) { ckeditor.on('instanceCreated', function(event) { event.editor.once('configLoaded', function(event) { ckeditor.tools.extend(event.editor.config, { plugins: 'ckeditor_wiris', }, true); }); ckeditor.plugins.addExternal('ckeditor_wiris', '/wiriseditorapp/ckeditor_wiris/plugin.js'); }); }); }); }})}); within CKEditor.EditSheet2 which loads everywhere (I hope syntax-colored html doesn't bother people's reading, it's a present of IntelliJ IDEA). I am sure there are less verbose ways to do it! One thing, however, where this is incomplete is that this only evaluates if XWiki.contextaction=='edit' instead of checking for something more realistic such as the availability of one or several CKeditors. It doesn't trigger errors so it's not too bad (it is because of the promise?). With comments on optimization, I think we should start a snippet page or something such. Now, the content that is created with this plugin (MathML elements) is being killed by the rendering framework. I guess I can either: - let it be wrapped as a macro - adjust the rendering framework to respect that bit I think the second is impossible though. Or? thanks Paul
is there some hint to add a plugin (with a button) to the CKEditor? Yes, but you can also do it without touching CKEditor.EditSheet (if you want to write an extension for instance). See http://jira.xwiki.org/browse/CKEDITOR-46?focusedCommentId=90672&page=com.atl... . I tried adding the extraConfigs variable within the configuration but it seems like this cannot load my plugin. I don't know what you mean by "extraConfigs" but you can checkout https://github.com/xwiki-contrib/application-ckeditor/blob/application-ckedi... to see how to use an external plugin (in the first version of the CKEditor integration the Source plugin was defined in a wiki page as a proof of concept).
It would be cool to have an extension mechanism for that.
See http://jira.xwiki.org/browse/CKEDITOR-16 . I voted.
On Fri, Aug 5, 2016 at 11:53 AM, Paul Libbrecht <[email protected]> wrote:
Cool, thanks Marius,
I was able to add something that adds a button to the CKEditor by using approximately the following snippet:
require(['jquery'], function($) {$(document).ready(function() { if(XWiki.contextaction=='edit') { require(['deferred!ckeditor'], function(ckeditorPromise) { ckeditorPromise.done(function(ckeditor) { ckeditor.on('instanceCreated', function(event) { event.editor.once('configLoaded', function(event) { ckeditor.tools.extend(event.editor.config, { plugins: 'ckeditor_wiris', }, true); }); ckeditor.plugins.addExternal('ckeditor_wiris', '/wiriseditorapp/ckeditor_wiris/plugin.js'); }); }); }); }})});
within CKEditor.EditSheet2 which loads everywhere (I hope syntax-colored html doesn't bother people's reading, it's a present of IntelliJ IDEA). I am sure there are less verbose ways to do it!
One thing, however, where this is incomplete is that this only evaluates if XWiki.contextaction=='edit' instead of checking for something more realistic such as the availability of one or several CKeditors. It
You don't need to check for XWiki.contextaction=='edit'. That's the goal of the deferred module loading http://platform.xwiki.org/xwiki/bin/view/DevGuide/JavaScriptAPI#HDeferredDep... . The ckeditorPromise will be resolved when the editor is available (either in edit mode or anywhere else the editor is loaded). In other words, you don't pull CKEditor, you are notified if someone else pulls it. Of course, you still need to load the JSX on each page. In order to load your JSX only when the CKEditor code is loaded we would need a UI extension point (that the CKEditor would execute each time its code is loaded).
doesn't trigger errors so it's not too bad (it is because of the promise?). With comments on optimization, I think we should start a snippet page or something such.
Now, the content that is created with this plugin (MathML elements) is being killed by the rendering framework. I guess I can either: - let it be wrapped as a macro - adjust the rendering framework to respect that bit
I think the second is impossible though. Or?
Very difficult anyway, so you should try the wiki macro approach first. Hope this helps, Marius
thanks
Paul
is there some hint to add a plugin (with a button) to the CKEditor? Yes, but you can also do it without touching CKEditor.EditSheet (if you want to write an extension for instance). See http://jira.xwiki.org/browse/CKEDITOR-46?focusedCommentId= 90672&page=com.atlassian.jira.plugin.system.issuetabpanels: comment-tabpanel#comment-90672 . I tried adding the extraConfigs variable within the configuration but it seems like this cannot load my plugin. I don't know what you mean by "extraConfigs" but you can checkout https://github.com/xwiki-contrib/application-ckeditor/ blob/application-ckeditor-1.0/ui/src/main/resources/ CKEditor/EditSheet.xml#L154 to see how to use an external plugin (in the first version of the CKEditor integration the Source plugin was defined in a wiki page as a proof of concept).
It would be cool to have an extension mechanism for that.
See http://jira.xwiki.org/browse/CKEDITOR-16 . I voted.
_______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Thank you Marius,
the deferred module loading http://platform.xwiki.org/xwiki/bin/view/DevGuide/JavaScriptAPI#HDeferredDep... . The ckeditorPromise will be resolved when the editor is available (either in edit mode or anywhere else the editor is loaded). In other words, you don't pull CKEditor, you are notified if someone else pulls it. That has worked very well. you should try the wiki macro approach first. Ok
The wiris editor I'm trying to integrate produces MathML-islands which, currently, gets removed by the rendering conversion. Is there a good hook at the XWiki or CKEditor level I could bind to, so that I change the content before it gets posted to the conversion? I'd convert the MathML islands to macros which would, depending on the browser, render to MathML or to images. thanks in advance. Paul
On Fri, Aug 12, 2016 at 4:04 PM, Paul Libbrecht <[email protected]> wrote:
Thank you Marius,
the deferred module loading http://platform.xwiki.org/xwiki/bin/view/DevGuide/JavaScriptAPI# HDeferredDependencyLoading . The ckeditorPromise will be resolved when the editor is available (either in edit mode or anywhere else the editor is loaded). In other words, you don't pull CKEditor, you are notified if someone else pulls it. That has worked very well. you should try the wiki macro approach first. Ok
The wiris editor I'm trying to integrate produces MathML-islands which, currently, gets removed by the rendering conversion.
Is there a good hook at the XWiki or CKEditor level I could bind to, so that I change the content before it gets posted to the conversion? I'd convert the MathML islands to macros which would, depending on the browser, render to MathML or to images.
CKEditor provides http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-toHtml and http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-toDataFormat . You could also write a https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwik... that is called on the server side before the HTML is converted to wiki syntax. Hope this helps, Marius
thanks in advance.
Paul _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
Hello Marius,
CKEditor provides http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-toHtml and http://docs.ckeditor.com/#!/api/CKEDITOR.editor-event-toDataFormat . Can you give an example on how to hook it? At least hooking it in the instanceCreated (calling then ckeditor.on( 'toDataFormat', function( evt) { console.log("toDataFormat"); }, null, null, 3 ); did not seem to call it.
Should it be called later? One of the alternative possibilities I have is to let the islands be directly converted to a macro-call right after they got edited. This is better for a predictable wysiwyg effect. However how could I let the macro-islands be edited using the wiris plugin instead of the default macro-editor when they are double clicked??
You could also write a https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwik... that is called on the server side before the HTML is converted to wiki syntax. I fear this is not pluggeable.
thanks paul
Hello Marius, (for the hook, well, I found a polling solution which worked. But surely something else would be better. No urgency) Now, I am still fighting trying to inject the appropriate reformulation from an image or a math element (which the Wiris plugin for the CKEditor converts to) to a Macro. As suggested I use CKEditor.editor's toHtml and toDataFormat events. I've managed to catch the parsing stage and replace the MathML macros by math elements which then get converted by the Wiris plugin to their image (including listeners for them to edit when double clicked) by hooking into the level 6 of parsing. How can I know which level I can hook to to reformulate the content just before it is sent to the conversion server? I've tried levels from 5 to 15 of the event toDataFormat and 15 seems to be the best idea... Unfortunately the changes are not sent, an earlier version is sent... Can it be that there's been a copy of the data before that? Where should I look? thanks in advance. Paul
Hi Paul, The CKEditor plugin that handles wiki macros is https://github.com/xwiki-contrib/application-ckeditor/blob/master/plugins/sr... . It uses https://github.com/xwiki-contrib/application-ckeditor/blob/master/plugins/sr... . Be aware that the macro output is not submitted. You need to update the macro markers. Also node that wiki macros are handles as CKEditor Widgets http://docs.ckeditor.com/#!/guide/widget_sdk_tutorial_1 . Hope this helps, Marius On Wed, Aug 31, 2016 at 5:46 PM, Paul Libbrecht <[email protected]> wrote:
Hello Marius,
(for the hook, well, I found a polling solution which worked. But surely something else would be better. No urgency)
Now, I am still fighting trying to inject the appropriate reformulation from an image or a math element (which the Wiris plugin for the CKEditor converts to) to a Macro.
As suggested I use CKEditor.editor's toHtml and toDataFormat events. I've managed to catch the parsing stage and replace the MathML macros by math elements which then get converted by the Wiris plugin to their image (including listeners for them to edit when double clicked) by hooking into the level 6 of parsing.
How can I know which level I can hook to to reformulate the content just before it is sent to the conversion server? I've tried levels from 5 to 15 of the event toDataFormat and 15 seems to be the best idea... Unfortunately the changes are not sent, an earlier version is sent... Can it be that there's been a copy of the data before that? Where should I look?
thanks in advance.
Paul _______________________________________________ devs mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/devs
participants (2)
-
Marius Dumitru Florea -
Paul Libbrecht