FIX: Remove linebreaks from cell data (#48)
Pasting text with linebreaks into the table UI results in incorrectly generated table markdown. This fix strips linebreaks from text during table markdown generation.
This commit is contained in:
parent
4c6b020fd8
commit
850e31c83d
|
@ -33,13 +33,14 @@ export function arrayToTable(array, cols, colPrefix = "col") {
|
||||||
table +=
|
table +=
|
||||||
cols
|
cols
|
||||||
.map(function (_key, index) {
|
.map(function (_key, index) {
|
||||||
return String(item[`${colPrefix}${index}`] || "");
|
return String(item[`${colPrefix}${index}`] || "").replace(
|
||||||
|
/\r?\n|\r/g,
|
||||||
|
" "
|
||||||
|
);
|
||||||
})
|
})
|
||||||
.join(" | ") + "|\r\n";
|
.join(" | ") + "|\r\n";
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return table
|
|
||||||
console.log(table);
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,6 +91,25 @@ discourseModule("Unit | Utilities", function () {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("arrayToTable returns valid table with multiline cell data", function (assert) {
|
||||||
|
const tableData = [
|
||||||
|
{
|
||||||
|
col0: "Jane\nDoe",
|
||||||
|
col1: "Teri",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
col0: "Finch",
|
||||||
|
col1: "Sami",
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
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`,
|
||||||
|
"it creates a valid table"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("findTableRegex", function (assert) {
|
test("findTableRegex", function (assert) {
|
||||||
const oneTable = `|Make|Model|Year|\r\n|--- | --- | ---|\r\n|Toyota|Supra|1998|`;
|
const oneTable = `|Make|Model|Year|\r\n|--- | --- | ---|\r\n|Toyota|Supra|1998|`;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue