问题描述
调用时如何去掉所有格式化标签:
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.)
这篇关于从电子邮件的字符串正文中删除格式标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!





大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)