tips and tricks for movable type

decoder from scriptygoddess
September 20, 2002

I've been meaning to blog this for a while: the ScriptyGoddess DeCoder bookmarklet - nifty for converting "<" and ">" into "&lt;" and "&gt;" when writing HTML code into my Tips entries so it displays properly.

Update 09.22.02: I wanted to also convert " to &quot;, so, since I don't know how to actually make a bookmarklet (sigh), I just edited the properties on the DeCoder link in my toolbar.

This is the new stuff I pasted in:

javascript:void(strSelection=document.selection.createRange().text);void(strSelection=strSelection.replace(new RegExp('<','g'),'&lt;'));void(strSelection=strSelection.replace(new RegExp('>','g'),'&gt;'));void(strSelection=strSelection.replace(new RegExp('\"','g'),'&quot;'));void(document.selection.createRange().text=strSelection);

In case it isn't clear - that's a \ followed by a double quote, then a single quote.

Oh hell, I couldn't stop there, could I? Let's convert those & to &amp; too:

javascript:void(strSelection=document.selection.createRange().text);void(strSelection=strSelection.replace(new RegExp('&','g'),'&amp;'));void(strSelection=strSelection.replace(new RegExp('<','g'),'&lt;'));void(strSelection=strSelection.replace(new RegExp('>','g'),'&gt;'));void(strSelection=strSelection.replace(new RegExp('\"','g'),'&quot;'));void(document.selection.createRange().text=strSelection);

You have to put the & to &amp; conversion first, otherwise, once the remaining characters get converted, their &s get converted too.

Comments

hey,

I was wondering if you can do a code conversion for me. Hopefully you know perl.
I have this code:

and i want that converted to work in perl
is there any chance you can help me or know a place i can go to get it converted?

Thanks for your help.

by EC | 12.19.03 11:16 AM

oops apperntly I cant post code:

"
function cleanCAPS(str) {
capsallowed = 3; // Lowercase if more than ## CAPS in a row
do {
eval("re = /([A-Z]{" + (capsallowed+1) + ",})/g;");
myArray = str.match(re);
if (myArray) {
eval("re = /" + myArray[0] + "/;");
str = str.replace(re, ""+myArray[0].toLowerCase());
}
} while (myArray);
return str;
"
hope this time it goes thru.

by EC | 12.19.03 11:18 AM

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

TrackBack: 3
(URL: http://www.thegirliematters.com/sf/mt-track.cgi/84)

» Writing code in entries
Excerpt: If u want to write code in entries or in ordinary webpages u have to convert "<" and ">" into
Weblog: [ S K A I H I G H ]
Tracked: 03.29.03 05:40 AM

» How do I post html inside an entry?
Excerpt: cliche -------------------------------------------------------------------------------- How do I post html inside an entry without having it mess up the blog itself. I want...
Weblog: General Site Info
Tracked: 04.17.03 05:36 PM

» code in entries
Excerpt: In order to display MT code in entries (or extended entries) without MT executing that code, it looks like most people are using &lt; and &gt; tags in place of "". I noticed, though, that you have to type "and...
Weblog: Design MT
Tracked: 11.04.03 01:48 AM