Remove formatting tags from string body of email

前端 未结 5 581
臣服心动
臣服心动 2020-12-03 02:38

How do you remove all formatting tags when calling:

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

such that the only remainder o

5条回答
  •  北海茫月
    2020-12-03 02:49

    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 & world 
    !"; 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
    tag.)

提交回复
热议问题