From 307094ab37c0a3fa8f7fa3dae3ffc04bc6f18fc4 Mon Sep 17 00:00:00 2001 From: awachen Date: Thu, 10 Jul 2025 20:26:37 +0800 Subject: [PATCH 1/2] Update tables.js Add separators on both sides of the table to maintain compatibility with other plugins. --- lib/tables.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/tables.js b/lib/tables.js index 7ec9d77..dee3d47 100644 --- a/lib/tables.js +++ b/lib/tables.js @@ -31,7 +31,8 @@ function addTable(addHeader) { var tableColumnSeparator = /([ ]{2,}|[\t])/gi; function convertToTableWithoutHeader(text) { - var firstRow = text.match(/.+/); + var tableContent = "| " + text.trim().replace(tableColumnSeparator, " | ").trim().replace(/\n/g, " |\n| ") + " |"; + var firstRow = text.trim().match(/.+/); var columnSeparators = firstRow == null ? null : firstRow[0].match(tableColumnSeparator); var columnCount = columnSeparators == null ? 0 : columnSeparators.length; @@ -39,18 +40,18 @@ function convertToTableWithoutHeader(text) { for (var i = 0; i < columnCount + 1; i++) { line1.push("column" + i); } - var tableHeader = line1.join(" | ") + "\n"; + var tableHeader = "| " + line1.join(" | ") + " |\n"; tableHeader = tableHeader + tableHeader.replace(/[a-z0-9]/gi, "-"); - return tableHeader + text.replace(tableColumnSeparator, " | "); + return tableHeader + tableContent; } function convertToTableWithHeader(text) { - var textAsTable = text.replace(tableColumnSeparator, " | "); + var textAsTable = "| " + text.trim().replace(tableColumnSeparator, " | ").trim().replace(/\n/g, " |\n| ") + " |"; var firstRow = textAsTable.match(/.+/)[0]; var headerLine = firstRow.replace(/[^\|]/gi, "-"); - return firstRow + "\n" + headerLine + textAsTable.substring(firstRow.length); -} \ No newline at end of file + return firstRow + "\n" + headerLine + textAsTable.substring(firstRow.length); +} From b9bdee129e2b513edbcf1131082de7bd58daf3e2 Mon Sep 17 00:00:00 2001 From: awachen Date: Thu, 10 Jul 2025 20:28:23 +0800 Subject: [PATCH 2/2] Update tables.js Add separators on both sides --- lib/tables.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tables.js b/lib/tables.js index dee3d47..10a12ce 100644 --- a/lib/tables.js +++ b/lib/tables.js @@ -8,11 +8,11 @@ module.exports = { var sampleTable = [ "", - "Column A | Column B | Column C", - "---------|----------|---------", - " A1 | B1 | C1", - " A2 | B2 | C2", - " A3 | B3 | C3" + "| Column A | Column B | Column C |", + "| ---------|----------|--------- |", + "| A1 | B1 | C1 |", + "| A2 | B2 | C2 |", + "| A3 | B3 | C3 |" ].join("\n"); function addTable(addHeader) {