MarkdownListInterceptor.js 1001 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { BasicInterceptor } from 'growi-pluginkit';
  2. import mlu from './MarkdownListUtil';
  3. export default class MarkdownListInterceptor extends BasicInterceptor {
  4. constructor() {
  5. super();
  6. }
  7. /**
  8. * @inheritdoc
  9. */
  10. isInterceptWhen(contextName) {
  11. return (
  12. contextName === 'preHandleEnter'
  13. );
  14. }
  15. /**
  16. * return boolean value whether processable parallel
  17. */
  18. isProcessableParallel() {
  19. return false;
  20. }
  21. /**
  22. * @inheritdoc
  23. */
  24. process(contextName, ...args) {
  25. const context = Object.assign(args[0]); // clone
  26. const editor = context.editor; // AbstractEditor instance
  27. // get strings from current position to EOL(end of line) before break the line
  28. const strToEol = editor.getStrToEol();
  29. if (mlu.indentAndMarkRE.test(strToEol)) {
  30. editor.insertLinebreak();
  31. // report to manager that handling was done
  32. context.handlers.push(this.className);
  33. }
  34. // resolve
  35. return Promise.resolve(context);
  36. }
  37. }