ckeditor如何允许.insertHtml(< customTag myAttr ='value'">< / customTag>“) [英] ckeditor how to allow for .insertHtml("<customTag myAttr='value'"></customTag>")

查看:242
本文介绍了ckeditor如何允许.insertHtml(< customTag myAttr ='value'">< / customTag>“)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  var currentDialog = CKEDITOR.dialog.getCurrent(); 
currentDialog ._。editor.insertHtml(< customTag myAttr ='var'>< / customTag>);

抛出一个错误, TypeError:无法读取属性'isBlock'undefined



如果我尝试 .insertHtml(< span> hello< / span>)

如何更改ckeditor允许我通过 .insertHtml()指定我自己的自定义html标签

code>?我想改变它,像< span class ='custom'... 或类似的东西,但我必须处理遗产CMS文章。使用最新ckeditor。感谢。

解决方案


  1. 您需要修改 CKEDITOR.dtd 对象,因此编辑器将知道此标记并正确解析HTML并处理DOM:

      CKEDITOR.dtd。 customtag = {em:1}; //可以包含的标签名称列表。 
    CKEDITOR.dtd。$ block.customtag = 1; //选择$ block或$ inline。
    CKEDITOR.dtd.body.customtag = 1; //正文可能包含customtag。


  2. 您必须允许此标记及其样式/ attrs / =http://docs.ckeditor.com/#!/guide/plugin_sdk_integration_with_acf =nofollow>高级内容过滤器:

      editor.filter.allow('customtag [myattr]','myfeature'); 


不幸的是,由于一些缓存,在CKEditor加载后,您不能修改DTD对象的情况 - 您需要在创建时修改它。所以要这样做:


  1. 克隆 CKEditor存储库 CKEditor预设存储库

    > core / dtd.js 代码。


  2. 按照 README.md - 唯一的要求是Java(对不起 - Google Closure Compiler:P)和Bash。


strong> PS。在插入未知元素时,不应抛出此错误,因此我报告了 http: //dev.ckeditor.com/ticket/10339 ,并解决这种不便( http:// dev .ckeditor.com / ticket / 10340


var currentDialog = CKEDITOR.dialog.getCurrent();
currentDialog._.editor.insertHtml("<customTag myAttr='var'></customTag>");

Throws an error, TypeError: Cannot read property 'isBlock' of undefined

If I try .insertHtml("<span>hello</span>") it works just fine.

How can I change ckeditor to allow me to specify my own custom html tags via .insertHtml()? I'd love to just change it to be something like <span class='custom'... or something like that, but I'm having to deal with legacy CMS articles. Using latest ckeditor. Thanks.

解决方案

  1. You need to modify CKEDITOR.dtd object so editor will know this tag and correctly parse HTML and process DOM:

    CKEDITOR.dtd.customtag = { em:1 };        // List of tag names it can contain.
    CKEDITOR.dtd.$block.customtag = 1;        // Choose $block or $inline.
    CKEDITOR.dtd.body.customtag = 1;          // Body may contain customtag.
    

  2. You need to allow for this tag and its styles/attrs/classes in Advanced Content Filter:

    editor.filter.allow( 'customtag[myattr]', 'myfeature' );
    

Unfortunately, due to some caching, in certain situations you cannot modify DTD object after CKEditor is loaded - you need to modify it when it is created. So to do that:

  1. Clone the CKEditor repository or CKEditor presets repository.

  2. Modify core/dtd.js code.

  3. And build your minified package following instructions in README.md - the only requirements are Java (sorry - Google Closure Compiler :P) and Bash.

PS. That error should not be thrown when unknown element is inserted, so I reported http://dev.ckeditor.com/ticket/10339 and to solve this inconvenience http://dev.ckeditor.com/ticket/10340.

这篇关于ckeditor如何允许.insertHtml(&lt; customTag myAttr ='value'&quot;&gt;&lt; / customTag&gt;“)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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