modules.mdx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. ---
  2. title: Modules
  3. ---
  4. 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.
  5. To enable a module, simply include it in Quill's configuration.
  6. ```javascript
  7. const quill = new Quill('#editor', {
  8. modules: {
  9. history: { // Enable with custom configurations
  10. delay: 2500,
  11. userOnly: true
  12. },
  13. syntax: true // Enable with default configuration
  14. }
  15. });
  16. ```
  17. The [Clipboard](/docs/modules/clipboard/), [Keyboard](/docs/modules/keyboard/), and [History](/docs/modules/history/) modules are required by Quill and do not need to be included explictly, but may be configured like any other module.
  18. ## Extending
  19. Modules may also be extended and re-registered, replacing the original module. Even required modules may be re-registered and replaced.
  20. ```javascript
  21. const Clipboard = Quill.import('modules/clipboard');
  22. const Delta = Quill.import('delta');
  23. class PlainClipboard extends Clipboard {
  24. convert(html = null) {
  25. if (typeof html === 'string') {
  26. this.container.innerHTML = html;
  27. }
  28. let text = this.container.innerText;
  29. this.container.innerHTML = '';
  30. return new Delta().insert(text);
  31. }
  32. }
  33. Quill.register('modules/clipboard', PlainClipboard, true);
  34. // Will be created with instance of PlainClipboard
  35. const quill = new Quill('#editor');
  36. ```
  37. <Hint>
  38. 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](/docs/modules/clipboard/#addmatcher) API is suitable for most paste customization scenarios.
  39. </Hint>