api.mdx 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837
  1. ---
  2. title: API
  3. ---
  4. import api from '../../src/data/api';
  5. <div className="table-of-contents">
  6. {api.map(({ hashes, title }) => (
  7. <nav key={title}>
  8. <h4 anchor="off">{title}</h4>
  9. <ul>
  10. {hashes.map(hash => (
  11. <li key={hash}>
  12. <a href={`#${hash.toLowerCase()}`}>
  13. {hash.replace('-experimental', '')}
  14. </a>
  15. </li>
  16. ))}
  17. </ul>
  18. </nav>
  19. ))}
  20. </div>
  21. ## Content
  22. ### deleteText
  23. Deletes text from the editor, returning a [Delta](/docs/delta/) representing the change. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  24. **Methods**
  25. ```javascript
  26. deleteText(index: Number, length: Number, source: String = 'api'): Delta
  27. ```
  28. **Examples**
  29. ```javascript
  30. quill.deleteText(6, 4);
  31. ```
  32. ### getContents
  33. Retrieves contents of the editor, with formatting data, represented by a [Delta](/docs/delta/) object.
  34. **Methods**
  35. ```javascript
  36. getContents(index: Number = 0, length: Number = remaining): Delta
  37. ```
  38. **Examples**
  39. ```javascript
  40. const delta = quill.getContents();
  41. ```
  42. ### getLength
  43. Retrieves the length of the editor contents. Note even when Quill is empty, there is still a blank line represented by '\n', so `getLength` will return 1.
  44. **Methods**
  45. ```javascript
  46. getLength(): Number
  47. ```
  48. **Examples**
  49. ```javascript
  50. const length = quill.getLength();
  51. ```
  52. ### getText
  53. Retrieves the string contents of the editor. Non-string content are omitted, so the returned string's length may be shorter than the editor's as returned by [`getLength`](#getlength). Note even when Quill is empty, there is still a blank line in the editor, so in these cases `getText` will return '\n'.
  54. The `length` parameter defaults to the length of the remaining document.
  55. **Methods**
  56. ```javascript
  57. getText(index: Number = 0, length: Number = remaining): String
  58. ```
  59. **Examples**
  60. ```javascript
  61. const text = quill.getText(0, 10);
  62. ```
  63. ### insertEmbed
  64. Insert embedded content into the editor, returning a [Delta](/docs/delta/) representing the change. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  65. **Methods**
  66. ```javascript
  67. insertEmbed(index: Number, type: String, value: any, source: String = 'api'): Delta
  68. ```
  69. **Examples**
  70. ```javascript
  71. quill.insertEmbed(10, 'image', 'https://quilljs.com/images/cloud.png');
  72. ```
  73. ### insertText
  74. Inserts text into the editor, optionally with a specified format or multiple [formats](/docs/formats/). Returns a [Delta](/docs/delta/) representing the change. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  75. **Methods**
  76. ```javascript
  77. insertText(index: Number, text: String, source: String = 'api'): Delta
  78. insertText(index: Number, text: String, format: String, value: any,
  79. source: String = 'api'): Delta
  80. insertText(index: Number, text: String, formats: { [String]: any },
  81. source: String = 'api'): Delta
  82. ```
  83. **Examples**
  84. ```javascript
  85. quill.insertText(0, 'Hello', 'bold', true);
  86. quill.insertText(5, 'Quill', {
  87. color: '#ffff00',
  88. italic: true,
  89. });
  90. ```
  91. ### setContents
  92. Overwrites editor with given contents. Contents should end with a [newline](/docs/delta/#line-formatting). Returns a Delta representing the change. This will be the same as the Delta passed in, if given Delta had no invalid operations. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  93. **Methods**
  94. ```javascript
  95. setContents(delta: Delta, source: String = 'api'): Delta
  96. ```
  97. **Examples**
  98. ```javascript
  99. quill.setContents([
  100. { insert: 'Hello ' },
  101. { insert: 'World!', attributes: { bold: true } },
  102. { insert: '\n' },
  103. ]);
  104. ```
  105. ### setText
  106. Sets contents of editor with given text, returning a [Delta](/docs/delta/) representing the change. Note Quill documents must end with a newline so one will be added for you if omitted. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  107. **Methods**
  108. ```javascript
  109. setText(text: String, source: String = 'api'): Delta
  110. ```
  111. **Examples**
  112. ```javascript
  113. quill.setText('Hello\n');
  114. ```
  115. ### updateContents
  116. Applies Delta to editor contents, returning a [Delta](/docs/delta/) representing the change. These Deltas will be the same if the Delta passed in had no invalid operations. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  117. **Methods**
  118. ```javascript
  119. updateContents(delta: Delta, source: String = 'api'): Delta
  120. ```
  121. **Examples**
  122. ```javascript
  123. // Assuming editor currently contains [{ insert: 'Hello World!' }]
  124. quill.updateContents(new Delta()
  125. .retain(6) // Keep 'Hello '
  126. .delete(5) // 'World' is deleted
  127. .insert('Quill')
  128. .retain(1, { bold: true }) // Apply bold to exclamation mark
  129. );
  130. // Editor should now be [
  131. // { insert: 'Hello Quill' },
  132. // { insert: '!', attributes: { bold: true} }
  133. // ]
  134. ```
  135. ## Formatting
  136. ### format
  137. Format text at user's current selection, returning a [Delta](/docs/delta/) representing the change. If the user's selection length is 0, i.e. it is a cursor, the format will be set active, so the next character the user types will have that formatting. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  138. **Methods**
  139. ```javascript
  140. format(name: String, value: any, source: String = 'api'): Delta
  141. ```
  142. **Examples**
  143. ```javascript
  144. quill.format('color', 'red');
  145. quill.format('align', 'right');
  146. ```
  147. ### formatLine
  148. Formats all lines in given range, returning a [Delta](/docs/delta/) representing the change. See [formats](/docs/formats/) for a list of available formats. Has no effect when called with inline formats. To remove formatting, pass `false` for the value argument. The user's selection may not be preserved. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  149. **Methods**
  150. ```javascript
  151. formatLine(index: Number, length: Number, source: String = 'api'): Delta
  152. formatLine(index: Number, length: Number, format: String, value: any,
  153. source: String = 'api'): Delta
  154. formatLine(index: Number, length: Number, formats: { [String]: any },
  155. source: String = 'api'): Delta
  156. ```
  157. **Examples**
  158. ```javascript
  159. quill.setText('Hello\nWorld!\n');
  160. quill.formatLine(1, 2, 'align', 'right'); // right aligns the first line
  161. quill.formatLine(4, 4, 'align', 'center'); // center aligns both lines
  162. ```
  163. ### formatText
  164. Formats text in the editor, returning a [Delta](/docs/delta/) representing the change. For line level formats, such as text alignment, target the newline character or use the [`formatLine`](#formatline) helper. See [formats](/docs/formats/) for a list of available formats. To remove formatting, pass `false` for the value argument. The user's selection may not be preserved. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  165. **Methods**
  166. ```javascript
  167. formatText(index: Number, length: Number, source: String = 'api'): Delta
  168. formatText(index: Number, length: Number, format: String, value: any,
  169. source: String = 'api'): Delta
  170. formatText(index: Number, length: Number, formats: { [String]: any },
  171. source: String = 'api'): Delta
  172. ```
  173. **Examples**
  174. ```javascript
  175. quill.setText('Hello\nWorld!\n');
  176. quill.formatText(0, 5, 'bold', true); // bolds 'hello'
  177. quill.formatText(0, 5, { // unbolds 'hello' and set its color to blue
  178. 'bold': false,
  179. 'color': 'rgb(0, 0, 255)'
  180. });
  181. quill.formatText(5, 1, 'align', 'right'); // right aligns the 'hello' line
  182. ```
  183. ### getFormat
  184. Retrieves common formatting of the text in the given range. For a format to be reported, all text within the range must have a truthy value. If there are different truthy values, an array with all truthy values will be reported. If no range is supplied, the user's current selection range is used. May be used to show which formats have been set on the cursor. If called with no arguments, the user's current selection range will be used.
  185. **Methods**
  186. ```javascript
  187. getFormat(range: Range = current): { [String]: any }
  188. getFormat(index: Number, length: Number = 0): { [String]: any }
  189. ```
  190. **Examples**
  191. ```javascript
  192. quill.setText('Hello World!');
  193. quill.formatText(0, 2, 'bold', true);
  194. quill.formatText(1, 2, 'italic', true);
  195. quill.getFormat(0, 2); // { bold: true }
  196. quill.getFormat(1, 1); // { bold: true, italic: true }
  197. quill.formatText(0, 2, 'color', 'red');
  198. quill.formatText(2, 1, 'color', 'blue');
  199. quill.getFormat(0, 3); // { color: ['red', 'blue'] }
  200. quill.setSelection(3);
  201. quill.getFormat(); // { italic: true, color: 'blue' }
  202. quill.format('strike', true);
  203. quill.getFormat(); // { italic: true, color: 'blue', strike: true }
  204. quill.formatLine(0, 1, 'align', 'right');
  205. quill.getFormat(); // { italic: true, color: 'blue', strike: true,
  206. // align: 'right' }
  207. ```
  208. ### removeFormat
  209. Removes all formatting and embeds within given range, returning a [Delta](/docs/delta/) representing the change. Line formatting will be removed if any part of the line is included in the range. The user's selection may not be preserved. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`. Calls where the `source` is `"user"` when the editor is [disabled](#disable) are ignored.
  210. **Methods**
  211. ```javascript
  212. removeFormat(index: Number, length: Number, source: String = 'api'): Delta
  213. ```
  214. **Examples**
  215. ```javascript
  216. quill.setContents([
  217. { insert: 'Hello', { bold: true } },
  218. { insert: '\n', { align: 'center' } },
  219. { insert: { formula: 'x^2' } },
  220. { insert: '\n', { align: 'center' } },
  221. { insert: 'World', { italic: true }},
  222. { insert: '\n', { align: 'center' } }
  223. ]);
  224. quill.removeFormat(3, 7);
  225. // Editor contents are now
  226. // [
  227. // { insert: 'Hel', { bold: true } },
  228. // { insert: 'lo\n\nWo' },
  229. // { insert: 'rld', { italic: true }},
  230. // { insert: '\n', { align: 'center' } }
  231. // ]
  232. ```
  233. ## Selection
  234. ### getBounds
  235. Retrieves the pixel position (relative to the editor container) and dimensions of a selection at a given location. The user's current selection need not be at that index. Useful for calculating where to place tooltips.
  236. **Methods**
  237. ```javascript
  238. getBounds(index: Number, length: Number = 0):
  239. { left: Number, top: Number, height: Number, width: Number }
  240. ```
  241. **Examples**
  242. ```javascript
  243. quill.setText('Hello\nWorld\n');
  244. quill.getBounds(7); // Returns { height: 15, width: 0, left: 27, top: 31 }
  245. ```
  246. ### getSelection
  247. Retrieves the user's selection range, optionally to focus the editor first. Otherwise `null` may be returned if editor does not have focus.
  248. **Methods**
  249. ```javascript
  250. getSelection(focus = false): { index: Number, length: Number }
  251. ```
  252. **Examples**
  253. ```javascript
  254. const range = quill.getSelection();
  255. if (range) {
  256. if (range.length == 0) {
  257. console.log('User cursor is at index', range.index);
  258. } else {
  259. const text = quill.getText(range.index, range.length);
  260. console.log('User has highlighted: ', text);
  261. }
  262. } else {
  263. console.log('User cursor is not in editor');
  264. }
  265. ```
  266. ### setSelection
  267. Sets user selection to given range, which will also focus the editor. Providing `null` as the selection range will blur the editor. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`.
  268. **Methods**
  269. ```javascript
  270. setSelection(index: Number, length: Number = 0, source: String = 'api')
  271. setSelection(range: { index: Number, length: Number },
  272. source: String = 'api')
  273. ```
  274. **Examples**
  275. ```javascript
  276. quill.setSelection(0, 5);
  277. ```
  278. ## Editor
  279. ### blur
  280. Removes focus from the editor.
  281. **Methods**
  282. ```javascript
  283. blur();
  284. ```
  285. **Examples**
  286. ```javascript
  287. quill.blur();
  288. ```
  289. ### disable
  290. Shorthand for [`enable(false)`](#enable).
  291. ### enable
  292. Set ability for user to edit, via input devices like the mouse or keyboard. Does not affect capabilities of API calls, when the `source` is `"api"` or `"silent".
  293. **Methods**
  294. ```javascript
  295. enable(((enabled: boolean) = true));
  296. ```
  297. **Examples**
  298. ```javascript
  299. quill.enable();
  300. quill.enable(false); // Disables user input
  301. ```
  302. ### focus
  303. Focuses the editor and restores its last range.
  304. **Methods**
  305. ```javascript
  306. focus();
  307. ```
  308. **Examples**
  309. ```javascript
  310. quill.focus();
  311. ```
  312. ### hasFocus
  313. Checks if editor has focus. Note focus on toolbar, tooltips, does not count as the editor.
  314. **Methods**
  315. ```javascript
  316. hasFocus(): Boolean
  317. ```
  318. **Examples**
  319. ```javascript
  320. quill.hasFocus();
  321. ```
  322. ### update
  323. Synchronously check editor for user updates and fires events, if changes have occurred. Useful for collaborative use cases during conflict resolution requiring the latest up to date state. [Source](/docs/api/#events) may be `"user"`, `"api"`, or `"silent"`.
  324. **Methods**
  325. ```javascript
  326. update(((source: String) = 'user'));
  327. ```
  328. **Examples**
  329. ```javascript
  330. quill.update();
  331. ```
  332. ## Events
  333. ### text-change
  334. Emitted when the contents of Quill have changed. Details of the change, representation of the editor contents before the change, along with the source of the change are provided. The source will be `"user"` if it originates from the users. For example:
  335. - User types into the editor
  336. - User formats text using the toolbar
  337. - User uses a hotkey to undo
  338. - User uses OS spelling correction
  339. Changes may occur through an API but as long as they originate from the user, the provided source should still be `"user"`. For example, when a user clicks on the toolbar, technically the toolbar module calls a Quill API to effect the change. But source is still `"user"` since the origin of the change was the user's click.
  340. APIs causing text to change may also be called with a `"silent"` source, in which case `text-change` will not be emitted. This is not recommended as it will likely break the undo stack and other functions that rely on a full record of text changes.
  341. Changes to text may cause changes to the selection (ex. typing advances the cursor), however during the `text-change` handler, the selection is not yet updated, and native browser behavior may place it in an inconsistent state. Use [`selection-change`](#selection-change) or [`editor-change`](#editor-change) for reliable selection updates.
  342. **Callback Signature**
  343. ```javascript
  344. handler(delta: Delta, oldContents: Delta, source: String)
  345. ```
  346. **Examples**
  347. ```javascript
  348. quill.on('text-change', function (delta, oldDelta, source) {
  349. if (source == 'api') {
  350. console.log('An API call triggered this change.');
  351. } else if (source == 'user') {
  352. console.log('A user action triggered this change.');
  353. }
  354. });
  355. ```
  356. ### selection-change
  357. Emitted when a user or API causes the selection to change, with a range representing the selection boundaries. A null range indicates selection loss (usually caused by loss of focus from the editor). You can also use this event as a focus change event by just checking if the emitted range is null or not.
  358. APIs causing the selection to change may also be called with a `"silent"` source, in which case `selection-change` will not be emitted. This is useful if `selection-change` is a side effect. For example, typing causes the selection to change but would be very noisy to also emit a `selection-change` event on every character.
  359. **Callback Signature**
  360. ```javascript
  361. handler(range: { index: Number, length: Number },
  362. oldRange: { index: Number, length: Number },
  363. source: String)
  364. ```
  365. **Examples**
  366. ```javascript
  367. quill.on('selection-change', function (range, oldRange, source) {
  368. if (range) {
  369. if (range.length == 0) {
  370. console.log('User cursor is on', range.index);
  371. } else {
  372. const text = quill.getText(range.index, range.length);
  373. console.log('User has highlighted', text);
  374. }
  375. } else {
  376. console.log('Cursor not in the editor');
  377. }
  378. });
  379. ```
  380. ### editor-change
  381. Emitted when either `text-change` or `selection-change` would be emitted, even when the source is `"silent"`. The first parameter is the event name, either `text-change` or `selection-change`, followed by the arguments normally passed to those respective handlers.
  382. **Callback Signature**
  383. ```javascript
  384. handler(name: String, ...args)
  385. ```
  386. **Examples**
  387. ```javascript
  388. quill.on('editor-change', function (eventName, ...args) {
  389. if (eventName === 'text-change') {
  390. // args[0] will be delta
  391. } else if (eventName === 'selection-change') {
  392. // args[0] will be old range
  393. }
  394. });
  395. ```
  396. ### on
  397. Adds event handler. See [text-change](#text-change) or [selection-change](#selection-change) for more details on the events themselves.
  398. **Methods**
  399. ```javascript
  400. on(name: String, handler: Function): Quill
  401. ```
  402. **Examples**
  403. ```javascript
  404. quill.on('text-change', function () {
  405. console.log('Text change!');
  406. });
  407. ```
  408. ### once
  409. Adds handler for one emission of an event. See [text-change](#text-change) or [selection-change](#selection-change) for more details on the events themselves.
  410. **Methods**
  411. ```javascript
  412. once(name: String, handler: Function): Quill
  413. ```
  414. **Examples**
  415. ```javascript
  416. quill.once('text-change', function () {
  417. console.log('First text change!');
  418. });
  419. ```
  420. ### off
  421. Removes event handler.
  422. **Methods**
  423. ```javascript
  424. off(name: String, handler: Function): Quill
  425. ```
  426. **Examples**
  427. ```javascript
  428. function handler() {
  429. console.log('Hello!');
  430. }
  431. quill.on('text-change', handler);
  432. quill.off('text-change', handler);
  433. ```
  434. ## Model
  435. ### find #experimental
  436. Static method returning the Quill or [Blot](https://github.com/quilljs/parchment) instance for the given DOM node. In the latter case, passing in true for the `bubble` parameter will search up the given DOM's ancestors until it finds a corresponding [Blot](https://github.com/quilljs/parchment).
  437. **Methods**
  438. ```javascript
  439. Quill.find(domNode: Node, bubble: boolean = false): Blot | Quill
  440. ```
  441. **Examples**
  442. ```javascript
  443. const container = document.querySelector('#container');
  444. const quill = new Quill(container);
  445. console.log(Quill.find(container) === quill); // Should be true
  446. quill.insertText(0, 'Hello', 'link', 'https://world.com');
  447. const linkNode = document.querySelector('#container a');
  448. const linkBlot = Quill.find(linkNode);
  449. ```
  450. ### getIndex #experimental
  451. Returns the distance between the beginning of document to the occurrence of the given [Blot](https://github.com/quilljs/parchment).
  452. **Methods**
  453. ```javascript
  454. getIndex(blot: Blot): Number
  455. ```
  456. **Examples**
  457. ```javascript
  458. let [line, offset] = quill.getLine(10);
  459. let index = quill.getIndex(line); // index + offset should == 10
  460. ```
  461. ### getLeaf #experimental
  462. Returns the leaf [Blot](https://github.com/quilljs/parchment) at the specified index within the document.
  463. **Methods**
  464. ```javascript
  465. getLeaf(index: Number): Blot
  466. ```
  467. **Examples**
  468. ```javascript
  469. quill.setText('Hello Good World!');
  470. quill.formatText(6, 4, 'bold', true);
  471. let [leaf, offset] = quill.getLeaf(7);
  472. // leaf should be a Text Blot with value "Good"
  473. // offset should be 1, since the returned leaf started at index 6
  474. ```
  475. ### getLine #experimental
  476. Returns the line [Blot](https://github.com/quilljs/parchment) at the specified index within the document.
  477. **Methods**
  478. ```javascript
  479. getLine(index: Number): [Blot, Number]
  480. ```
  481. **Examples**
  482. ```javascript
  483. quill.setText('Hello\nWorld!');
  484. let [line, offset] = quill.getLine(7);
  485. // line should be a Block Blot representing the 2nd "World!" line
  486. // offset should be 1, since the returned line started at index 6
  487. ```
  488. ### getLines #experimental
  489. Returns the lines contained within the specified location.
  490. **Methods**
  491. ```javascript
  492. getLines(index: Number = 0, length: Number = remaining): Blot[]
  493. getLines(range: Range): Blot[]
  494. ```
  495. **Examples**
  496. ```javascript
  497. quill.setText('Hello\nGood\nWorld!');
  498. quill.formatLine(1, 1, 'list', 'bullet');
  499. let lines = quill.getLines(2, 5);
  500. // array with a ListItem and Block Blot,
  501. // representing the first two lines
  502. ```
  503. ## Extension
  504. ### debug
  505. Static method enabling logging messages at a given level: `'error'`, `'warn'`, `'log'`, or `'info'`. Passing `true` is equivalent to passing `'log'`. Passing `false` disables all messages.
  506. **Methods**
  507. ```javascript
  508. Quill.debug(level: String | Boolean)
  509. ```
  510. **Examples**
  511. ```javascript
  512. Quill.debug('info');
  513. ```
  514. ### import
  515. Static method returning Quill library, format, module, or theme. In general the path should map exactly to Quill source code directory structure. Unless stated otherwise, modification of returned entities may break required Quill functionality and is strongly discouraged.
  516. **Methods**
  517. ```javascript
  518. Quill.import(path): any
  519. ```
  520. **Examples**
  521. ```javascript
  522. const Parchment = Quill.import('parchment');
  523. const Delta = Quill.import('delta');
  524. const Toolbar = Quill.import('modules/toolbar');
  525. const Link = Quill.import('formats/link');
  526. // Similar to ES6 syntax `import Link from 'quill/formats/link';`
  527. ```
  528. ### register
  529. Registers a module, theme, or format(s), making them available to be added to an editor. Can later be retrieved with [`Quill.import`](/docs/api/#import). Use the path prefix of `'formats/'`, `'modules/'`, or `'themes/'` for registering formats, modules or themes, respectively. For formats specifically there is a shorthand to just pass in the format directly and the path will be autogenerated. Will overwrite existing definitions with the same path.
  530. **Methods**
  531. ```javascript
  532. Quill.register(format: Attributor | BlotDefinintion, supressWarning: Boolean = false)
  533. Quill.register(path: String, def: any, supressWarning: Boolean = false)
  534. Quill.register(defs: { [String]: any }, supressWarning: Boolean = false)
  535. ```
  536. **Examples**
  537. ```javascript
  538. const Module = Quill.import('core/module');
  539. class CustomModule extends Module {}
  540. Quill.register('modules/custom-module', CustomModule);
  541. ```
  542. ```javascript
  543. Quill.register({
  544. 'formats/custom-format': CustomFormat,
  545. 'modules/custom-module-a': CustomModuleA,
  546. 'modules/custom-module-b': CustomModuleB,
  547. });
  548. Quill.register(CustomFormat);
  549. // You cannot do Quill.register(CustomModuleA); as CustomModuleA is not a format
  550. ```
  551. ### addContainer
  552. Adds and returns a container element inside the Quill container, sibling to the editor itself. By convention, Quill modules should have a class name prefixed with `ql-`. Optionally include a refNode where container should be inserted before.
  553. **Methods**
  554. ```javascript
  555. addContainer(className: String, refNode?: Node): Element
  556. addContainer(domNode: Node, refNode?: Node): Element
  557. ```
  558. **Examples**
  559. ```javascript
  560. const container = quill.addContainer('ql-custom');
  561. ```
  562. ### getModule
  563. Retrieves a module that has been added to the editor.
  564. **Methods**
  565. ```javascript
  566. getModule(name: String): any
  567. ```
  568. **Examples**
  569. ```javascript
  570. const toolbar = quill.getModule('toolbar');
  571. ```