首页 > 解决方案 > 自定义格式在“所见即所得的附加选项”中不起作用

问题描述

我正在使用最新的 Keystone.js,以下是我的 Keystone.init

var keystone = require('keystone');

keystone.init({
    'name': 'Dashboard',
    'user model': 'User',
    'auto update': true,
    'auth': true,
    'cookie secret': 'secure string goes here',
     views: 'templates/views',
    'view engine': 'pug',
    'wysiwyg cloudinary images': true,
    'wysiwyg additional plugins': 'example, autosave, charmap, table, '
    + 'advlist, anchor, wordcount, preview, fullscreen, importcss,  '
    + 'paste',
    'wysiwyg additional buttons' : 'undo redo charmap blockquote formatselect styleselect removeformat  |'
    + 'example preview fullscreen bodytext',
    'wysiwyg additional options': { 
            default_link_target: '_blank',
            paste_as_text: true,
            menubar: true, // added to test formats
            'style_formats': [ 
                { title: 'Red text', inline: 'span', styles: { color: '#ff0000' } }
                ],
            formats: {
                    bodytext: {block : 'p', attributes : {title : 'bodyText'}, styles : {color : 'grey'}}
                }
        }, });

keystone.set('routes', require('./routes'));

keystone.import('models');

keystone.set('nav', {
    'projects': ['Projects', 'Keywords'],
    });

keystone.start();

我在 TinyMCE 编辑器中得到的是格式下拉菜单,其中没有任何自定义格式。

有谁知道如何解决它?我需要添加一个自定义格式来为文本添加一个类,例如。图片标题,正文等

在查看 Keystone.js 文件后,我发现它使用的是 TinyMCE 版本 4.4.3,而 Keystone 版本是 4.0 RC。

标签: tinymcekeystonejs

解决方案


所以,我找到了解决方案,这是一个愚蠢的错误, style_formats: 应该出现在引号中:

'wysiwyg additional options': { 
            default_link_target: '_blank',
            paste_as_text: true,
            menubar: true, // added to test formats
            style_formats: [ 
                { title: 'Red text', inline: 'span', styles: { color: '#ff0000' } }
                ],
            formats: {
                    bodytext: {block : 'p', attributes : {title : 'bodyText'}, styles : {color : 'grey'}}
                }
        }, });

我希望如果其他人也面临这个问题,您可以检查这是否可以为您解决。


推荐阅读