Skip to content

Commit

Permalink
Skip minimum distance between columns
Browse files Browse the repository at this point in the history
  • Loading branch information
nekno committed Mar 18, 2022
1 parent 97b4a1a commit 2762be9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions assets/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,9 @@ function parseTable(table) {
for (var j = 0; j < longest.length; j++) {
if (isColumnSeparator(lines.slice(), j)) {
colIndexes.push(j);
// column separators are each padded by a space
// so skip over minimum distance between 2 columns
j += 2;
}
}

Expand Down Expand Up @@ -566,16 +569,15 @@ function isColumnSeparator(lines, column) {
return false;
}

var previousColumn = column-1;
var previousColumn = column - 1;
var thisLineThisChar = thisLine[column];
var thisLinePreviousChar = (previousColumn > 0) ? thisLine[previousColumn] : " ";
var nextLineThisChar = nextLine[column];
var nextLinePreviousChar = (previousColumn > 0) ? nextLine[previousColumn] : " ";

if (thisLineThisChar == nextLineThisChar
&& thisLineThisChar != " "
&& thisLinePreviousChar == " "
&& nextLinePreviousChar == " "
if (thisLineThisChar == nextLineThisChar
&& !isSpace(thisLineThisChar)
&& isSpace(thisLinePreviousChar, nextLinePreviousChar)
) {
// Rows match, check next row down
return isColumnSeparator(lines.splice(1), column);
Expand All @@ -590,6 +592,10 @@ function isSeparatorLine(line) {
return line.trim().indexOf(" ") == -1; // must not have spaces
}

function isSpace(...chars) {
return chars.every(value => value == " ");
}

function _trim(str) {
var rgx = /^\s*(.*?)\s*$/;
var result = str.match(rgx);
Expand Down

0 comments on commit 2762be9

Please sign in to comment.