我需要一种从无效中获取有效 html 的方法(我在数据库中有脏记录,所以我需要通过它并处理每条记录)。
有效的标准是它可以粘贴到一个<div></div>
as innerHtml 中。如果不能生成有效的 html,它应该是一个空字符串。我需要它做和 tinyMCE 一样的事情。见:
http: //fiddle.tinymce.com/v6baab
示例 1:
<div>hi there</span>
应该
<div>hi there</div>
或者<span>hi there</span>
示例 2:
<style> &amp;amp;lt;!-- /* Font Definitions */ @font-face {font-family: 'Century Gothic';} --&amp;gt; </style> AAAA
应该
<p>AAAA</p>
实现这一目标的最佳方法是什么?