Home > Enterprise >  How to convert html string to plain text without html tags in google app script?
How to convert html string to plain text without html tags in google app script?

Time:11-01

I'm new to google app script.

I was trying to convert html string to plain text without html tags in google app script using the enter image description here

While my actual expectation is in the third column.

Can someone tell me what is wrong with my previous script?

Thank you!

CodePudding user response:

In your situation, for example, how about the following modification?

From:

return strText;

To:

return strText.trim();

Reference:

CodePudding user response:

If you're running in a browser, then the easiest way is just to let the browser do it for you

function stripHtml(html)
{
   let tmp = document.createElement("DIV");
   tmp.innerHTML = html;
   return tmp.textContent || tmp.innerText || "";
}
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related