从电子邮件的字符串正文中删除格式标签 [英] Remove formatting tags from string body of email
问题描述
如何在调用时删除所有格式标签:
How do you remove all formatting tags when calling:
GmailApp.getInboxThreads()[0].getMessages()[0].getBody()
这样,文本的唯一剩余部分就是可以阅读的内容.
such that the only remainder of text is that which can be read.
格式化可以销毁;正文中的文本只需要解析,但标签如:
Formatting can be destroyed; the text in the body is only needed to be parsed, but tags such as:
"&"
<br>
可能还有其他人需要删除.
and possibly others, need to be removed.
推荐答案
我不确定您所说的 .getBody()
是什么意思 - 这应该返回 DOM 主体元素吗?
I am not sure what you mean by .getBody()
- is this supposed to return a DOM body element?
然而,去除 HTML 标签最简单的解决方案可能是让浏览器渲染 HTML 并要求他提供文本内容:
However, the simplest solution for removing HTML tags is probably to let the browser render the HTML and ask him for the text content:
var myHTMLContent = "hello & world <br />!";
var tempDiv = document.createElement('div');
tempDiv.innerHTML = myHTMLContent;
// retrieve the cleaned content:
var textContent = tempDiv.innerText;
在上面的例子中,textContent
变量将包含文本
With the above example, the textContent
variable will contain the text
"hello & world
!"
(注意由于 <br/>
标签导致的换行符.)
(Note the line break due to the <br />
tag.)
这篇关于从电子邮件的字符串正文中删除格式标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!