Gossamer Forum
Home : Products : Gossamer Forum : Discussion :

FR: Advanced CODE tag

Quote Reply
FR: Advanced CODE tag
Hi

I've seen on a few forums, mainly VBulletin that the CODE tag actually highlights various functions in your code.

I think this would be a really funky addition to this forum, too. It could automaticaly highlight code like EditPlus does to make it easier for perl,php .. code to be read and understood.

Code:
sub make_coffee {

# it's time for coffee

push(@coffee,$milk);

for $kettle {
sleep until $boil;
}

...
}

What do you reckon?

- wil
Quote Reply
Re: [Wil] FR: Advanced CODE tag In reply to
Sure... We could just build vim right into the forum. Then we could put it into the template editor, and.... Wink



Seriously, it's a cool idea, but it sounds like quite a bit of work - maybe for GForum 2.0.0 or perhaps 3.0.0.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [jagerman] FR: Advanced CODE tag In reply to
Would this be do-able as a plugin?

If so I may have a go as I've been playing with a perl script to do the same.

It may do as a temporary solution until you create something better?
Quote Reply
Re: [RedRum] FR: Advanced CODE tag In reply to
We've got a vim syntax file which is mainly regular expressions. Although it would be possible, I expect it would be quite CPU intensive. However, if you want to give it a try, by all means go ahead. Let me know if you get stuck.

Jason Rhinelander
Gossamer Threads
jason@gossamer-threads.com
Quote Reply
Re: [jagerman] FR: Advanced CODE tag In reply to
I think it could look cool, though. It should probably be reserved for people who know what they're doing. ie, keep the current [CODE] tag and add maybe another [CODE ADV] tag that does all the colouring, so people don't exhaust it.

- wil
Quote Reply
Re: [RedRum] FR: Advanced CODE tag In reply to
It could definately be done as a plugin. Add a hook to 'convert_markup' that looks something like:

Code:
sub advanced_convert {
my $text = shift;
$$text =~ s,\[adv\](.*?)\[/adv\],highlight_perl($1),g;
return $text;
}

sub highlight_perl {
my $perl = shift;
... add regexes here to highlight perl code.
return $perl;
}


Let me know how it goes..

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] FR: Advanced CODE tag In reply to
Cool. Good thing you mentioned the hook as I was about to ask which one to use :)

I'll keep you updated on my progress....
Quote Reply
Re: [Alex] FR: Advanced CODE tag In reply to
Ok I've run into problems.

Firstly the wizard adds my @args = @_; into the module but your example showed that the argument was a scalar reference.

To debug I tried printing $$text but I get:

Can't use an undefined value as a SCALAR reference

Any thoughts?

Last edited by:

RedRum: Feb 12, 2002, 1:12 PM
Quote Reply
Re: [Alex] FR: Advanced CODE tag In reply to
Sorry just ignore me. I used a POST instead of PRE hook.
Quote Reply
Re: [Alex] FR: Advanced CODE tag In reply to
This is looking like it could get complicated :)
Quote Reply
Re: [RedRum] FR: Advanced CODE tag In reply to
Parsing perl you mean? Or the plugin itself? You may want to see if there is a perl syntax highlighter on CPAN, and use that instead.

Cheers,

Alex
--
Gossamer Threads Inc.
Post deleted by Wil In reply to

Last edited by:

Wil: Feb 13, 2002, 1:40 AM
Quote Reply
Re: [Alex] FR: Advanced CODE tag In reply to
I meant parsing the perl.

I have all the functions and such from the EditPlus perl syntax file but parsing it is a bit trickier :)

I'll take a look at CPAN thanks.
Quote Reply
Re: [RedRum] FR: Advanced CODE tag In reply to
Aha! Look at this little beauty. Exactly what we need - it even adds line numbers for you! There's an online demo too where you can upload your Perl files and see the output. Good stuff!

http://www.palfrader.org/code2html/

- wil
Quote Reply
Re: [Wil] FR: Advanced CODE tag In reply to
code2html is =amazing=! I've fallen in love already. No need for it as I'm using Vim but it is amazing! Could definitily be written into this forum?

- wil
Quote Reply
Re: [Alex] FR: Advanced CODE tag In reply to
I've finished the plugin and it seems to work really nicely.

All thats left to do is sort out the colors to make it look a little prettier.

http://213.106.15.150/...post_view&post=4

Last edited by:

RedRum: Feb 13, 2002, 3:34 AM
Quote Reply
Re: [RedRum] FR: Advanced CODE tag In reply to
That link doesn't work for me. The tag [preety] doesn't get parsed. Can you change the tag name to [perl] just to be really fussy :-). Good job...

- wil
Quote Reply
Re: [RedRum] FR: Advanced CODE tag In reply to
If anyone goes to the demo and finds it doesn't work, don't worry, it's just because I have to uninstall the plugin to make changes.

I am just going to make the colors and the tags user options and then it should be ready.