从电子邮件的字符串正文中移除格式化标签 [英] Remove formatting tags from string body of email

查看:113
本文介绍了从电子邮件的字符串正文中移除格式化标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  GmailApp.getInboxThreads()[0] .getMessages()[

如何在调用时移除所有格式化标记? 0] .getBody()

这样文本的唯一剩余部分就是可读取的。 / p>

格式化可能会被破坏;在正文中的文本只需要被解析,但标签如:

 & amp; 
< br>

以及其他可能需要删除的内容。

.getBody() - 是否应该返回一个DOM body元素?

然而,移除HTML标签最简单的解决方案可能是让浏览器呈现HTML并请求他提供文本内容:

  var myHTMLContent =hello& amp; world< br /> ;!; 
var tempDiv = document.createElement('div');
tempDiv.innerHTML = myHTMLContent;

//检索清理过的内容:
var textContent = tempDiv.innerText;

通过上面的例子, textContent 变量将包含文本

 hello& world 

(注意由于< br /> 标签。)


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:

"&amp;" 
<br>

and possibly others, need to be removed.

解决方案

I am not sure what you mean by .getBody() - is this supposed to return a DOM body element?

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 &amp; world <br />!";
var tempDiv = document.createElement('div');
tempDiv.innerHTML = myHTMLContent;

// retrieve the cleaned content:
var textContent = tempDiv.innerText;

With the above example, the textContent variable will contain the text

"hello & world
!"

(Note the line break due to the <br /> tag.)

这篇关于从电子邮件的字符串正文中移除格式化标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆