PreventMarkdownListInterceptor.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import { BasicInterceptor } from 'growi-pluginkit';
  2. import mlu from './MarkdownListUtil';
  3. export default class PreventMarkdownListInterceptor 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. // newline simply
  31. editor.insertLinebreak();
  32. // report to manager that handling was done
  33. context.handlers.push(this.className);
  34. }
  35. // resolve
  36. return Promise.resolve(context);
  37. }
  38. }