drupal-ckeditor-libraries-group / wordcount
CKEditor 4 wordcount 插件
README
为 CKEditor v4(或更高版本)提供的 WordCount 插件,该插件可以计算文章中的字数/字符数,并在编辑器页脚中显示字数和/或字符数。
演示
http://w8tcha.github.com/CKEditor-WordCount-Plugin/
免责声明:这是一个分支版本,我无法再找到原始作者。如果有人知道原始作者,请与我联系,我可以将作者包括在版权声明中。
许可协议
根据 MIT 许可协议许可。
安装
如果使用来自 https://ckeditor.npmjs.net.cn/ 的 CKBuilder 构建新编辑器,则无需遵循以下步骤。如果要将 Word Count & Char Count 插件添加到已建立的 CKEditor 中,请按照以下编号步骤操作。
- 从 https://ckeditor.npmjs.net.cn/addon/wordcount 或 https://github.com/w8tcha/CKEditor-WordCount-Plugin 下载 Word Count & Char Count 插件。这将下载一个名为 wordcount_version.zip 或 CKEditor-WordCount-Plugin-master.zip 的文件夹到您的下载文件夹。
- 从 https://ckeditor.npmjs.net.cn/addon/notification 下载 Notification 插件。这将下载一个名为 notification_version.zip 的文件夹到您的下载文件夹。
- 解压缩 Word Count & Char Count 和 Notification 插件的相关 .zip 文件。解压缩后,您应该有一个名为 wordcount 的文件夹和一个名为 notification 的文件夹。
- 将 wordcount 文件夹移动到 /web/server/root/ckeditor/plugins/。将 notification 文件夹移动到 /web/server/root/ckeditor/plugins/。
- 将以下行文本添加到位于 /web/server/root/ckeditor 的 config.js 文件中。
config.extraPlugins = 'wordcount,notification';
以下是添加 config.extraPlugins = 'wordcount,notification'; 后您的 config.js 文件可能的样子。
CKEDITOR.editorConfig = function( config ) { config.extraPlugins = 'wordcount,notification'; config.toolbar [ et cetera . . . ]; };
现在,您的 CKEditor 的右下角应该有文本,显示段落数和单词数。
要修改 CKEditor 右下角 Word Count & Char Count 文本的显示行为,将以下文本添加到位于 /web/server/root/ckeditor/config.js 的 config.js 文件中。
config.wordcount = { // Whether or not you want to show the Paragraphs Count showParagraphs: true, // Whether or not you want to show the Word Count showWordCount: true, // Whether or not you want to show the Char Count showCharCount: false, // 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 maxWordCount: -1, // Maximum allowed Char Count, -1 is default for unlimited maxCharCount: -1, // 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; } } } }) };
注意:如果您计划更改一些 JavaScript,可能不会想使用 CKBuilder,因为这会将 Word Count & Char Count 插件的 JavaScript 放置在位于 /web/server/root/ckeditor/ckeditor.js 的 ckeditor.js 文件中。ckeditor.js 中的 Word Count & Char Count 插件的 JavaScript 与手动添加 Word Count & Char Count 插件时使用的 JavaScript 不同。当手动添加 Word Count & Char Count 插件时,JavaScript 将位于位于
如果您想查询当前的词数,可以通过以下方式实现
// get the word count CKEDITOR.instances.editor1.wordCount.wordCount // get the char count CKEDITOR.instances.editor1.wordCount.charCount