Search code examples
javascriptnwjs

Break lines after loading text from file and placing it in div nwjs


After loading text from inside a file using fs.readFileSync(Folder); How do I place it inside a div (which has contenteditable="true") in my nwjs app breaking lines according to how it was in the file?

Because a direct load places everything in the same line of that div.


Solution

  • You can replace all \n with <br />, or you can use the css style to preserve all line breakers:

    <div style="white-space: pre-line">{your text}</div>