#167 accepted
Michael Stillwell

create glow.data.unescapeHTML()

Reported by Michael Stillwell | December 10th, 2009 @ 04:24 PM | in 2.0

There's a glow.data.escapeHTML(), but no analogous glow.data.unescapeHTML().

This would be useful if, for example, your JS source code is US-ASCII (either as policy, or so that the non-breaking space   can be distinguished from the breaking space  ), but you want to output UTF-8.

var suffix = glow.data.unescapeHTML(" …"); // non-breaking space + ellipsis

Comments and changes to this ticket

  • Jake Archibald

    Jake Archibald December 11th, 2009 @ 12:00 PM

    • Tag set to data, enhancement
    • State changed from “new” to “accepted”
    • Milestone set to 2.0

    Good idea. In the mean time:

    var decoded = glow.dom.create('<div></div>').html(encoded).text();
  • Michael Stillwell

    Michael Stillwell May 19th, 2010 @ 03:33 PM

    In case anyone's wondering, Jake's suggestion is faster than you might think (around 10,000/sec on modern hardware).

  • Jake Archibald

    Jake Archibald May 20th, 2010 @ 10:01 AM

    If it's something you do more than once, you can also cache the creation of the div to speed things up...

      var tmpDiv = glow.dom.create('<div></div>');
        function unescapeHtml(encoded) {
            return tmpDiv.html(encoded).text();
  • KushalP

    KushalP June 6th, 2010 @ 10:12 AM

    So couldn't that just be written as:

    function unescapeHTML(encoded) {
        return glow.dom.create('<div></div>').html(encoded).text();

    My only worry is whether or not it should contain the unescaped text in a variable, destroy the created dom element and then return the text.

  • KushalP

    KushalP June 6th, 2010 @ 10:51 AM

    If I was going to add this to the codebase from my Github fork, where's the glow.data object that it would go under stored?

  • Jake Archibald

    Jake Archibald June 7th, 2010 @ 08:36 AM

    Your code example is the 'quick and dirty' way, the same one I posted in the first comment.

    The code in my second comment avoids creating and destroying the temporary div each time the function runs. This temporary div can also be used by other functions, such as escapeHtml. I guess the ideal solution would be to create the temporary div the first time it's needed, meaning it isn't taking up memory on pages that never use it.

    In Glow 2, glow.lang and glow.data have been merged into glow.util


Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A JavaScript Library

Shared Ticket Bins

People watching this ticket