tinymce 4个自定义类供用户使用

时间:2014-09-03 06:00:36

标签: tinymce tinymce-4

如何向tinymce 4添加自定义类?我想要一个select用户可以选择要在其文本上使用的类。我不想使用像forecolor这样的标准插件,因为我想提供我的用户可以使用的某些类。

简短的例子:

tinymce编辑"选择课程" (工具栏中的按钮)

  • 红色
  • 绿色

my_custom_css.css

.red { color: red; }
.blue { color: blue; }
.green { color: green; }

1 个答案:

答案 0 :(得分:2)

您可以使用style_formats配置选项。 TinyMCE文档提供了您需要的所有信息:http://www.tinymce.com/wiki.php/Configuration:style_formats

该选项中指定的样式将显示在下拉菜单中,可以作为内联样式和类应用。如果您选择将类应用于所选元素,您可能希望使用content_css选项为编辑器的内容添加自定义样式表。

在您的示例中,配置的相应部分如下所示:

tinymce.init({
    ...
    style_formats: [
        {title: 'Red', inline: 'span', classes: 'red'},
        {title: 'Green', inline: 'span', classes: 'green'},
        {title: 'Blue', inline: 'span', classes: 'blue'}
    ],
    content_css: 'my_custom_css.css'
});
相关问题