繁体   English   中英

CK编辑器。 设置每页最大字数?

[英]CK editor. Set maximum word count per page?

有没有办法为每页的CK编辑器设置最大字数?

甚至更好:每个编辑器?

我找不到与此相关的任何文档。

我在CKEditor文档中找到了解决方案; 我已经使用CKEditor 4.7.3对其进行了测试。 参见网址: https : //docs.ckeditor.com/ckeditor4/docs/#!/ guide/ dev_configuration

1)创建config.js文件的副本(尽管示例显示的方式不同,但可能位于同一位置)

2)添加所需的任何设置,例如:

限制nb char:“ config.wordcount = {maxCharCount:255,showWordCount:true,showCharCount:true};”

要么

限制nb个单词:“ config.wordcount = {maxWordCount:255,showWordCount:true,showCharCount:true};”

3)在需要特定配置的页面中,将以下内容添加到调用CKEditor进行文本区域替换的行中

例如:CKEDITOR.replace('editor1',{customConfig:'/custom/ckeditor_config.js'});

4),您就完成了:-),可能需要刷新页面上的ctrl才能重新加载新设置

请记住,您需要额外的插件来使字数统计工作:htmlwriter,notification,undo和wordcount。 参见参考文件: https : //ckeditor.com/cke4/addon/wordcount

不要以为CKeditor可以立即执行此操作。 尝试在这里阅读。

https://stackoverflow.com/a/27720326/42446

要么..

https://divgo.wordpress.com/2013/01/04/ckeditor-maxlength-plugin/

下载CK编辑器,将其粘贴到Res文件夹中。 下载wordcount插件并将其粘贴到CKEditor的Plugin文件夹中。

然后在config.cs(出现在CKEditor文件夹中)中,粘贴以下内容:

        config.extraPlugins = 'wordcount';
        config.wordcount = {

            // Whether or not you want to show the Word Count
            showWordCount: true,

            // Whether or not you want to show the Char Count
            showCharCount: false,

            // Maximum allowed Word Count
            maxWordCount: -1,

            // Maximum allowed Char Count
            maxCharCount: 10
};

然后在HTML中使用:

/*        If instance is already present then destory it 
 * 
 */
          var currentEditor = CKEDITOR.instances.answerCKEditor;
            if (currentEditor) {
                currentEditor.destroy(true); 
            }   
          CKEDITOR.replace('answerCKEditor',{wordcount: {
                showParagraphs: false,
                showWordCount: true,
                showCharCount: true,
                countSpacesAsChars: false,
                countHTML: false,
                maxWordCount: -1,
                maxCharCount: 40}
            });

      });   

这将替换普通的TextArea:

<div class="form-group">
    <label>Answer</label>
    <textarea class="ckeditor" id="answerCKEditor" rows="6" cols="50" th:text="${faqDetail.answer}"></textarea>
</div>

在CKEditor 4中,您可以编辑config.js以限制字符和单词。 您需要包括Wordcount插件。

    CKEDITOR.editorConfig = function( config ) {

        // Include 'wordcount' plugin
        config.extraPlugins = 'wordcount'; 

           config.wordcount = {

                    // Whether or not you want to show the Paragraphs Count
                    showParagraphs: false,

                    // Whether or not you want to show the Word Count
                    showWordCount: true,

                    // Whether or not you want to show the Char Count
                    showCharCount: true,

                    // Whether or not you want to count Spaces as Chars
                    countSpacesAsChars: false,

                    // Whether or not to include Html chars in the Char Count
                    countHTML: false,

                    // Whether or not to include Line Breaks in the Char Count
                    countLineBreaks: false,

                    // Maximum allowed Word Count, -1 is default for unlimited
                    // NOTE - This is where you configure Max Word Count
                    maxWordCount: -1,

                    // Maximum allowed Char Count, -1 is default for unlimited
                    maxCharCount: 250,

                    // Maximum allowed Paragraphs Count, -1 is default for unlimited
                    maxParagraphs: 1,

                    // How long to show the 'paste' warning, 0 is default for not auto-closing the notification
                    pasteWarningDuration: 0,


                    // Add filter to add or remove element before counting (see CKEDITOR.htmlParser.filter), Default value : null (no filter)
                    filter: new CKEDITOR.htmlParser.filter({
                        elements: {
                            div: function( element ) {
                                if(element.attributes.class == 'mediaembed') {
                                    return false;
                                }
                            }
                        }
                    })
                };

    };

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM