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;
if (story.text) {
let domparser = new DOMParser();
let doc = domparser.parseFromString(story.text, 'text/html');
nodes = doc.querySelector('body').children;
let div = document.createElement('div');
div.innerHTML = story.text;
nodes = div.childNodes;
}
return (
@ -85,11 +85,15 @@ class Article extends React.Component {
v.innerHTML.split('\n\n').map(x =>
<p dangerouslySetInnerHTML={{ __html: x }} />
)
:
(v.nodeName === '#text' ?
<p>{v.data}</p>
:
<>
<v.localName dangerouslySetInnerHTML={{ __html: v.innerHTML }} />
<v.localName dangerouslySetInnerHTML={v.innerHTML ? { __html: v.innerHTML } : null} />
{v.localName == 'pre' && <button onClick={() => this.pConvert(k)}>Convert Code to Paragraph</button>}
</>
)
)}
</div>
: