开发者

Ignore/replace element attributes in TinyMCE

I have been searching without any results, does anyone here know how to ignore and/or replace element attributes in TinyMCE?

For example:

<table cellpadding="0" cellspacing="0" class="tdTable" style="margin: 0 20px 0 0;">

I would like to replace the code above to:

<table cellpadding="0" c开发者_运维问答ellspacing="5">


tinyMCE brings this functionality within its dom.parser:

    tinyMCE.activeEditor.dom.Serializer.addAttributeFilter('class,style', function(nodes, name) {
        for (var i = 0; i < nodes.length; i++) {
            console.log(nodes[i].name);
            tinyMCE.dom.setAttrib(nodes[i], 'class', null);
            tinyMCE.dom.setAttrib(nodes[i], 'style', null);
            // Process the nodes here (e.g. set attribute to null or delete Attribute)
        }
    });

You can also apply the change for the whole array:

    tinyMCE.activeEditor.dom.Serializer.addAttributeFilter('class', function(nodes, name) {
        tinyMCE.dom.setAttrib(nodes, 'class', null);
    });
    tinyMCE.activeEditor.dom.Serializer.addAttributeFilter('style', function(nodes, name) {
        tinyMCE.dom.setAttrib(nodes, 'style', null);
    });

See here for a complete documentation of the functions: http://www.tinymce.com/wiki.php/API3:namespace.tinymce.dom


use the invalid_elements setting when initializing the editor for example, i use:

invalid_elements: '@[onclick|ondblclick|onmousedown|onmouseup|onmouseover|onmousemove|onmouseout|onkeypress|onkeydown|onkeyup],script,input,select,option,button,textarea,form',

to get rid of all the mentioned elements/attributes at the output text

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜