In my Ckeditor (version 4.8) I have a custom citation
tag like <citation>page 2</citation>
. My problem is that when I copy paste the content like <citation>page 2</citation>
, To be or not to be<citation>page 2</citation>
. My custom tag gets lost and result is To be or not to bepage 2
instead of To be or not to be<citation>page 2</citation>
.
In my config I allow my custom tag:
config = {extraAllowedContent: 'citation'}
My current workaround is the following:
init: function(editor){
editor.on('contentDom',function()
{
editor.on('paste', function(e)
{
var focusManager = new CKEDITOR.focusManager(editor);
if(focusManager.hasFocus)
{
e.data.dataValue = "<span class='paste'>" + e.data.dataValue + "</span>" //wraps it in a utils tag
}
});
editor.on('afterPaste', function(e)
{
var focusManager = new CKEDITOR.focusManager(editor); //unwraps it again
if(focusManager.hasFocus)
{
var $content = $("<div/>").html(editor.getData());
$content.find("span.paste").children().unwrap();
editor.setData($content.html());
}
});
});
},
Before pasting it wraps content to be pasted into a span and removes it after pasting again. I know there is a similiar question about my problem. However, I wonder what would be the correct way. Can somebody help me? Thanks.