mirror of
https://github.com/discourse/discourse.git
synced 2025-01-18 18:52:45 +08:00
FIX: uses \n
for line breaks in table builder (#27711)
The old implementation used unnecessary `\r\n` and caused the table generator to incorrectly add extra empty lines. This commit replaces it with `\n`, fixing the bug
This commit is contained in:
parent
09b57bff11
commit
59b061ccfe
|
@ -645,7 +645,7 @@ export function arrayToTable(array, cols, colPrefix = "col", alignments) {
|
|||
// Generate table headers
|
||||
table += "|";
|
||||
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 body
|
||||
array.forEach(function (item) {
|
||||
|
@ -671,7 +671,7 @@ export function arrayToTable(array, cols, colPrefix = "col", alignments) {
|
|||
" "
|
||||
);
|
||||
})
|
||||
.join(" | ") + "|\r\n";
|
||||
.join(" | ") + "|\n";
|
||||
});
|
||||
|
||||
return table;
|
||||
|
|
|
@ -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`;
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue
Block a user