New Syntax Highlighting in Forums and Journals

Published April 21, 2011
Advertisement
We've introduced an old favorite for syntax highlighting code in our forums and journals. In addition to the standard [ code ] tags that exist now, we have introduced a tag that we used to use readily in past versions of GameDev.net. The "new" bbcode tag that is available for use is the [ source ] tag.

The source tag requires an attribute specifying what language you want to use. Available language options are:


Language Tag Argument

ActionScript3 as3, actionscript3
Bash/shell bash, shell
ColdFusion cf, coldfusion
C# c-sharp, csharp
C++ cpp, c
CSS css
Delphi delphi, pas, pascal
Diff diff, patch
Erlang erl, erlang
Groovy groovy
JavaScript js, jscript, javascript
Java java
JavaFX jfx, javafx
Lua lua
Perl perl, pl
PHP php
Plain Text plain, text
PowerShell ps, powershell
Python py, python
Ruby rails, ror, ruby
Scala scala
SQL sql
Visual Basic vb, vbnet
XML xml, xhtml, xslt, html, xhtml


[size="4"]Before:

[ source lang="csharp"] <-- remove space before 'source'

[color="#000000"]using System;
using System.IO;

class Test {
private static void Main() {
for (int i = 0; i < 5000; i++) {
using (TextWriter w = File.CreateText("C:\\tmp\\test\\log" + i + ".txt")) {
string msg = DateTime.Now + ", " + i;
w.WriteLine(msg);
Console.Out.WriteLine(msg);
}
}
Console.In.ReadLine();
}
}

[/color][ /source ]


[size="4"]After:

[source lang="csharp"][color="#000000"]
using System;
using System.IO;

class Test {
private static void Main() {
for (int i = 0; i < 5000; i++) {
using (TextWriter w = File.CreateText("C:\\tmp\\test\\log" + i + ".txt")) {
string msg = DateTime.Now + ", " + i;
w.WriteLine(msg);
Console.Out.WriteLine(msg);
}
}
Console.In.ReadLine();
}
}

[/color][/source]
9 likes 10 comments

Comments

rip-off
Very nice.
April 22, 2011 02:00 PM
swiftcoder
That is very slick. Nice to have it mesh well with the various blogging platforms as well.
April 22, 2011 11:15 PM
Gaiiden
FYI there are some small issues using it with articles thanks to the fact that they parse HTML by default but we'll work to get those resolved so that we can use this there as well for some of the larger blocks of code listings
April 23, 2011 01:13 AM
TomKQT
That's nice, but unfortunatelly it didn't fix the source code in old posts (the forum shows them on one long line and it's impossible to read it, making this forum very hard to use when you're doing what you are supposed to do - search first, ask only when you don't find the answer).
April 23, 2011 09:20 AM
JTippetts
Awesome. :D
Any chance of adding Lua to the list?
April 23, 2011 11:47 AM
Michael Tanczos
We can add any brush really, as long as it's compatible with the highlighter here: http://alexgorbatchev.com/SyntaxHighlighter

Contributions are always appreciated as well.
April 23, 2011 01:25 PM
rip-off
Despite having a scroll bar, it doesn't actually seem to have a useful limit on the amount of code you can paste in.

I created this just now: http://www.gamedev.net/topic/600192-c-templates-and-skill-bar/page__view__findpost__p__4801947

The source code is reasonably long and the scroll bar is useless as the source isn't constrained to a particular maximum height. Tried on Firefox 4 and Chrome.
April 23, 2011 02:15 PM
Michael Tanczos
[quote name='rip-off' timestamp='1303568136']
Despite having a scroll bar, it doesn't actually seem to have a useful limit on the amount of code you can paste in.

I created this just now: [url="http://www.gamedev.net/topic/600192-c-templates-and-skill-bar/page__view__findpost__p__4801947"]http://www.gamedev.n...ost__p__4801947[/url]

The source code is reasonably long and the scroll bar is useless as the source isn't constrained to a particular maximum height. Tried on Firefox 4 and Chrome.
[/quote]


I added a max-height attribute to constrain it like the other version does.
April 25, 2011 01:25 AM
rip-off
Thanks!
April 26, 2011 09:06 AM
tom_mai78101
When will the [source] tag replace the [code] tag?
April 28, 2011 09:04 PM
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Advertisement