w8tcha / ckeditor-wordcount-plugin
CKEditor 编辑器的词数插件
v1.17.12
2023-07-11 04:38 UTC
README
为 CKEditor v4 提供的词数插件,用于统计字数和字符数,并在编辑器的页脚显示字数和/或字符数。
演示
http://w8tcha.github.io/CKEditor-WordCount-Plugin/
免责声明:这是一个分支版本,我已找不到原始作者。如果有人知道原始作者,请与我联系,我可以将作者列入版权声明。
许可证
在 MIT 许可证条款下授权。
安装
如果使用 https://ckeditor.npmjs.net.cn/ 的 CKBuilder 构建新编辑器,则无需遵循以下步骤。如果要将词数和字符数插件添加到已建立的 CKEditor,请按照以下编号步骤操作。
- 从 https://ckeditor.npmjs.net.cn/addon/wordcount 或 https://github.com/w8tcha/CKEditor-WordCount-Plugin 下载词数和字符数插件。这将下载一个名为 wordcount_version.zip 或 CKEditor-WordCount-Plugin-master.zip 的文件夹到您的下载文件夹。
- 从 https://ckeditor.npmjs.net.cn/addon/notification 下载通知插件。这将下载一个名为 notification_version.zip 的文件夹到您的下载文件夹。
- 解压词数和字符数插件以及通知插件的 .zip 文件夹。解压后,您应该有一个名为 wordcount 的文件夹和一个名为 notification 的文件夹。
- 将 wordcount 文件夹移动到 /web/server/root/ckeditor/plugins/。将 notification 文件夹移动到 /web/server/root/ckeditor/plugins/。
- 将以下行文本添加到位于 /web/server/root/ckeditor/ 的 config.js 文件中。
config.extraPlugins = 'wordcount';
以下是添加 config.extraPlugins = 'wordcount,notification'; 后 config.js 文件可能的样子:
CKEDITOR.editorConfig = function( config ) { config.extraPlugins = 'wordcount,notification'; config.toolbar [ et cetera . . . ]; };
现在,在您的 CKEditor 右下角应该有文本,显示段落数和词数。
要修改 CKEditor 右下角词数和字符数文本的行为,请将以下文本添加到位于 /web/server/root/ckeditor/config.js 的 config.js 文件中。
config.wordcount = { // Whether or not you Show Remaining Count (if Maximum Word/Char/Paragraphs Count is set) showRemaining: false, // 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 Bytes as Characters (needed for Multibyte languages such as Korean and Chinese) countBytesAsChars: 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, // Whether or not to prevent entering new Content when limit is reached. hardLimit: true, // Whether or not to to Warn only When limit is reached. Otherwise content above the limit will be deleted on paste or entering warnOnLimitOnly: 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,因为这将把词数和字符数插件的 JavaScript 放入位于 /web/server/root/ckeditor/ckeditor.js 的 ckeditor.js 文件中。ckeditor.js 文件中的词数和字符数插件的 JavaScript 与手动添加词数和字符数插件时使用的 JavaScript 不同。手动添加词数和字符数插件时,JavaScript 将位于
如果您想查询当前的词数,可以通过以下方式进行:
// get the word count CKEDITOR.instances.editor1.wordCount.wordCount // get the char count CKEDITOR.instances.editor1.wordCount.charCount