Copy & Paste custom tags in CKEDITOR 4.0

随声附和 提交于 2019-12-01 01:38:23

Too long to be a comment. I'm not sure that this method will work - depends on how the copy&paste events work. I suggestion that you listen to the "paste" event and during the paste you convert the incoming elements from <xxx> to for example <div class="converted" original="xxx" >. The xxx can be any tag name, such as mytag or iloveponies.

Then when before saving your content you examine the data from CKEditor and convert the elements back to their original statuses. The algorithm might look like this:

  1. Get data from CKEditor
  2. Loop through each DIV element from data
  3. Check if element has the .converted class
  4. If no, don't do anything to it
  5. If yes, get the value of it's "original" attribute (xxx)
  6. Convert the element from DIV back to XXX
  7. Continue saving your data

You can do that in the fronted or the backend, most likely either will have tools available for this kind of operation. I'm guessing that fronted will be easier though.

You can create a Widget for each custom tag. Don't forget to specify the allowedContent- and requiredContent-Attributes. And modify the dtd to make the tag editable.

For example:

CKEDITOR.dtd.$editable['mytag'] = 1;    
editor.widgets.add('mytagWidget', {
        allowedContent: 'mytag(atr)',
        requiredContent: 'mytag',
        template: '<mytag class="atr">text</mytag>',
        editables: {
            text: {
                selector: '.atr'
            }
        },
        ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!