configuration.mdx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ---
  2. title: Configuration
  3. ---
  4. Quill allows several ways to customize it to suit your needs. This section is dedicated to tweaking existing functionality. See the [Modules](/docs/modules/) section for adding new functionality and the [Themes](/docs/themes/) section for styling.
  5. ## Container
  6. Quill requires a container where the editor will be appended. You can pass in either a CSS selector or a DOM object.
  7. ```javascript
  8. const quill = new Quill('#editor'); // First matching element will be used
  9. ```
  10. ```javascript
  11. const container = document.getElementById('editor');
  12. const quill = new Quill(container);
  13. ```
  14. If the container is not empty, Quill will initialize with the existing contents.
  15. ## Options
  16. To configure Quill, pass in an options object:
  17. <SandpackWithQuillTemplate
  18. files={{
  19. "/index.js": `
  20. const options = {
  21. debug: 'info',
  22. modules: {
  23. toolbar: true,
  24. },
  25. placeholder: 'Compose an epic...',
  26. theme: 'snow'
  27. };
  28. const quill = new Quill('#editor', options);
  29. `}}
  30. />
  31. The following keys are recognized:
  32. ### bounds
  33. Default: `document.body`
  34. DOM Element or a CSS selector for a DOM Element, within which the editor's ui elements (i.e. tooltips, etc.) should be confined. Currently, it only considers left and right boundaries.
  35. ### debug
  36. Default: `warn`
  37. Shortcut for [debug](/docs/api/#debug). Note `debug` is a static method and will affect other instances of Quill editors on the page. Only warning and error messages are enabled by default.
  38. ### formats
  39. Default: `null`
  40. A list of formats that are recognized and can exist within the editor contents.
  41. By default, all formats that are defined in the Quill library are allowed.
  42. To restrict formatting to a smaller list, pass in an array of the format names to support.
  43. You can create brand new formats or more fully customize the content using [Registries](/docs/registries/).
  44. Specifying a `registry` option will ignore this `formats` option.
  45. <Sandpack
  46. defaultShowPreview
  47. activeFile="index.js"
  48. files={{
  49. 'index.html': `
  50. <!-- Include stylesheet -->
  51. <link href="{{site.cdn}}/quill.snow.css" rel="stylesheet" />
  52. <div id="editor">
  53. </div>
  54. <!-- Include the Quill library -->
  55. <script src="{{site.cdn}}/quill.js"></script>
  56. <script src="/index.js"></script>`,
  57. "/index.js": `
  58. const Parchment = Quill.import('parchment');
  59. const quill = new Quill('#editor', {
  60. formats: ['italic'],
  61. });
  62. const Delta = Quill.import('delta');
  63. quill.setContents(
  64. new Delta()
  65. .insert('Only ')
  66. .insert('italic', { italic: true })
  67. .insert(' is allowed. ')
  68. .insert('Bold', { bold: true })
  69. .insert(' is not.')
  70. );
  71. `}}
  72. />
  73. ### placeholder
  74. Default: None
  75. Placeholder text to show when editor is empty.
  76. <SandpackWithQuillTemplate
  77. files={{
  78. "/index.js": `
  79. const options = {
  80. placeholder: 'Hello, World!',
  81. theme: 'snow'
  82. };
  83. const quill = new Quill('#editor', options);
  84. `}}
  85. />
  86. ### readOnly
  87. Default: `false`
  88. Whether to instantiate the editor to read-only mode.
  89. <SandpackWithQuillTemplate
  90. files={{
  91. "/index.js": `
  92. const options = {
  93. readOnly: true,
  94. modules: {
  95. toolbar: null
  96. },
  97. theme: 'snow'
  98. };
  99. const quill = new Quill('#editor', options);
  100. const Delta = Quill.import('delta');
  101. quill.setContents(
  102. new Delta()
  103. .insert('Hello, ')
  104. .insert('World', { bold: true })
  105. .insert('\\n')
  106. );
  107. `}}
  108. />
  109. ### registry
  110. Default: `null`
  111. By default all formats defined by Quill are supported in the editor contents through a shared registry between editor instances. Use `formats` to restrict formatting for simple use cases and `registry` for greater customization. Specifying this `registry` option will ignore the `formatting` option. Learn more about [Registries](/docs/registries/).
  112. ### theme
  113. Name of theme to use. The builtin options are `"bubble"` or `"snow"`. An invalid or falsy value will load a default minimal theme. Note the theme's specific stylesheet still needs to be included manually. See [Themes](/docs/themes/) for more information.