mirror of
https://github.com/gchq/CyberChef.git
synced 2025-05-10 00:05:11 -04:00
Edited ToTable to finish rows in each format
This commit is contained in:
parent
c9d9730726
commit
7e9c6ec2aa
1 changed files with 25 additions and 0 deletions
|
@ -59,6 +59,18 @@ class ToTable extends Operation {
|
||||||
// Process the input into a nested array of elements.
|
// Process the input into a nested array of elements.
|
||||||
const tableData = Utils.parseCSV(Utils.escapeHtml(input), cellDelims.split(""), rowDelims.split(""));
|
const tableData = Utils.parseCSV(Utils.escapeHtml(input), cellDelims.split(""), rowDelims.split(""));
|
||||||
|
|
||||||
|
// Gets maximum number of columns for row formatting completion
|
||||||
|
let maxNumCols = 0;
|
||||||
|
tableData.forEach(function(row, index) {
|
||||||
|
let numCols = 0;
|
||||||
|
row.forEach(function(cell, cellIndex) {
|
||||||
|
numCols += 1;
|
||||||
|
if (numCols > maxNumCols) {
|
||||||
|
maxNumCols = numCols;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
if (!tableData.length) return "";
|
if (!tableData.length) return "";
|
||||||
|
|
||||||
// Render the data in the requested format.
|
// Render the data in the requested format.
|
||||||
|
@ -118,10 +130,17 @@ class ToTable extends Operation {
|
||||||
* Outputs a row of correctly padded cells.
|
* Outputs a row of correctly padded cells.
|
||||||
*/
|
*/
|
||||||
function outputRow(row, longestCells) {
|
function outputRow(row, longestCells) {
|
||||||
|
let rowCount = 0;
|
||||||
let rowOutput = verticalBorder;
|
let rowOutput = verticalBorder;
|
||||||
row.forEach(function(cell, index) {
|
row.forEach(function(cell, index) {
|
||||||
rowOutput += " " + cell + " ".repeat(longestCells[index] - cell.length) + " " + verticalBorder;
|
rowOutput += " " + cell + " ".repeat(longestCells[index] - cell.length) + " " + verticalBorder;
|
||||||
|
rowCount += 1;
|
||||||
});
|
});
|
||||||
|
while (rowCount < maxNumCols) {
|
||||||
|
rowOutput += " " + " ".repeat(longestCells[rowCount]) + " " + verticalBorder;
|
||||||
|
rowCount += 1;
|
||||||
|
}
|
||||||
|
|
||||||
rowOutput += "\n";
|
rowOutput += "\n";
|
||||||
return rowOutput;
|
return rowOutput;
|
||||||
}
|
}
|
||||||
|
@ -175,10 +194,16 @@ class ToTable extends Operation {
|
||||||
* @param {string} cellType
|
* @param {string} cellType
|
||||||
*/
|
*/
|
||||||
function outputRow(row, cellType) {
|
function outputRow(row, cellType) {
|
||||||
|
let rowCount = 0
|
||||||
let output = "<tr>";
|
let output = "<tr>";
|
||||||
row.forEach(function(cell) {
|
row.forEach(function(cell) {
|
||||||
output += "<" + cellType + ">" + cell + "</" + cellType + ">";
|
output += "<" + cellType + ">" + cell + "</" + cellType + ">";
|
||||||
|
rowCount += 1;
|
||||||
});
|
});
|
||||||
|
while (rowCount < maxNumCols) {
|
||||||
|
output += "<" + cellType + ">" + "</" + cellType + ">";
|
||||||
|
rowCount += 1;
|
||||||
|
}
|
||||||
output += "</tr>";
|
output += "</tr>";
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue