Producing HTML file with safe HTML characters?

I’m using a script to loop through JSON objects to produce an HTML file. When I send the data to the HTML viewer action, everything works fine. When I instead write the data to a file (file.html) and open in Safari, everything works as expected except I get weird stuff like this:


I have tried to do this to the variables holding the text:

variable = encodeURI(variable);

but this results in text with a bunch of percents in it. I know there’s something to do here about escaping certain characters (quotation marks in particular, but I’m also trying to get emoji) but I don’t know what’s needed exactly.

You need to escape HTML entities. That is s different type of encoding from what is done for URLs. The HTML.escape docs function is provided for this purpose.

1 Like