I'm trying to create a text editor in electron. I have this in my HTML file:
<pre><div class="file-content" contenteditable="true"></div></pre>
<button onclick="saveFile();">Save</button>
In a Javascript file, I have this:
const fs = require('fs');
const $ = require('jquery');
function saveFile() {
fs.writeFile([filepath], $('.file-content').text(), function (err) {
if (err) return console.log(err);
});
}
But when I enter a text with a few lines in it, when I click the save button, the text gets written as one line. For example:
Input:
line1
line2
line3
File after save:
line1line2line3
tag, which is exactly what you're already doing. That works for a prefilled
tag, but not for your scenario of a content editable
tags with linebreaks (\n) and Chromium is putting
.