2012-07-05 60 views
1

有谁知道如何允许在TinyMCE中使用自定义的大写标签?看起来,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> 

不起作用,因为< CUSTOM>被剥离。

如果我改变初始化脚本extended_valid_elements: "custom",然后正常工作 - 我可以输入

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

和<习俗被保留。

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

谢谢!

+0

不能你只使用小写标签? – Thariama

+0

不,这是传统数据,所有标签都是自定义的,并且是大写字母。这是否意味着TinyMCE无法实现? – His

+0

您可以将它们转换为编辑器初始化的小写字母。我不知道其他方式(但可能有一个) – Thariama

回答

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); 
    }); 
}, 
相关问题