Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

196
Views
How to convert html string to plain text without html tags in google app script?

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 reference in this question.

However, when I try to apply it to my script, it is not working as expected.

This is the script that I use:

function toStringFromHtml(html)
{
  
html = '<div>' + html + '</div>';
html = html.replace(/<br>/g,"");
var document = XmlService.parse(html);
var strText = XmlService.getPrettyFormat().format(document);
strText = strText.replace(/<[^>]*>/g,"");
return strText;
}

and this is the output: 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!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

From:

return strText;

To:

return strText.trim();

Reference:

  • trim()
about 4 years ago · Juan Pablo Isaza Report

0

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 || "";
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!