模块
模块允许自定义 Quill 的行为和功能。有多个官方支持的模块可供选择,其中一些模块还提供了额外的配置选项和 API。有关更多详细信息,请参阅各自的文档页面。
¥Modules allow Quill's behavior and functionality to be customized. Several officially supported modules are available to pick and choose from, some with additional configuration options and APIs. Refer to their respective documentation pages for more details.
要启用模块,只需将其添加到 Quill 的配置中即可。
¥To enable a module, simply include it in Quill's configuration.
const quill = new Quill('#editor', { modules: { history: { // Enable with custom configurations delay: 2500, userOnly: true }, syntax: true // Enable with default configuration }});
Quill 需要 剪贴板、键盘 和 历史记录 模块,无需显式包含,但可以像其他模块一样进行配置。
¥The Clipboard, Keyboard, and History modules are required by Quill and do not need to be included explictly, but may be configured like any other module.
扩展
¥Extending
模块也可以扩展和重新注册,替换原始模块。即使所需的模块也可能被重新注册和替换。
¥Modules may also be extended and re-registered, replacing the original module. Even required modules may be re-registered and replaced.
const Clipboard = Quill.import('modules/clipboard');const Delta = Quill.import('delta');
class PlainClipboard extends Clipboard { convert(html = null) { if (typeof html === 'string') { this.container.innerHTML = html; } let text = this.container.innerText; this.container.innerHTML = ''; return new Delta().insert(text); }}
Quill.register('modules/clipboard', PlainClipboard, true);
// Will be created with instance of PlainClipboardconst quill = new Quill('#editor');
选择此特定示例是为了展示可能性。通常,使用现有模块公开的 API 或配置会更简单。在本例中,现有的剪贴板 addMatcher API 适用于大多数粘贴自定义场景。
¥This particular example was selected to show what is possible. It is often easier to just use an API or configuration the existing module exposes. In this example, the existing Clipboard's addMatcher API is suitable for most paste customization scenarios.