JSFiddle - React, Tailwind, and code Playground

HTML

<!DOCTYPE html>
<html>
    
    <head></head>
    
    <body>
        <pre class="does-not-preserve-newlines"></pre>
        <pre class="does-preserve-newlines"></pre>
    </body>
    
</html>

JavaScript

$('pre.does-not-preserve-newlines').html("line1\nline2");
$('pre.does-preserve-newlines').html(" line1\nline2");