Pretty Code module

Posted by cgardner 
Pretty Code module
December 15, 2006 05:50PM
I got bored the other day and decided to write a module that makes the
 tags prettier.

See it in action: [goodpacket.com]

Here it is in all of it's glory.

Hope it helps someone.



Edited 5 time(s). Last edit at 01/12/2007 06:31PM by cgardner.
Attachments:
open | download - pretty_code_20070112.zip (1.9 KB)
Re: Pretty Code module
December 16, 2006 03:39AM
so thats essentially a php-code highlighter?
I don't think its a general "pretty code" mod as there are quite some other kinds of code ;).


Thomas Seifert
Re: Pretty Code module
December 17, 2006 08:53PM
I can't run it under php/4.4.4 (doesn't support htmlspecialchars_decode() ).
Is there a way to run it under 4.4.4 version of php?



Edited 1 time(s). Last edit at 12/17/2006 08:54PM by Rec-Sec.
Re: Pretty Code module
December 19, 2006 05:53AM
It doesn't work with this: [www.phorum.org]

I need that for the inbodyattachments module, otherwise it wouldn't scale
Re: Pretty Code module
December 20, 2006 12:49PM
Yes, it will highlight the code for PHP only, but there is absolutely no reason you wouldn't be able to use it for other languages or just for fun.

I made some updates, but unfortunately I don't have any PHP4 servers that I can test with...
Attachments:
open | download - pretty_code_2006122001.zip (2.5 KB)
Re: Pretty Code module
December 21, 2006 03:22PM
ok, I'll try it and tell yo how it goes..
Re: Pretty Code module
December 21, 2006 05:52PM
Works perfect, thanks alot. :)

Maybe you could add a fix for links in comments, which get posted with their whole phorum code, in <a> tags etc.



Edited 1 time(s). Last edit at 12/21/2006 06:02PM by Hiiri.
Re: Pretty Code module
January 03, 2007 06:08AM
Quote
cgardner
Yes, it will highlight the code for PHP only, but there is absolutely no reason you wouldn't be able to use it for other languages or just for fun.

One problem with that, is that any other preformatted text will be PHP code highlighted as well. For example ASCII art or HTML code (see the examples I posted on the URL you mentioned above).

I think it might be a better idea to introduce a special [php] tag, which can be used for PHP coloring the code contained within that tag. I see two advantages for that:

1) The users can still create preformatted text using
 without the highlighting;

2) There will be no module ordering problems with the bbcode mod, which implements the 
 tag as well (which is probably the problem that Hiiri is running into).


Maurice Makaay Phorum Development Team my blog linkedin profile secret sauce
Re: Pretty Code module
January 12, 2007 06:14PM
Quote
mmakaay
I think it might be a better idea to introduce a special [php] tag, which can be used for PHP coloring the code contained within that tag.

I took your advice and got rid of the formatting, but I'm still noticing what Hiiri mentioned. Any URLs that are posted within the code tags are truncated and formatted according to the bbcode bare URL formatter.

I've played with the bbcode module a bit to try to make it exclude any URLs that are in code tags, but have been unsuccessful so far. If you modify the bbcode module to disable bare url formatting by commenting out the following line it works, but any other URLs that you may want formatted are not formatted.
// convert bare urls into bbcode tags as best we can
// the haystack has to have a space in front of it for the preg to work.
$body = preg_replace("/([^='\"([url\]|[img\])])((http|https|ftp):\/\/[a-z0-9;\/\?:@=\&\$\-_\.\+!*'\(\),~%#]+)/i", "$1:$rnd:$2:/$rnd:", " $body");

I also uploaded the newest version of the formatter.



Edited 1 time(s). Last edit at 01/12/2007 06:16PM by cgardner.
Sorry, only registered users may post in this forum.

Click here to login