通过API将颜色样式设置为tinyMCE文本选择

Zhi*_*vko 3 jquery tinymce

我正在尝试使用tinyMCE api(jQuery版本)将特定颜色应用于编辑器中的选定文本

这就是我到目前为止所做的事情:

var node = tinyMCE.activeEditor.selection.getNode();
tinyMCE.DOM.setStyle(node, 'color', '#FFF');
Run Code Online (Sandbox Code Playgroud)

问题是这将改变整个节点的颜色而不仅仅是标记的文本.有没有办法通过tinyMCE API将颜色仅应用于标记的文本?

谢谢

Zhi*_*vko 5

我找到了答案.万一其他人被困在这里,我会发布解决方案.

// Registering the special format with a variable
tinymce.activeEditor.formatter.register('custom_format', {inline : 'span', styles : {color : '%value'}});

// Applying the specified format with the variable specified
tinymce.activeEditor.formatter.apply('custom_format', {value : 'red'});
Run Code Online (Sandbox Code Playgroud)