In this example I'm trying to convert everything in #fileDisplayArea
to markdown. However, the raw HTML within the div
is not applied.
<div id="fileDisplayArea"># Title
Lorem **ipsum** dolor sit amet, *consectetur adipiscing* elit
<center>Consectetur libero id faucibus nisl tincidunt eget</center>
In ornare quam viverra orci sagittis eu.
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/10.0.0/markdown-it.min.js"></script>
<script>
let md = window.markdownit();
let txt = document.getElementById('fileDisplayArea').innerHTML;
document.getElementById('fileDisplayArea').innerHTML = md.render(txt);
</script>
Running this code properly converts the markdown elements but the raw HTML is not read and instead shows up in the output. Changing the last instance of innerHTML
to innerText
provides the following output:
<p>Lorem <strong>ipsum</strong> dolor sit amet,
<em>consectetur adipiscing</em> elit</p>
<p><center>Consectetur libero id faucibus nisl tincidunt eget</center></p>
<p>In ornare quam viverra orci sagittis eu.</p>
This shows that the less/greater than symbols are being escaped. How do I prevent this?