A platform for community discussion. Free, open, simple.
FIX: uses `\n` for line breaks in table builder (#27711)
锦心59b061ccfe86
diff --git a/app/assets/javascripts/discourse/app/lib/utilities.js b/app/assets/javascripts/discourse/app/lib/utilities.jsindex 2de3aa38027..d16c394a342 100644--- a/app/assets/javascripts/discourse/app/lib/utilities.js+++ b/app/assets/javascripts/discourse/app/lib/utilities.js@@ -645,7 +645,7 @@ export function arrayToTable(array, cols, colPrefix = "col", alignments) {// Generate table headerstable += "|";table += cols.join(" | ");- table += "|\r\n|";+ table += "|\n|";const alignMap = {left: ":--",@@ -657,7 +657,7 @@ export function arrayToTable(array, cols, colPrefix = "col", alignments) {table += cols.map((_, index) => alignMap[String(alignments?.[index])] || "---").join(" | ");- table += "|\r\n";+ table += "|\n";// Generate table bodyarray.forEach(function (item) {@@ -671,7 +671,7 @@ export function arrayToTable(array, cols, colPrefix = "col", alignments) {" ");})- .join(" | ") + "|\r\n";+ .join(" | ") + "|\n";});return table;diff --git a/app/assets/javascripts/discourse/tests/fixtures/md-table.js b/app/assets/javascripts/discourse/tests/fixtures/md-table.jsindex cf410f5c6a4..5802a943703 100644--- a/app/assets/javascripts/discourse/tests/fixtures/md-table.js+++ b/app/assets/javascripts/discourse/tests/fixtures/md-table.js@@ -1,3 +1,3 @@-export const mdTable = `|Make | Model | Year|\r\n|--- | --- | ---|\r\n|Toyota | Supra | 1998|\r\n|Nissan | Skyline | 1999|\r\n|Honda | S2000 | 2001|\r\n`;-export const mdTableSpecialChars = `|Make | Model | Price|\r\n|--- | --- | ---|\r\n|Toyota | Supra | $50,000|\r\n| | Celica | $20,000|\r\n|Nissan | GTR | $80,000|\r\n`;-export const mdTableNonUniqueHeadings = `|col1 | col2 | col1|\r\n|--- | --- | ---|\r\n|Col A | Col B | Col C|\r\n`;+export const mdTable = `|Make | Model | Year|\n|--- | --- | ---|\n|Toyota | Supra | 1998|\n|Nissan | Skyline | 1999|\n|Honda | S2000 | 2001|\n`;+export const mdTableSpecialChars = `|Make | Model | Price|\n|--- | --- | ---|\n|Toyota | Supra | $50,000|\n| | Celica | $20,000|\n|Nissan | GTR | $80,000|\n`;+export const mdTableNonUniqueHeadings = `|col1 | col2 | col1|\n|--- | --- | ---|\n|Col A | Col B | Col C|\n`;diff --git a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.jsindex c36b28e34a3..0bc0471e734 100644--- a/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js+++ b/app/assets/javascripts/discourse/tests/unit/lib/utilities-test.js@@ -388,7 +388,7 @@ module("Unit | Utilities | table-builder", function (hooks) {assert.strictEqual(arrayToTable(tableData, ["Col 1", "Col 2"], "A"),- `|Col 1 | Col 2|\r\n|--- | ---|\r\n|hey | you|\r\n|over | there|\r\n`,+ `|Col 1 | Col 2|\n|--- | ---|\n|hey | you|\n|over | there|\n`,"it works");});@@ -407,7 +407,7 @@ module("Unit | Utilities | table-builder", function (hooks) {assert.strictEqual(arrayToTable(tableData, ["Col 1", "Col 2"]),- `|Col 1 | Col 2|\r\n|--- | ---|\r\n|Jane Doe | Teri|\r\n|Finch | Sami|\r\n`,+ `|Col 1 | Col 2|\n|--- | ---|\n|Jane Doe | Teri|\n|Finch | Sami|\n`,"it creates a valid table");});@@ -425,13 +425,13 @@ module("Unit | Utilities | table-builder", function (hooks) {"col",alignment),- "|Col 1 | Col 2 | Col 3 | Col 4|\r\n|:-- | :-: | --: | ---|\r\n|left | center | right | unspecificated|\r\n|111 | 222 | 333 | 444|\r\n",+ "|Col 1 | Col 2 | Col 3 | Col 4|\n|:-- | :-: | --: | ---|\n|left | center | right | unspecificated|\n|111 | 222 | 333 | 444|\n","it creates a valid table");});test("findTableRegex", function (assert) {- const oneTable = `|Make|Model|Year|\r\n|--- | --- | ---|\r\n|Toyota|Supra|1998|`;+ const oneTable = `|Make|Model|Year|\n|--- | --- | ---|\n|Toyota|Supra|1998|`;assert.strictEqual(oneTable.match(findTableRegex()).length,