Html parser in React not parsing correctly script

时间:2019-03-06 11:39:16

标签: javascript html reactjs html-parsing

I am using this library https://www.npmjs.com/package/html-to-react for html parsing but for some reason the scripts are not parsed correctly or probably I am missing some configurations.

The html,js (embedded code from infogram) looks like this:

<div class="infogram-embed" data-id="bc973e33-5e3e-4bf3-b587-9a6f16caf158" data-type="interactive" data-title="Konsumtionslån från Norden ökar"></div><script>!function(e,t,s,i){var n="InfogramEmbeds",o=e.getElementsByTagName("script")[0],d=/^http:/.test(e.location)?"http:":"https:";if(/^/{2}/.test(i)&&(i=d+i),window[n]&&window[n].initialized)window[n].process&&window[n].process();else if(!e.getElementById(s)){var r=e.createElement("script");r.async=1,r.id=s,r.src=i,o.parentNode.insertBefore(r,o)}}(document,0,"infogram-async","https://e.infogram.com/js/dist/embed-loader-min.js");</script><div style="padding:8px 0;font-family:Arial!important;font-size:13px!important;line-height:15px!important;text-align:center;border-top:1px solid #dadada;margin:0 30px"><a href="https://infogram.com/bc973e33-5e3e-4bf3-b587-9a6f16caf158" style="color:#989898!important;text-decoration:none!important;" target="_blank">Konsumtionslån från Norden ökar</a><br><a href="https://infogram.com" style="color:#989898!important;text-decoration:none!important;" target="_blank" rel="nofollow">Infogram</a></div>

And I parse it as htmlToReactParser.parse(html)} but for some reason is not working.

I will also attach a print screen how the dom looks like in inspector. enter image description here

So basically my problem is that I dont see infogram graphs appearing on my react app.

1 个答案:

答案 0 :(得分:0)

问题出在https:“附近的脚本;如果((/ ^ / {2} /