Need help pruning the HTML file I get from one of my queries

Hi everyone!

I wonder how you would solve this?

I get this messy HTML of emails from one of my queries. It's actually mostly email, but at the bottom of it - there's always a big signature that messes up the looks of my retool app and makes the components way too large. I would love to prune the HTML before displaying it.

Bellow is an example HTML input that I get. I would like to remove the table bellow:

<span dir="ltr">Actual email</span>





<table style='color: rgba(0, 0, 0, 0.69); font-family: "Lineto Circular", -apple-system, "system-ui", "Segoe UI", Roboto, Helvetica, 
Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol"; font-size: 16px; overflow-anchor: none !important' width="100%">


table/signature stuff 

</table>




I get how its done in Javascript, but its always in the same HTML document so its easy to reference the table to GetElementByID, but how would it work in this case?

First solution that I have just came across was to add a transformer step and simply do this:

let data = {{DATA_SOURCE}}


return data.split('<table')[0]

This gets me everything in the HTML string before there are ever words 'Table'.

I am still curious if there's any way to manipulate the HTML with Javascript?

Hey @Arnoldas!

You can try using DOMParser here to create an element from your HTML that you can manipulate as you normally would then convert it back with its innertHTML property:

const parser = new DOMParser();
const doc = parser.parseFromString(htmlString, "text/html");
const tableElement = doc.querySelector('table');
tableElement.remove();
console.log(doc)
return doc.innerHTML;

Otherwise, you might explore using regular expressions to be a bit more precise in the way you remove parts of the string. For instance, the following should remove all table tags:

htmlString.replace(/<table.*table>/sg, '')

Do either of those work?

Appreciate the answers! I ended up using the data.split() in a transformer. I will come back here for these answers if I ever want to make this more advanced and learn more!