Javascript解析clipboardData.getData("text/html")中的ht

Javascript parse the htmlstring from clipboardData.getData("text/html")

本文关键字:quot html 中的 ht text clipboardData Javascript 解析 getData      更新时间:2023-09-26

我从MS word复制/粘贴样式文本到在线文本编辑器。当我使用JavaScript clipboardData.getData("text/html")获取htmlstring时,我可以看到文本已经被转换为HTML/CSS样式,例如,缩进将被转换为text-indent="10dp""'t""     "代替。是否有一种方法可以在文本中键入所有控制字符?

也,我不知道CRLF是从哪里来的?

从Htmlstring

THE BOAT did not sail until late afternoon, but so eager was **CRLF**
Robert Townsend to get home that he thought, had there been a day as long as **CRLF**
this.
原来

THE BOAT did not sail until late afternoon, but so eager was Robert Townsend to get home that he thought, had there been a day as long as this.

编辑

对不起,也许我之前的问题不够清楚。当我剥离html字符串,由doc.body. textcontent ||doc.body。innerText,我仍然得到结果字符串中的CRLF,所以如何摆脱那些样式标记。哪一个就像clipboardData.getData("text")一样?

多余的空格和CRLF在HTML中是没有意义的,你可以忽略它们;你会在需要的地方发现困难(