Skip to content

Commit 7b43e99

Browse files
committed
Handle escaping pipe.
1 parent 7dc3157 commit 7b43e99

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/CsvToMarkdown.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ function csvToMarkdown(csvContent, delimiter, hasHeader) {
2727
if (typeof maxRowLen[ii] == "undefined") {
2828
maxRowLen[ii] = 0;
2929
}
30+
// escape pipes
31+
ee = ee.replace(/\|/g, "\\|");
3032
maxRowLen[ii] = Math.max(maxRowLen[ii], ee.length);
3133
tabularData[i][ii] = ee;
3234
});

src/CsvToMarkdown.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @param {boolean} hasHeader - Whether to use the first row of Data as headers
77
* @returns {string}
88
*/
9-
export function csvToMarkdown(csvContent: string, delimiter: string = "\t", hasHeader: boolean = false) : string {
9+
export function csvToMarkdown(csvContent: string, delimiter: string = "\t", hasHeader: boolean = false): string {
1010
if (delimiter != "\t") {
1111
csvContent = csvContent.replace(/\t/g, " ");
1212
}
@@ -27,6 +27,9 @@ export function csvToMarkdown(csvContent: string, delimiter: string = "\t", hasH
2727
maxRowLen[ii] = 0;
2828
}
2929

30+
// escape pipes
31+
ee = ee.replace(/\|/g, "\\|");
32+
3033
maxRowLen[ii] = Math.max(maxRowLen[ii], ee.length);
3134
tabularData[i][ii] = ee;
3235
});

0 commit comments

Comments
 (0)