如何在TinyMCE中允许自定义大写标签

时间:2012-07-05 07:25:02

标签: tinymce customization

有谁知道如何在TinyMCE中使用自定义大写标签?似乎TinyMCE不喜欢大写标签,即使它们已被声明为有效。这是我的TinyMCE配置:

tinyMCE.init({
    mode: "specific_textareas",
    theme: "advanced",
    language: "en",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_buttons1: "bold,italic,|,sub,sup,|,charmap,|,table,|,code",
    theme_advanced_path: false,
    theme_advanced_resizing: true,
    plugins: "fullscreen,paste,table",
    paste_auto_cleanup_on_paste : true,
    relative_urls: false,
    width: "300",
    height: "300",
    theme_advanced_resizing_min_height : "10",
    force_br_newlines : true,
    force_p_newlines : false,
    forced_root_block : '',
    entity_encoding: "raw",
    valid_elements : "B/strong,I/em,SUP/sup,SUB/sub",
    extended_valid_elements: "CUSTOM"
})

输入类似

的内容
<CUSTOM>this is a custom tag</CUSTOM>

不起作用,因为&lt; CUSTOM&gt;被剥夺了。

如果我将init脚本更改为extended_valid_elements: "custom",那么它可以正常工作 - 我可以输入

<custom>this is a custom tag</custom>

并且&lt;自定义被保留。

没有人知道任何解决方法吗?

谢谢!

1 个答案:

答案 0 :(得分:1)

以下是如何操作的说明(反向模拟):http://www.codingforums.com/archive/index.php/t-148450.html

您应该使用tinymce onInit事件并将标签更改回大写字母使用onSubmit或onSave(或者您可以在任何其他合适的代码位置上提交内容之前更改内容)。 要添加此处理程序,请使用tinymce setup configuration parameter

setup : function(ed) {

    ed.onInit.add(function(ed, evt) {
        $(ed.getBody()).find('p').addClass('headline');

        // get content from editor source html element
        var content = $(ed.id).html();

        // tagname to lowercase
        content = content.replace(/< *\/?(\w+)/g,function(w){return w.toLowerCase()});

        ed.setContent(content);
    });

    ed.onSubmit.add(function(ed, evt) {
        $(ed.getBody()).find('p').addClass('headline');

        // get content from edito
        var content = ed.getContent();

        // tagname to toUpperCase
        content = content.replace(/< *\/?(\w+)/g,function(w){return w.toUpperCase()});

        // write content to html source element (usually a textarea)
        $(ed.id).html(content );
    });
},
相关问题