It's too dang hard to monkify my code before I post, so I built a system that I'd like to see here so every one can benifit from the time savings.

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 += '&#091;'; } else if ( node_doctext.value.charAt( i ) == ']' ) { monkified += '&#093;'; } else if ( node_doctext.value.charAt( i ) == '<' ) { monkified += '&lt;'; } else if ( node_doctext.value.charAt( i ) == '>' ) { monkified += '&gt;'; } 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>

And if vroom doesn't add it, you can take it and benifit if you like.
--
Casey

Replies are listed 'Best First'.
RE: Monkifying posts is too rough (solution, not rant :)
by vroom (His Eminence) on Jun 15, 2000 at 17:47 UTC
      I guess it's not. I'll chalk that up to a lack of brain cells, but it was fun to write that code anyhow. It was fun while it lasted. Enjoy!
      --
      Casey
      
RE: Monkifying posts is too rough (solution, not rant :)
by cwest (Friar) on Jun 14, 2000 at 04:33 UTC
    I seem to have mis guessed the monks parser with the example that I gave, but feel free to type your own in. ( that's why you see some 'interesting' Perl code there ;-)
    --
    Casey
    
RE: Monkifying posts is too rough (solution, not rant :)
by Aighearach (Initiate) on Jun 15, 2000 at 00:09 UTC
    I would just like to point out that using apache mod_perl, trips to the server are cheap. And there is at least _one_ Monk that surfs without JavaScript: me.

    I love the idea, though, it should be added as a standard feature for us not-with-multimedia-revolution types.

    "Just the Data, please."

    Paris Sinclair    |    4a75737420416e6f74686572
    pariss@efn.org    |    205065726c204861636b6572
    I wear my Geek Code on my finger.
    
RE: Monkifying posts is too rough (solution, not rant :)
by mcwee (Pilgrim) on Jun 15, 2000 at 00:24 UTC
    Something (the Javascript, I assume) has broken my ability to vote on the posts to this node while browsing using Netscape under Win95. Damn shame, too.

    Wait, I can vote using IE. It's a wierd, wonderful world children

    Hold up, I take that back-- I can't vote using IE, either (although it LOOKS like I can vote. How Microsofty.)

    The Autonomic Pilot; it's FunkyTown, babe.

RE: Monkifying posts is too rough (solution, not rant :)
by merlyn (Sage) on Jun 17, 2000 at 02:31 UTC
    I think it's a bad UI decision to usurp both angle brackets and square brackets. Why not let angle brackets do double duty:
    This is a link to <link to="merlyn">. --- like [merlyn] This is a link to <link to="merlyn" text="merlyn's home page"> --- l +ike [merlyn|merlyn's home page]
    I really hate having to remember to type special chars for brackets.

    -- Randal L. Schwartz, Perl hacker

      Uhoh - you propose a change down in the guts of the Everything engine :). While it would surely be the Right Thing, I guess that won't happen, because many things in the Everything engine are hardcoded to use [ and ] for evaluation. I also think that non-HTML-knowing people find it easier to put a link into square brackets instead of learning HTML syntax (though it would maybe be a good thing to force HTML syntax unto the people :)).

      I think you will be welcome to submit patches to the engine that parse <LINK ...> tags in a special way, but I don't see that square-bracket-linking will go away soon ...

RE: Monkifying posts is too rough (solution, not rant :)
by Jonathan (Curate) on Jun 14, 2000 at 17:51 UTC
    JavaScript? Who let that in? :-)

    Hang your head in shame...
      Do you prefer something like this? I don't care really, just as long as it get's easier to post... this is a programmatic situation, and can be handled programmaticaly.
      my $text = q{
      I like to <tt><monkify>smile ;-></monkify></tt>
      <br>
      some code:
      <pre><monkify>
      my $value = [ qw/one two/ ];
      print $value->[1];
      </monkify></pre>
      };
      
      sub fix {
        my $text = shift;
      
        my $good = {
                    '[' => '&#091;',
                    ']' => '&#093;',
                    '<' => '&lt;',
                    '>' => '&gt;',
                   };
        my $bad  = join '', map { "\\$_" } keys %{$good};
      
        $text =~ s/([$bad])/$good->{$1}/g;
      
        return $text;
      
      }
      
      $text =~ s/<monkify>(.+?)<\/monkify>/fix($1)/ges;
      
      print $text;
      
      PS: I hope I got this post right for the parser ;-)
      --
      Casey
      
RE: Monkifying posts is too rough (solution, not rant :)
by btrott (Parson) on Jun 14, 2000 at 04:37 UTC
    This is quite clever.

    Unfortunately, the node parsing code has also destroyed some of your Javascript; it's translated the ] and ^ substitutions into bastardized links. :) But we get the point, anyway.

      I shall never give up! a working version: <FORM> <TEXTAREA name='node_doctext' cols=50 rows=15> I like to smile... <monkify>;-></monkify>
      Here's some code
      <monkify>
      my $value = [ qw/hey there/ ];
      print $value->[1];
      </monkify>
      </TEXTAREA>

      <SCRIPT LANGUAGE="JavaScript"> </SCRIPT> <INPUT Type=Button VALUE="Monkify" OnClick="monkify(this.form.node_doctext);return true;"> </FORM>

      --
      Casey
      
        Well... I lost that battle, I'm sure you all get the idea, and understand the functional improvement thereof.
        --
        Casey