Răsfoiți Sursa

rename and moved files about markdown.

Ryu Sato 8 ani în urmă
părinte
comite
28b1f6e216

+ 4 - 4
resource/js/components/PageEditor/Editor.js

@@ -38,8 +38,8 @@ import emojiAutoCompleteHelper from './EmojiAutoCompleteHelper';
 
 
 import InterceptorManager from '../../../../lib/util/interceptor-manager';
 import InterceptorManager from '../../../../lib/util/interceptor-manager';
 
 
-import MarkdownListHelper from './MarkdownListHelper';
-import MarkdownTableHelper from './MarkdownTableHelper';
+import MarkdownListInterceptor from './MarkdownListInterceptor';
+import MarkdownTableInterceptor from './MarkdownTableInterceptor';
 
 
 export default class Editor extends React.Component {
 export default class Editor extends React.Component {
 
 
@@ -51,8 +51,8 @@ export default class Editor extends React.Component {
 
 
     this.interceptorManager = new InterceptorManager();
     this.interceptorManager = new InterceptorManager();
     this.interceptorManager.addInterceptors([
     this.interceptorManager.addInterceptors([
-      new MarkdownListHelper(),
-      new MarkdownTableHelper(),
+      new MarkdownListInterceptor(),
+      new MarkdownTableInterceptor(),
     ]);
     ]);
 
 
     this.state = {
     this.state = {

+ 8 - 13
resource/js/components/PageEditor/MarkdownListHelper.js → resource/js/components/PageEditor/MarkdownListInterceptor.js

@@ -1,18 +1,13 @@
 import { BasicInterceptor } from 'crowi-pluginkit';
 import { BasicInterceptor } from 'crowi-pluginkit';
 import * as codemirror from 'codemirror';
 import * as codemirror from 'codemirror';
 
 
-import mlu from '../../util/interceptor/MarkdownListUtil';
+import mlu from './MarkdownListUtil';
 
 
-export default class MarkdownListHelper extends BasicInterceptor {
+export default class MarkdownListInterceptor extends BasicInterceptor {
 
 
   constructor() {
   constructor() {
     super();
     super();
 
 
-    // https://github.com/codemirror/CodeMirror/blob/c7853a989c77bb9f520c9c530cbe1497856e96fc/addon/edit/continuelist.js#L14
-    // https://regex101.com/r/7BN2fR/5
-    this.indentAndMarkRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]\s|[*+-]\s|(\d+)([.)]))(\s*)/;
-    this.indentAndMarkOnlyRE = /^(\s*)(>[> ]*|[*+-] \[[x ]\]|[*+-]|(\d+)[.)])(\s*)$/;
-
     this.pasteText = this.pasteText.bind(this);
     this.pasteText = this.pasteText.bind(this);
   }
   }
 
 
@@ -41,7 +36,7 @@ export default class MarkdownListHelper extends BasicInterceptor {
 
 
     // get strings from current position to EOL(end of line) before break the line
     // get strings from current position to EOL(end of line) before break the line
     const strToEol = mlu.getStrToEol(editor);
     const strToEol = mlu.getStrToEol(editor);
-    if (this.indentAndMarkRE.test(strToEol)) {
+    if (mlu.indentAndMarkRE.test(strToEol)) {
       codemirror.commands.newlineAndIndent(editor);
       codemirror.commands.newlineAndIndent(editor);
 
 
       // replace the line with strToEol (abort auto indent)
       // replace the line with strToEol (abort auto indent)
@@ -65,10 +60,10 @@ export default class MarkdownListHelper extends BasicInterceptor {
     // get strings from BOL(beginning of line) to current position
     // get strings from BOL(beginning of line) to current position
     const strFromBol = mlu.getStrFromBol(editor);
     const strFromBol = mlu.getStrFromBol(editor);
 
 
-    const matched = strFromBol.match(this.indentAndMarkRE);
+    const matched = strFromBol.match(mlu.indentAndMarkRE);
     // when match indentAndMarkOnlyRE
     // when match indentAndMarkOnlyRE
     // (this means the current position is the beginning of the list item)
     // (this means the current position is the beginning of the list item)
-    if (this.indentAndMarkOnlyRE.test(strFromBol)) {
+    if (mlu.indentAndMarkOnlyRE.test(strFromBol)) {
       const adjusted = this.adjustPastedData(strFromBol, text);
       const adjusted = this.adjustPastedData(strFromBol, text);
 
 
       // replace
       // replace
@@ -91,8 +86,8 @@ export default class MarkdownListHelper extends BasicInterceptor {
     let adjusted = null;
     let adjusted = null;
 
 
     // list data (starts with indent and mark)
     // list data (starts with indent and mark)
-    if (text.match(this.indentAndMarkRE)) {
-      const indent = indentAndMark.match(this.indentAndMarkRE)[1];
+    if (text.match(mlu.indentAndMarkRE)) {
+      const indent = indentAndMark.match(mlu.indentAndMarkRE)[1];
 
 
       // splice to an array of line
       // splice to an array of line
       const lines = text.match(/[^\r\n]+/g);
       const lines = text.match(/[^\r\n]+/g);
@@ -134,7 +129,7 @@ export default class MarkdownListHelper extends BasicInterceptor {
     let isListful = false;
     let isListful = false;
     let count = 0;
     let count = 0;
     lines.forEach((line) => {
     lines.forEach((line) => {
-      if (line.match(this.indentAndMarkRE)) {
+      if (line.match(mlu.indentAndMarkRE)) {
         count++;
         count++;
       }
       }
       // ensure to be true if it is 50% or more
       // ensure to be true if it is 50% or more

+ 0 - 2
resource/js/util/interceptor/MarkdownListUtil.js → resource/js/components/PageEditor/MarkdownListUtil.js

@@ -1,5 +1,3 @@
-import * as codemirror from 'codemirror';
-
 /**
 /**
  * Utility for markdown list
  * Utility for markdown list
  */
  */

+ 4 - 10
resource/js/components/PageEditor/MarkdownTableHelper.js → resource/js/components/PageEditor/MarkdownTableInterceptor.js

@@ -1,21 +1,15 @@
 import { BasicInterceptor } from 'crowi-pluginkit';
 import { BasicInterceptor } from 'crowi-pluginkit';
-import * as codemirror from 'codemirror';
 import markdownTable from 'markdown-table';
 import markdownTable from 'markdown-table';
 
 
-import mtu from '../../util/interceptor/MarkdownTableUtil';
+import mtu from './MarkdownTableUtil';
 
 
 /**
 /**
- * Utility for markdown table
+ * Interceptor for markdown table
  */
  */
-export default class MarkdownTableUtil extends BasicInterceptor {
+export default class MarkdownTableInterceptor extends BasicInterceptor {
 
 
   constructor() {
   constructor() {
     super();
     super();
-
-    // https://github.com/markdown-it/markdown-it/blob/d29f421927e93e88daf75f22089a3e732e195bd2/lib/rules_block/table.js#L83
-    // https://regex101.com/r/7BN2fR/7
-    this.tableAlignmentLineRE = /^[-:|][-:|\s]*$/;
-    this.linePartOfTableRE = /^\|[^\r\n]*|[^\r\n]*\|$|([^\|\r\n]+\|[^\|\r\n]*)+/; // own idea
   }
   }
 
 
   /**
   /**
@@ -47,7 +41,7 @@ export default class MarkdownTableUtil extends BasicInterceptor {
     // get strings from BOL(beginning of line) to current position
     // get strings from BOL(beginning of line) to current position
     const strFromBol = mtu.getStrFromBol(editor);
     const strFromBol = mtu.getStrFromBol(editor);
 
 
-    if (isEndOfLine && this.linePartOfTableRE.test(strFromBol)) {
+    if (isEndOfLine && mtu.linePartOfTableRE.test(strFromBol)) {
       // get lines all of table from current position to beginning of table
       // get lines all of table from current position to beginning of table
       const strTableLines = mtu.getStrFromBot(editor);
       const strTableLines = mtu.getStrFromBot(editor);
 
 

+ 0 - 2
resource/js/util/interceptor/MarkdownTableUtil.js → resource/js/components/PageEditor/MarkdownTableUtil.js

@@ -1,5 +1,3 @@
-import * as codemirror from 'codemirror';
-
 /**
 /**
  * Utility for markdown table
  * Utility for markdown table
  */
  */

+ 2 - 2
resource/js/components/PageEditor/PasteHelper.js

@@ -1,6 +1,6 @@
 import accepts from 'attr-accept'
 import accepts from 'attr-accept'
 
 
-import markdownListHelper from './MarkdownListHelper';
+import markdownListInterceptor from './MarkdownListInterceptor';
 
 
 class PasteHelper {
 class PasteHelper {
 
 
@@ -21,7 +21,7 @@ class PasteHelper {
       return;
       return;
     }
     }
 
 
-    markdownListHelper.pasteText(editor, event, text);
+    markdownListInterceptor.pasteText(editor, event, text);
   }
   }
 
 
   // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with
   // Firefox versions prior to 53 return a bogus MIME type for every file drag, so dragovers with