|
|
@@ -5,7 +5,7 @@ import csvToMarkdown from 'csv-to-markdown-table';
|
|
|
// https://github.com/markdown-it/markdown-it/blob/d29f421927e93e88daf75f22089a3e732e195bd2/lib/rules_block/table.js#L83
|
|
|
// https://regex101.com/r/7BN2fR/7
|
|
|
const tableAlignmentLineRE = /^[-:|][-:|\s]*$/;
|
|
|
-const tableAlignmentLineNegRE = /^[^-:]*$/; // it is need to check to ignore empty row which is matched above RE
|
|
|
+const tableAlignmentLineNegRE = /^[^-:]*$/; // it is need to check to ignore empty row which is matched above RE
|
|
|
const linePartOfTableRE = /^\|[^\r\n]*|[^\r\n]*\|$|([^|\r\n]+\|[^|\r\n]*)+/; // own idea
|
|
|
|
|
|
// set up DOMParser
|
|
|
@@ -33,7 +33,7 @@ export default class MarkdownTable {
|
|
|
* (This method clones only the table field.)
|
|
|
*/
|
|
|
clone() {
|
|
|
- let newTable = [];
|
|
|
+ const newTable = [];
|
|
|
for (let i = 0; i < this.table.length; i++) {
|
|
|
newTable.push([].concat(this.table[i]));
|
|
|
}
|
|
|
@@ -75,11 +75,11 @@ export default class MarkdownTable {
|
|
|
const tableElement = dom.querySelector('table');
|
|
|
const trElements = tableElement.querySelectorAll('tr');
|
|
|
|
|
|
- let table = [];
|
|
|
+ const table = [];
|
|
|
let maxRowSize = 0;
|
|
|
for (let i = 0; i < trElements.length; i++) {
|
|
|
- let row = [];
|
|
|
- let cellElements = trElements[i].querySelectorAll('th,td');
|
|
|
+ const row = [];
|
|
|
+ const cellElements = trElements[i].querySelectorAll('th,td');
|
|
|
for (let j = 0; j < cellElements.length; j++) {
|
|
|
row.push(cellElements[j].innerHTML);
|
|
|
}
|
|
|
@@ -88,12 +88,12 @@ export default class MarkdownTable {
|
|
|
if (maxRowSize < row.length) maxRowSize = row.length;
|
|
|
}
|
|
|
|
|
|
- let align = [];
|
|
|
+ const align = [];
|
|
|
for (let i = 0; i < maxRowSize; i++) {
|
|
|
align.push('');
|
|
|
}
|
|
|
|
|
|
- return new MarkdownTable(table, {align: align});
|
|
|
+ return new MarkdownTable(table, { align });
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -110,7 +110,7 @@ export default class MarkdownTable {
|
|
|
*/
|
|
|
static fromMarkdownString(str) {
|
|
|
const arrMDTableLines = str.split(/(\r\n|\r|\n)/);
|
|
|
- let contents = [];
|
|
|
+ const contents = [];
|
|
|
let aligns = [];
|
|
|
for (let n = 0; n < arrMDTableLines.length; n++) {
|
|
|
const line = arrMDTableLines[n];
|
|
|
@@ -119,15 +119,15 @@ export default class MarkdownTable {
|
|
|
// parse line which described alignment
|
|
|
const alignRuleRE = [
|
|
|
{ align: 'c', regex: /^:-+:$/ },
|
|
|
- { align: 'l', regex: /^:-+$/ },
|
|
|
- { align: 'r', 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 : '';
|
|
|
+ aligns = lineText.split(/\|/).map((col) => {
|
|
|
+ const rule = alignRuleRE.find((rule) => { return col.match(rule.regex) });
|
|
|
+ return (rule != null) ? rule.align : '';
|
|
|
});
|
|
|
}
|
|
|
else if (linePartOfTableRE.test(line)) {
|
|
|
@@ -141,4 +141,5 @@ export default class MarkdownTable {
|
|
|
}
|
|
|
return (new MarkdownTable(contents, { align: aligns, stringLength: stringWidth }));
|
|
|
}
|
|
|
+
|
|
|
}
|