繁体   English   中英

富文本内容打破了TinyMCE

[英]Rich Text Content Breaks TinyMCE

因此,我正在使用TinyMCE处理某些内容,但不幸的是,有时放入其中的内容(数据库中的RTE blob数据)正在破坏脚本。

这是操作中的一个小提琴

我使用一个函数来设置tinymce.init() ,并且工作正常,但是似乎RTE数据中的某些内容完全破坏了文本区域。

这是脚本:

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");

HTML很简单,但是:

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

看到小提琴中打破它的内容。 有没有办法保护我的脚本不受诸如此类的输入?

这也是错误:

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

这似乎是TinyMCE中错误

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

快速解决方法是确保评论前有空格

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

JSFiddle修复演示

在该错误中添加了一条注释,指出它仍然存在于4.1中

其他修复:

code添加到工具栏列表

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

补丁码

错误似乎来自过滤掉data-mce-bogus元素的语句之一

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

由于注释没有getAttribute函数,因此会出错。 因此,添加对getAttribute的检查即可解决该问题

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

Tinymce 4.1.2缩小版补丁

修补程序源 (需要构建node.js)

从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

暂无
暂无

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

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