简体   繁体   English

在CKEDITOR 4.0中复制和粘贴自定义标签

[英]Copy & Paste custom tags in CKEDITOR 4.0

I have some custom tags inside my HTML. 我的HTML内有一些自定义标签。

Like <mytag class="atr">text</mytag> . 就像<mytag class="atr">text</mytag> I want to copy this whole tag and paste the same. 我要复制整个标签并粘贴相同的标签。 When i try to copy i am getting only the text, i know editor will support only valid html tags. 当我尝试复制时,我只会得到文本,我知道编辑器将仅支持有效的html标签。 Like copy and paste the bold,italic etc., Is there any other way to make my custom tag to copy?. 像复制并粘贴粗体,斜体等一样,还有其他方法可以使我的自定义标签复制吗? Like using the DTD of CKEDITOR or htmlparser. 就像使用CKEDITOR或htmlparser的DTD一样。 Any suggestions.? 有什么建议么。?

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" > . 我建议您听“粘贴”事件,并在粘贴期间将传入的元素从<xxx>转换为例如<div class="converted" original="xxx" > The xxx can be any tag name, such as mytag or iloveponies. xxx可以是任何标签名称,例如mytag或iloveponies。

Then when before saving your content you examine the data from CKEditor and convert the elements back to their original statuses. 然后,在保存内容之前,请检查来自CKEditor的数据,并将元素转换回其原始状态。 The algorithm might look like this: 该算法可能如下所示:

  1. Get data from CKEditor 从CKEditor获取数据
  2. Loop through each DIV element from data 从数据循环遍历每个DIV元素
  3. Check if element has the .converted class 检查元素是否具有.converted类
  4. If no, don't do anything to it 如果否,则不执行任何操作
  5. If yes, get the value of it's "original" attribute (xxx) 如果是,请获取其“原始”属性的值(xxx)
  6. Convert the element from DIV back to XXX 将元素从DIV转换回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. 不要忘记指定allowedContent-和requiredContent-Attributes。 And modify the dtd to make the tag editable. 并修改dtd以使标签可编辑。

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'
            }
        },
        ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM