View Single Post
Old 06-16-2009, 03:15 PM   #1 (permalink)
Wildhoney
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Application Go Prettifying Pasted Code on TalkPHP

You may notice that when you post code, you can wrap it in a few BBCodes. Mostly we use [code], [php] and [highlight], as described below.

Some people, however, don't wrap their code in any BBCodes at all, which ends up looking messy, and likely to immediately deter people from reading your code, thus replies will be scarce.

Option 1: [code]

At the very least we should be using this BBCode because at least it preserves white-space, tabbing being the most important. However, when using this BBCode, there is no colour highlighting and so whilst it's acceptable, it's not perfect.

This really should be limited to code that is in a language that is unsupported by any other of our BBCodes. Pseudo code, for instance.

Option 2: [php]

As this is a PHP forum, if you hadn't noticed, I imagine most people will want to use this tag. It is the most popular, and will get the job done nicely. It has all the advantages of the aforementioned BBCode, but with the added nicety of PHP syntax highlighting.

This, whilst more than fine, is not quite as advanced as the last of the BBCode tags, but when it comes to PHP highlighting, this or the subsequent will be more than appreciated.

One thing though, please do not use this tag for non-PHP code, as the highlighting will likely resemble that of a firework in a paint pot.

Option 3: [highlight]

This BBCode is something I added to TalkPHP because it allows for much more advanced syntax highlighting. I use this for PHP as well because I find it looks nicer than the antecedent BBCode, but each to their own.

The highlight BBCode uses Geshi syntax highlighting, which supports a wide-range of programming languages. To specify the language you wish to place in between the BBCode tags, you can do the following. For example, if you wish to show PHP:

[highlight=php]/* PHP code */[/highlight]

Albeit this is not a comprehensive list of supported languages, but the ones that are most common on TalkPHP:
  • highlight=php (PHP)
  • highlight=javascript (JavaScript)
  • highlight=html4strict (HTML)
  • highlight=css (CSS)
  • highlight=xml (XML)
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.

Last edited by Wildhoney : 06-25-2009 at 07:49 PM.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote