Javascript从clipboardData.getData解析htmlstring(" text / html")

时间:2013-01-22 09:08:05

标签: javascript clipboard

我将样式文本从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.

修改

抱歉,也许我之前的问题不够明确。当我通过doc.body.textContent || doc.body.innerText去掉html字符串时,我仍然在结果字符串中得到CRLF,所以如何摆脱那些样式标记。就像clipboardData.getData(“text”)一样?

1 个答案:

答案 0 :(得分:0)

额外的空格和CRLF在HTML中毫无意义,你可以忽略它们;你会发现需要的地方(