Fix bug with rendering text nodes

This commit is contained in:
Tanner Collin 2020-10-10 21:07:54 +00:00
parent f95df227f1
commit 99d3a234f4

View File

@ -56,9 +56,9 @@ class Article extends React.Component {
let nodes = null; let nodes = null;
if (story.text) { if (story.text) {
let domparser = new DOMParser(); let div = document.createElement('div');
let doc = domparser.parseFromString(story.text, 'text/html'); div.innerHTML = story.text;
nodes = doc.querySelector('body').children; nodes = div.childNodes;
} }
return ( return (
@ -86,10 +86,14 @@ class Article extends React.Component {
<p dangerouslySetInnerHTML={{ __html: x }} /> <p dangerouslySetInnerHTML={{ __html: x }} />
) )
: :
<> (v.nodeName === '#text' ?
<v.localName dangerouslySetInnerHTML={{ __html: v.innerHTML }} /> <p>{v.data}</p>
{v.localName == 'pre' && <button onClick={() => this.pConvert(k)}>Convert Code to Paragraph</button>} :
</> <>
<v.localName dangerouslySetInnerHTML={v.innerHTML ? { __html: v.innerHTML } : null} />
{v.localName == 'pre' && <button onClick={() => this.pConvert(k)}>Convert Code to Paragraph</button>}
</>
)
)} )}
</div> </div>
: :