scriptygoddess

04 Jun, 2002

Code decoder…

Posted by: Jennifer In: Scripts

We post code here a lot on scriptygoddess… and if you haven't already noticed, if you don't replace your "<" and your ">" with "&lt;" and "&gt;" you break the page.

Well, they say that necessity is the mother of invention… so I guess that means that LAZINESS is the mother of programming. :)

Here's a script AND A (beta) BOOKMARKLET that will do all that for you :)

First the bookmarklet… As I said before… this is BETA. Use it at your own risk. (heh. Everything on this site is use it at your own risk, but you knew that already). (please note: I'm pretty sure this won't work with netscape ever, but maybe 6.2 will accept it…) You drag it to your links bar, then select some text, and it should replace those characters. If you crash, or get an error, email me and give me as much specfics as you can.

Bookmarklet (beta) ===> email me

function deCode() {
strSelection = document.selection.createRange().text
strSelection = strSelection.replace(new RegExp("<","g"), "&lt;");
strSelection = strSelection.replace(new RegExp(">","g"), "&gt;");
document.selection.createRange().text = strSelection;
return;
}

17 Responses to "Code decoder…"

1 | Lynda

June 4th, 2002 at 9:01 am

Avatar

Nifty!!!!

Very very nifty.

<testing>

GREAT job, Jenn!!!! :)

2 | kristine

June 4th, 2002 at 9:25 am

Avatar

OOOohhhh, you rock! This could be so handy when I feel like typing a huge entry with tons of <html> in it! 😉 Thank you thank you!!! :)

3 | Simply Sara

June 8th, 2002 at 9:07 am

Avatar

This is wonderful! :) Thank you, have a great weekend~

4 | girlie

September 22nd, 2002 at 3:29 pm

Avatar

I also wanted to convert " to &quot;, so I inserted this into the bookmarklet:

void(strSelection=strSelection.replace(new RegExp('\"','g'),'&quot;'));

It's hard to tell here, but that's a \ followed by a double quote, and a single quote. =)

5 | iki

March 18th, 2003 at 1:44 pm

Avatar

Tales from Extreme Newbie Land:

Oh my Goddess, I'm a moron. It took me an hour to figure out I was supposed to highlight the code before clicking that DeCoder button.

And reminded me why I keep thinking the URL button when posting doesn't work.

Duh!

Thanks for the decoder! I want to put bits of code into my blog so I can remember how I did something later on, and you've just made that possible. Thank you for contributing to my MT education. :)

6 | alex

August 5th, 2003 at 2:27 pm

Avatar

This is IE only right? You can get selection in Mozilla using selectionStart and selectionEnd.

7 | Sara

November 25th, 2003 at 2:21 pm

Avatar

Is there any way to have a bookmark for this in Mozilla/Netscape?

8 | Joel "Jaykul" Bennett

December 3rd, 2003 at 5:39 pm

Avatar

So yeah, I have a Windows-only cross-application version of this: http://www.huddledmasses.org/2003/12/3/converting-to-entities-on-the-fly/

It works in any application, but because it's a .wsf file, it only works in Windows. Thought some of you might like it anyway.

9 | Mark

December 7th, 2003 at 6:51 pm

Avatar

I have a working version of this bookmarklet for Mozilla. Here is the link to the hack.
http:⁄⁄dinki.mine.nu⁄word⁄index.php?p=68&more=1&c=1

10 | Mark

December 8th, 2003 at 6:50 pm

Avatar

Somehow the link above does not work, so here it again.
Bookmarklet for Mozilla

11 | 99 shades of grey

August 18th, 2004 at 7:31 pm

Avatar

Customising Quicktags II
A quick update to the Quicktag customisation : I just incorporated Scriptygoddess' decodeIt function, which neatly translates ' into '&gt;'. The original version of the function was IE-friendly only, however an update sees it working quite happ…

12 | Arvind

August 20th, 2004 at 7:27 am

Avatar

Hey this doesn't work in Firefox, is it possible you could whip up some code that will work with Firefox ? I've thrown Alex's quicktags into MT but want this decode thing too but it only works in IE atm :(

14 | Arvind

August 20th, 2004 at 8:21 am

Avatar

Oh thanks Jennifer, didn't see that !

15 | BytchInNY

October 31st, 2004 at 9:32 pm

Avatar

I just want to say this is fabulous! I grequently post code for suture reference and this will make my life soooo much easier. Thx for sharing.

16 | scriptygoddess » Decoder Button

December 23rd, 2006 at 8:57 pm

Avatar

[…] Had to create a plugin. Guess this means I'm getting back in the groove. ;P Referring back to these posts, this plugin will make a button on your edit post/page making it possible to paste some code you wanted to show, select the code, then click "decode" – which will convert your < to &lt; and > to &gt; in the selection – so that it doesn't break your page. […]

17 | scriptygoddess » Mozilla and IE decoder

December 23rd, 2006 at 9:16 pm

Avatar

[…] Recent Comments Code decoder…: […]

Featured Sponsors

Genesis Framework for WordPress

Advertise Here


  • Scott: Just moved changed the site URL as WP's installed in a subfolder. Cookie clearance worked for me. Thanks!
  • Stephen Lareau: Hi great blog thanks. Just thought I would add that it helps to put target = like this:1-800-555-1212 and
  • Cord Blomquist: Jennifer, you may want to check out tp2wp.com, a new service my company just launched that converts TypePad and Movable Type export files into WordPre

About


Advertisements