可能的解決方法:
style_formats: [
{title:'Indent', selector:'p', styles:{'text-indent':'30px'}}
],
style_formats_merge: true,
或
style_formats: [
{title:'Indent', selector:'p', classes:'tindent'}
],
style_formats_merge: true,
content_css: 'my_styles.css', //define 'p.tindent' in the css file
最終的答案:增加了一個新的風格格式(styleselect)和一個按鈕(tindent_bttn)
// id_ is not a selector(no '#'), but the simple element id
function tinymce_init(id_) {
var settings = {
...
style_formats: [
{title:'Indent', selector:'p', classes:'tindent'},
],
style_formats_merge: true,
toolbar1:'... styleselect | tindent_bttn',
toolbar2:'...',
content_css:'my_styles.css',
formats: {
tindent_format:{selector:'p', classes:'tindent'},
},
...
};
var editor = new tinymce.Editor(id_, settings, tinymce.EditorManager);
editor.addButton('tindent_bttn', {
text:'Indent',
tooltip:'Indent',
onclick:function() {
editor.execCommand('mceToggleFormat', false, 'tindent_format');
},
onpostrender:function() {
var btn = this;
editor.formatter.formatChanged('tindent_format', function(state) {
btn.active(state);
});
}
});
editor.render();
return editor;
}
文檔:
https://www.tinymce.com/docs/configure/content-formatting/ https://www.tinymce.com/docs/advanced/creating-a-custom-button/ https://www.tinymce.com/docs/api/tinymce/tinymce.editor/