复制&在CKEDITOR 4.0中粘贴自定义标签 [英] Copy & Paste custom tags in CKEDITOR 4.0

查看:119
本文介绍了复制&在CKEDITOR 4.0中粘贴自定义标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的HTML中有一些自定义标签。

I have some custom tags inside my HTML.

喜欢< mytag class =atr> text< / mytag> 。我想复制整个标签并粘贴相同的标签。当我尝试复制时我只得到文本,我知道编辑器只支持有效的html标签。像复制和粘贴粗体,斜体等,还有其他方法可以让我的自定义标签复制吗?比如使用CKEDITOR或htmlparser的DTD。任何建议。?

Like <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. 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. Any suggestions.?

推荐答案

评论太久了。我不确定这种方法是否有效 - 取决于复制和粘贴事件的工作方式。我建议您收听粘贴事件,并在粘贴过程中将传入元素从< xxx> 转换为例如< div class =convertedoriginal =xxx> 。 xxx可以是任何标签名称,例如mytag或iloveponies。

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.

然后在保存内容之前,您检查来自CKEditor的数据并将元素转换回其原始状态。该算法可能如下所示:

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. 从CKEditor获取数据

  2. 循环遍历每个DIV元素数据

  3. 检查元素是否具有.converted类

  4. 如果否,请勿对其执行任何操作

  5. 如果是,请获取其原始属性的值(xxx)

  6. 将元素从DIV转换回XXX

  7. 继续保存数据

  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.

这篇关于复制&amp;在CKEDITOR 4.0中粘贴自定义标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆