I built a small client side, javascript engine that will work on 3.0 browsers and up. It finds the special characters and converts them to the HTML Elements they deserve to be.
I know what you're thinking, 'I don't want my whole post to be Monkified, just the code and certain smiley faces.".
Taken care of my friends, just put the tags <monkify>and</monkify> around any text that you want 'interpreted'. Pretty neat huh?
I went with JavaScript becuase I figured the less trips to the server the better, especialy for just formating the message. And it's ease to add a new button to the posting sections. Here's a demo:
<FORM> <TEXTAREA name='node_doctext' cols=50 rows=15> I like to smile... <tt><monkify>;-></monkify> <br> Here's some code <pre><monkify> my $value = [ qw/hey there/ ]; print $value->[1]; </monkify></pre> </TEXTAREA> <P> <SCRIPT LANGUAGE="JavaScript"> <!-- // Activate cloak function monkify(node_doctext) { var monkified = ''; var can_monkify = false; for ( i = 0; i < node_doctext.value.length; i++ ) { if ( node_doctext.value.substring( i, i+9 ) == '<monkify +>' ) { can_monkify = true; i += 9; } else if ( node_doctext.value.substring( i, i+10 ) == ' +</monkify>' ) { can_monkify = false; i += 10; } if ( can_monkify ) { if ( node_doctext.value.charAt( i ) == '[' ) { monkified += '['; } else if ( node_doctext.value.charAt( i ) == ']' ) { monkified += ']'; } else if ( node_doctext.value.charAt( i ) == '<' ) { monkified += '<'; } else if ( node_doctext.value.charAt( i ) == '>' ) { monkified += '>'; } else { monkified += node_doctext.value.charAt( i ); } } else { monkified += node_doctext.value.charAt( i ); } } node_doctext.value = monkified; } // monkify() // Deactivate cloak --> </SCRIPT> <INPUT Type=Button VALUE="Monkify" OnClick="monkify(this.form.no +de_doctext);return true;"> </FORM>
-- Casey
|
|---|