MarkdownListInterceptor.js 1.0 KB

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