2012-07-05 88 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); 
    }); 
},