views:

99

answers:

1

Some online websites like to encode all their text through HTML entities, so instead of seeing a text like

So I'm looking

You get something like:

So I'm looking 

I was wondering if there's a built in way to translate the encoded text to regular text using any Emacs built-ins or if I should declare my map of strings ("&83" => "S"...) and manually decode it using a map.

Any pointers would be greatly appreciated.

+1  A: 

Don't know if there is a built in function, but this small function can do the job:

(defun my-insert-encode-entities-string (str)
  (mapconcat
   (lambda (char) (format "&#%d;" char))
   (string-to-list str)
   ""))

If you only wish to encode HTML entities, use url-insert-entities-in-string instead.

Török Gábor
The function is wrong since you don't want to format as %d, you want to get a %d and format it as a char.
Federico Builes
@Federico: I'm not sure if I can see your point. Calling `(my-insert-encode-entities-string "So I'm looking")` returns exactly the same result you provided. Variable `char` holds the current character represented as a integer so in this particular case I think it's no matter whether using `%s` or `%d`.
Török Gábor
@Török: There was a little misunderstanding, as you can see in the question I was looking for "...a built in way to translate the encoded text to regular text". Your solution converts regular to encoded text :)I wrote this http://gist.github.com/222709 to fix it but it's obviously not as clean as your original proposal.
Federico Builes