Code decoder…

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 Says:

    Nifty!!!!

    Very very nifty.

    <testing>

    GREAT job, Jenn!!!! :)

  2. kristine Says:

    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 Says:

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

  4. girlie Says:

    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 Says:

    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 Says:

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

  7. Sara Says:

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

  8. Joel "Jaykul" Bennett Says:

    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 Says:

    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 Says:

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

  11. 99 shades of grey Says:
    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 Says:

    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 :(

  13. Jennifer Says:

    Arvind - see this post

  14. Arvind Says:

    Oh thanks Jennifer, didn’t see that !

  15. BytchInNY Says:

    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 Says:

    [...] 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 Says:

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