Преглед изворни кода

use fromMarkdownString instead of parseFromTableStringToMarkdownTable

utsushiiro пре 7 година
родитељ
комит
16abc5435b

+ 2 - 1
src/client/js/components/PageEditor/Editor.js

@@ -13,6 +13,7 @@ import HandsontableModal from './HandsontableModal';
 import pasteHelper from './PasteHelper';
 import pasteHelper from './PasteHelper';
 
 
 import mtu from './MarkdownTableUtil';
 import mtu from './MarkdownTableUtil';
+import MarkdownTable from '../../models/MarkdownTable';
 
 
 export default class Editor extends AbstractEditor {
 export default class Editor extends AbstractEditor {
 
 
@@ -217,7 +218,7 @@ export default class Editor extends AbstractEditor {
    */
    */
   getMarkDownTable() {
   getMarkDownTable() {
     const cm = this.getEditorSubstance().getCodeMirror();
     const cm = this.getEditorSubstance().getCodeMirror();
-    return mtu.parseFromTableStringToMarkdownTable(mtu.getStrFromBotToEot(cm));
+    return MarkdownTable.fromMarkdownString(mtu.getStrFromBotToEot(cm));
   }
   }
 
 
   /**
   /**

+ 3 - 2
src/client/js/components/PageEditor/MarkdownTableInterceptor.js

@@ -1,6 +1,7 @@
 import { BasicInterceptor } from 'growi-pluginkit';
 import { BasicInterceptor } from 'growi-pluginkit';
 
 
 import mtu from './MarkdownTableUtil';
 import mtu from './MarkdownTableUtil';
+import MarkdownTable from '../../models/MarkdownTable';
 
 
 /**
 /**
  * Interceptor for markdown table
  * Interceptor for markdown table
@@ -47,12 +48,12 @@ export default class MarkdownTableInterceptor extends BasicInterceptor {
     if (mtu.isEndOfLine(cm) && mtu.linePartOfTableRE.test(strFromBol)) {
     if (mtu.isEndOfLine(cm) && 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 strFromBot = mtu.getStrFromBot(cm);
       const strFromBot = mtu.getStrFromBot(cm);
-      let table = mtu.parseFromTableStringToMarkdownTable(strFromBot);
+      let table = MarkdownTable.fromMarkdownString(strFromBot);
 
 
       mtu.addRowToMarkdownTable(table);
       mtu.addRowToMarkdownTable(table);
 
 
       const strToEot = mtu.getStrToEot(cm);
       const strToEot = mtu.getStrToEot(cm);
-      const tableBottom = mtu.parseFromTableStringToMarkdownTable(strToEot);
+      const tableBottom = MarkdownTable.fromMarkdownString(strToEot);
       if (tableBottom.table.length > 0) {
       if (tableBottom.table.length > 0) {
         table = mtu.mergeMarkdownTable([table, tableBottom]);
         table = mtu.mergeMarkdownTable([table, tableBottom]);
       }
       }

+ 0 - 40
src/client/js/components/PageEditor/MarkdownTableUtil.js

@@ -20,7 +20,6 @@ class MarkdownTableUtil {
     this.getStrFromBot = this.getStrFromBot.bind(this);
     this.getStrFromBot = this.getStrFromBot.bind(this);
     this.getStrToEot = this.getStrToEot.bind(this);
     this.getStrToEot = this.getStrToEot.bind(this);
 
 
-    this.parseFromTableStringToMarkdownTable = this.parseFromTableStringToMarkdownTable.bind(this);
     this.replaceMarkdownTableWithReformed = this.replaceMarkdownTableWithReformed.bind(this);
     this.replaceMarkdownTableWithReformed = this.replaceMarkdownTableWithReformed.bind(this);
   }
   }
 
 
@@ -92,45 +91,6 @@ class MarkdownTableUtil {
     return editor.getDoc().getRange(this.getBot(editor), this.getEot(editor));
     return editor.getDoc().getRange(this.getBot(editor), this.getEot(editor));
   }
   }
 
 
-  /**
-   * returns markdown table whose described by 'markdown-table' format
-   *   ref. https://github.com/wooorm/markdown-table
-   * @param {string} lines all of table
-   */
-  parseFromTableStringToMarkdownTable(strMDTable) {
-    const arrMDTableLines = strMDTable.split(/(\r\n|\r|\n)/);
-    let contents = [];
-    let aligns = [];
-    for (let n = 0; n < arrMDTableLines.length; n++) {
-      const line = arrMDTableLines[n];
-
-      if (this.tableAlignmentLineRE.test(line) && !this.tableAlignmentLineNegRE.test(line)) {
-        // parse line which described alignment
-        const alignRuleRE = [
-          { align: 'c', regex: /^:-+:$/ },
-          { align: 'l', regex: /^:-+$/  },
-          { align: 'r', regex: /^-+:$/  },
-        ];
-        let lineText = '';
-        lineText = line.replace(/^\||\|$/g, ''); // strip off pipe charactor which is placed head of line and last of line.
-        lineText = lineText.replace(/\s*/g, '');
-        aligns = lineText.split(/\|/).map(col => {
-          const rule = alignRuleRE.find(rule => col.match(rule.regex));
-          return (rule != undefined) ? rule.align : '';
-        });
-      }
-      else if (this.linePartOfTableRE.test(line)) {
-        // parse line whether header or body
-        let lineText = '';
-        lineText = line.replace(/\s*\|\s*/g, '|');
-        lineText = lineText.replace(/^\||\|$/g, ''); // strip off pipe charactor which is placed head of line and last of line.
-        const row = lineText.split(/\|/);
-        contents.push(row);
-      }
-    }
-    return (new MarkdownTable(contents, { align: aligns, stringLength: stringWidth }));
-  }
-
   /**
   /**
    * return boolean value whether the current position of cursor is end of line
    * return boolean value whether the current position of cursor is end of line
    */
    */