如何扩展tinyMCE表插件

时间:2017-07-20 10:06:25

标签: javascript tinymce

是否有一种方法可以扩展tinyMCE表插件,以便模板表在其第一列上具有默认的200px宽度?我正在使用inlite主题,我希望默认表格模板如下所示:

<table>
   <tr>
     <td width='200px'>First columns will have 200px width by default</td>
     <td></td>
   </tr>
</table>

1 个答案:

答案 0 :(得分:0)

对于可能遇到此问题的任何人,可以使用BeforeSetContent事件来获取插入的表。 [https://www.tinymce.com/docs/advanced/events/#beforesetcontent][1]

tinymce.init({
        selector: '.tinymce' ,
        theme: 'inlite',
        plugins: 'table',
        insert_toolbar: 'quicktable',
        table_appearance_options: true,
        selection_toolbar: 'bold italic underline',
        nonbreaking_force_tab: true,
        inline: true,
        init_instance_callback: function (editor) {
            editor.on('BeforeSetContent', function (e) {
                if(e.content.indexOf('<td>')){
                    e.content = e.content.replace(/<td>/, "<td width='200'>");
                }
            });
        }
    });