Save line-breaks in a custom Electron text editor

Viewed 55

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
0 Answers
Related