6258615a30b00bdccd6585e8d8a5a41f2d59661c707f3855d46275cd709d133b2133f077ced8f2f9b95930684a951a8519b6d3f2eefbd9939661af8f7d0a58 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import Block from '../blots/block.js';
  2. import Break from '../blots/break.js';
  3. import Cursor from '../blots/cursor.js';
  4. import Inline from '../blots/inline.js';
  5. import TextBlot, { escapeText } from '../blots/text.js';
  6. import Container from '../blots/container.js';
  7. import Quill from '../core/quill.js';
  8. class CodeBlockContainer extends Container {
  9. static create(value) {
  10. const domNode = super.create(value);
  11. domNode.setAttribute('spellcheck', 'false');
  12. return domNode;
  13. }
  14. code(index, length) {
  15. return this.children
  16. // @ts-expect-error
  17. .map(child => child.length() <= 1 ? '' : child.domNode.innerText).join('\n').slice(index, index + length);
  18. }
  19. html(index, length) {
  20. // `\n`s are needed in order to support empty lines at the beginning and the end.
  21. // https://html.spec.whatwg.org/multipage/syntax.html#element-restrictions
  22. return `<pre>\n${escapeText(this.code(index, length))}\n</pre>`;
  23. }
  24. }
  25. class CodeBlock extends Block {
  26. static TAB = ' ';
  27. static register() {
  28. Quill.register(CodeBlockContainer);
  29. }
  30. }
  31. class Code extends Inline {}
  32. Code.blotName = 'code';
  33. Code.tagName = 'CODE';
  34. CodeBlock.blotName = 'code-block';
  35. CodeBlock.className = 'ql-code-block';
  36. CodeBlock.tagName = 'DIV';
  37. CodeBlockContainer.blotName = 'code-block-container';
  38. CodeBlockContainer.className = 'ql-code-block-container';
  39. CodeBlockContainer.tagName = 'DIV';
  40. CodeBlockContainer.allowedChildren = [CodeBlock];
  41. CodeBlock.allowedChildren = [TextBlot, Break, Cursor];
  42. CodeBlock.requiredContainer = CodeBlockContainer;
  43. export { Code, CodeBlockContainer, CodeBlock as default };
  44. //# sourceMappingURL=code.js.map