[英]CK editor. Set maximum word count per page?
Is there a way to set a maximum word count for a CK editor per page? 有没有办法为每页的CK编辑器设置最大字数?
Or even better: per editor? 甚至更好:每个编辑器?
I can't find any documentation for this. 我找不到与此相关的任何文档。
I found the solution inside the CKEditor doc; 我在CKEditor文档中找到了解决方案; I've tested it with CKEditor 4.7.3. 我已经使用CKEditor 4.7.3对其进行了测试。 See url: https://docs.ckeditor.com/ckeditor4/docs/#!/guide/dev_configuration 参见网址: https : //docs.ckeditor.com/ckeditor4/docs/#!/ guide/ dev_configuration
1) create a copy of your config.js file (possibly in the same location although the example shows differently) 1)创建config.js文件的副本(尽管示例显示的方式不同,但可能位于同一位置)
2) Add whatever settings you need eg: 2)添加所需的任何设置,例如:
Limit nb char: "config.wordcount = { maxCharCount: 255, showWordCount: true, showCharCount: true};" 限制nb char:“ config.wordcount = {maxCharCount:255,showWordCount:true,showCharCount:true};”
Or 要么
Limit nb words: "config.wordcount = { maxWordCount: 255, showWordCount: true, showCharCount: true};" 限制nb个单词:“ config.wordcount = {maxWordCount:255,showWordCount:true,showCharCount:true};”
3) In the page that requires a specific config, add the following to the lines that call CKEditor for textarea replacement 3)在需要特定配置的页面中,将以下内容添加到调用CKEditor进行文本区域替换的行中
ex: CKEDITOR.replace( 'editor1', {customConfig: '/custom/ckeditor_config.js'}); 例如:CKEDITOR.replace('editor1',{customConfig:'/custom/ckeditor_config.js'});
4) and you're done :-) might require a ctrl refresh on your page to reload the new settings 4),您就完成了:-),可能需要刷新页面上的ctrl才能重新加载新设置
Remember that you need extra plugins to make the word count work: htmlwriter, notification, undo, and wordcount. 请记住,您需要额外的插件来使字数统计工作:htmlwriter,notification,undo和wordcount。 See ref doc: https://ckeditor.com/cke4/addon/wordcount 参见参考文件: https : //ckeditor.com/cke4/addon/wordcount
Don't think CKeditor performs this out of the box. 不要以为CKeditor可以立即执行此操作。 Try reading here. 尝试在这里阅读。
https://stackoverflow.com/a/27720326/42446 https://stackoverflow.com/a/27720326/42446
or.. 要么..
https://divgo.wordpress.com/2013/01/04/ckeditor-maxlength-plugin/ https://divgo.wordpress.com/2013/01/04/ckeditor-maxlength-plugin/
Download the CK editor,paste it in Res folder. 下载CK编辑器,将其粘贴到Res文件夹中。 Download wordcount plugin and paste it in CKEditor's Plugin folder. 下载wordcount插件并将其粘贴到CKEditor的Plugin文件夹中。
Then in config.cs (present inside CKEditor folder), Paste this : 然后在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
};
Then in HTML use this : 然后在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}
});
});
This will replace the normal TextArea: 这将替换普通的TextArea:
<div class="form-group">
<label>Answer</label>
<textarea class="ckeditor" id="answerCKEditor" rows="6" cols="50" th:text="${faqDetail.answer}"></textarea>
</div>
In CKEditor 4 you can edit your config.js
to have limits on chars and words. 在CKEditor 4中,您可以编辑config.js
以限制字符和单词。 You need to include the Wordcount plugin. 您需要包括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.