Open mariuspaliga opened 1 year ago
Hi @mariuspaliga! Sorry for the delay, I missed this in the Github email firehose.
Happy to give a shot of adding this usecase, I'll see if I can work on this over the weekend
Man, this was a nerd snipe. I learnt a lot 😄
It is technically part of the CSV RFC I found out!
Fields containing line breaks (CRLF), double quotes, and commas should be enclosed in double-quotes. For example:
"aaa","b CRLF bb","ccc" CRLF zzz,yyy,xxx
It's a bit of a pain with most of the existing libraries because they do various trim/whitespace removal. I did find one that does it, but it turns it into an array rather than a JSON object, but it does handle newlines in quotes:
//convert.js
const { parseCsv } = require("@jjkavalam/csv-parse")
function convert(csvString) {
let csvrows = parseCsv(csvString)
// remove empty elements
csvrows = csvrows.filter(e => e.length);
// regex newline-alikes
// TODO
var arrayLength = csvrows.length;
for (var i = 0; i < arrayLength; i++) {
console.log(csvrows[i]);
}
return csvrows
}
module.exports = convert
console.log
[ 'first', 'line', '\n multi\n line\n input\n' ]
at log (convert.js:22:13)
Gonna poke at it more tonight
It seems that the current version does not correctly convert when there are multiline inputs. Example:
This would result in broken md output.
One possible result could possibly be (but still not sure this is the correct one):
line
input
Would it be possible to implement something like that?