Replace special characters with HTML Entities?

Is there a way to do this with an action inside of KM? So that the text will correctly display on a webpage.

e.g.

the cat didn't sit on the "mat"

would become:

     the cat didn't sit on the "mat"

See Filter Variable action

mm, the other way round would often be useful too!

FILTER VARIABLE Action with “Encode HTML Entities” doesn’t work for me. The encoded entities don’t look correct and when “file/saved” the resulting html file doesn’t display correctly in either Safari or Chrome. (Saving it as Text, HTML Folder etc don’t work similarly).

When I follow the same procedure using the website:
http://www.htmlescape.net/htmlescape_tool.html
to do the encoding everything works as expected:

I tried this for often-used characters like: & ’ "

Am I misunderstanding the KM action: FILTER VARIABLE with “Encode HTML Entities” ?

Here's my html encode the clipboard macro. Has always worked for me.

10)HTML Encode.kmmacros (2.3 KB)

It works well for me. Please post your macro.
See How to Post/Upload Your Macro to the Forum

MACRO: Encode HTML

Encode HTML.kmmacros (4.9 KB)

I have added stuff to the end of your macro to indicate my problem.

I have sent your last variable to a TXT file and then opened that in Safari.
Displays incorrectly!

(Also displays incorrectly if I write the variable to an HTML Folder and then open the contained html file in Safari.)

Encode HTML-1.kmmacros (6.5 KB)

How does that fail? If I run your macro, it displays:

Which looks encoded correctly.

If I change it to write and open .html, it displays:

How is this different to what you are expecting?

The subtlety was that I had saved the variable as plain text with a .txt file extension (see my KM macro).
When this gets opened it shows up wrong (with the encodings).
It should have been given the .html extension. Thanks.

1 Like

Glad you solved it! It’s always SOMETHING…