markdown-table-prettify
Version:
Transforms markdown tables to be more readable.
36 lines (35 loc) • 1.58 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectionInterpreter = void 0;
var SelectionInterpreter = /** @class */ (function () {
function SelectionInterpreter(_strict) {
this._strict = _strict;
}
SelectionInterpreter.prototype.allRows = function (selection) {
var split = selection.split(/\r\n|\r|\n/).map(this.splitLine, this);
return this._strict
? split
: split.filter(function (arr) { return arr.length > 0 && !(arr.length == 1 && /^\s*$/.test(arr[0])); });
};
SelectionInterpreter.prototype.separator = function (selection) {
return this.allRows(selection).filter(function (v, i) { return i == 1; })[0];
};
SelectionInterpreter.prototype.splitLine = function (line) {
if (line == null || line.length == 0)
return [];
var result = [], index = -1, previousSplitIndex = -1;
while ((index = line.indexOf("|", index + 1)) > -1) {
if (line[index - 1] != "\\" && !this.codeBlockOpenTill(line.substr(0, index))) {
result.push(line.substring(previousSplitIndex + 1, index));
previousSplitIndex = index;
}
}
result.push(line.substring(previousSplitIndex + 1));
return result;
};
SelectionInterpreter.prototype.codeBlockOpenTill = function (text) {
return (text.match(/`/g) || []).length % 2 != 0;
};
return SelectionInterpreter;
}());
exports.SelectionInterpreter = SelectionInterpreter;
;