【问题标题】:Html parser in React not parsing correctly scriptReact中的Html解析器无法正确解析脚本
【发布时间】:2019-07-28 01:37:02
【问题描述】:

我正在使用这个库 https://www.npmjs.com/package/html-to-react 进行 html 解析,但由于某种原因,脚本没有正确解析,或者我可能缺少一些配置。

html,js(来自 infogram 的嵌入代码)如下所示:

<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>

我将其解析为htmlToReactParser.parse(html)},但由于某种原因无法正常工作。

我还将附上 dom 在检查器中的外观的打印屏幕。

所以基本上我的问题是我的反应应用程序上没有出现信息图。

【问题讨论】:

    标签: javascript html reactjs html-parsing


    【解决方案1】:

    问题出在脚本上,靠近 https:"; if (/^/{ 2 } /

    【讨论】:

    • 任何可能的解决方案?
    猜你喜欢
    • 1970-01-01
    • 2019-03-01
    • 2013-02-21
    • 2014-10-10
    • 2013-04-11
    • 1970-01-01
    • 1970-01-01
    • 2020-11-26
    • 2016-01-21
    相关资源
    最近更新 更多