简体   繁体   English

富文本内容打破了TinyMCE

[英]Rich Text Content Breaks TinyMCE

So I'm working with some content using TinyMCE, and unfortunately it seems that sometimes, the content put into it (RTE blob data from the database) is breaking the script. 因此,我正在使用TinyMCE处理某些内容,但不幸的是,有时放入其中的内容(数据库中的RTE blob数据)正在破坏脚本。

Here is a fiddle of it in action. 这是操作中的一个小提琴

I use a function to set the tinymce.init() , and it works fine, however it seems that something in the RTE data completely breaks the textareas. 我使用一个函数来设置tinymce.init() ,并且工作正常,但是似乎RTE数据中的某些内容完全破坏了文本区域。

Here is the script: 这是脚本:

function initMCE(e) {
    tinymce.init({
        mode:"exact",
        elements:e,
        plugins:"paste",
        height:300,
        width:750,
        toolbar: "bold italic underline, bullist, numlist superscript subscript",
        menubar:false,
        valid_elements : "em/i,li,ul,ol,u,strong/b,sup,sub,p"
    });
}
initMCE("definition");
initMCE("consent");
initMCE("penalty");

And the HTML is simple but: HTML很简单,但是:

<textarea name="definition" id="definition"></textarea>
<textarea name="consent" id="consent"></textarea>
<textarea name="penalty" id="penalty"></textarea>

See the content in the fiddle that's breaking it. 看到小提琴中打破它的内容。 Is there a way to protect my script from input such as this? 有没有办法保护我的脚本不受诸如此类的输入?

Here is the error as well: 这也是错误:

Uncaught TypeError: undefined is not a function tinymce.cachefly.net/4.1/tinymce.min.js:6

This seems to be a bug in TinyMCE . 这似乎是TinyMCE中错误

Reproduction: http://jsfiddle.net/pevans02/6t25w/ 复制: http : //jsfiddle.net/pevans02/6t25w/

A quick fix for this is just make sure there is a space before the comments 快速解决方法是确保评论前有空格

<textarea name="definition" id="definition"> <!-- some comment --></textarea>
<textarea name="consent" id="consent"></textarea>
<textarea name="penalty" id="penalty"></textarea>

JSFiddle Fix Demo JSFiddle修复演示

Added a comment to the bug about it still being in 4.1 在该错误中添加了一条注释,指出它仍然存在于4.1中

Other Fixes: 其他修复:

Add code to the toolbar list code添加到工具栏列表

toolbar: "code bold italic underline, bullist, numlist superscript subscript"

Patch code 补丁码

Error seems to be from one of the statements filtering out data-mce-bogus elements 错误似乎来自过滤掉data-mce-bogus元素的语句之一

//From Formatter.js source
parents = Tools.grep(parents, function(node) {
    return !node.getAttribute('data-mce-bogus');
});

Since comments do not have a getAttribute function, it errors out. 由于注释没有getAttribute函数,因此会出错。 So adding a check for getAttribute fixes it 因此,添加对getAttribute的检查即可解决该问题

return (node.getAttribute && !node.getAttribute('data-mce-bogus'));

Tinymce 4.1.2 Minified Version Patch Tinymce 4.1.2缩小版补丁

Patch source (requires node.js to build) 修补程序源 (需要构建node.js)

Get tinymce source from github, patch Formatter.js , and build 从github获取tinymce源码, 修补Formatter.js并构建

git clone git://github.com/tinymce/tinymce.git ./tinymce
git checkout -b patched 416e35737aed2af60eff69887bb7bf33cc3b4bc8
wget -O Formatter.js.patch https://www.dropbox.com/s/mt5ar8k8iru8x6o/Formatter.js.patch?dl=1
patch -p1 < Formatter.js.patch
npm i -g jake
npm i
jake

https://github.com/tinymce/tinymce https://github.com/tinymce/tinymce

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

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