-
Syntax highlighting in forum code
Hi,
Perhaps this has come up before, but I feel it may be time to update the syntax highlighting in the code here in the forum, don't you think?
I mean the [HIGHLIGHT=vb.net]code...[/HIGHLIGHT] or [HIGHLIGHT=csharp]test[/HIGHLIGHT] tags specifically.
Their syntax highlighting seems rather arbitrary and doesn't match the default VS syntax highlighting at all. Would it be possible to change this?
Or would it be too much work? I can't really imagine that, there must be some kind of code you can simply edit to change the colors... What I see wrong specifically is that many keywords are colored in some kind of orange color. It shouldn't be too hard to make them blue? Also, every member (basically every word that follows a period ".") is turned blue, which is not the case in VS. Oh and strings are gray for some reason.
There are also a few keywords that aren't recognized but that's not really a big problem. So basically all that needs to change is the colors... That shouldn't be more than 10 seconds work if you got access to the syntax highlighting code I think?
-
Re: Syntax highlighting in forum code
To add on to this, whenever you do use the [Highligh] tags, could the line numbers be outside of the code div? I dont use highlight yet because the line numbers get highlighted when you copy&paste.
-
Re: Syntax highlighting in forum code
Quote:
Originally Posted by
JuggaloBrotha
To add on to this, whenever you do use the [Highligh] tags, could the line numbers be outside of the code div? I dont use highlight yet because the line numbers get highlighted when you copy&paste.
You can just quote someone's post and you can then copy/paste the code without linenumbers from the quoted text.:) But yes, that would be a good change too!
-
Re: Syntax highlighting in forum code
Sorry folks, but we had to do considerable searching even to find the highlighter that we have. It's the only one out there, and it needed to be modified just to work with this version. I'm afraid we probably can't devote more man-hours to it.
The line numbering can be turned on or off, that's the only option that exists for numbers.
-
Re: Syntax highlighting in forum code
That's too bad... Though I can't imagine it taking more than a few minutes, all you'd really need to do is change two or three colors... I could be wrong of course. Is the code for it publicly available, can I see it, or is it private?
-
Re: Syntax highlighting in forum code
It would take you more than a few minutes just to track down the CSS entry for a particular class of words. They're not really labeled in any way that makes sense, or makes them easy to find. It's called the GeSHi - Generic Syntax Highlighter. You can download it for free I believe.
-
Re: Syntax highlighting in forum code
Quote:
Originally Posted by
NickThissen
I mean the [HIGHLIGHT=vb.net]code...[/HIGHLIGHT] or [HIGHLIGHT=csharp]test[/HIGHLIGHT] tags specifically.
Their syntax highlighting seems rather arbitrary and doesn't match the default VS syntax highlighting at all.
It doesn't? I didn't notice the difference. Why does it matter anyway?
-
Re: Syntax highlighting in forum code
You don't see the difference?
vb.net Code:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If Not m_Updating Then
Dim g As Graphics = e.Graphics
Dim y As Integer = 2
For Each n As TreeListNode In Me.Nodes
DrawRecursive(g, n, y, 0)
Next
If Me.Nodes.Count > 0 Then g.DrawLine(Pens.Black, 0, y, Me.Width, y)
g.DrawRectangle(Pens.Black, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
MyBase.OnPaint(e)
End If
End Sub
http://i47.tinypic.com/rhirgz.png
They're not even remotely the same. Some keywords aren't recognized, others are orange while they should be blue, and all members are blue while they shouldn't be... Why does it matter? Why have syntax highlighting at all if it doesn't match the colors most people use? I don't see the point then.
-
Re: Syntax highlighting in forum code
I think the only reason that the highlight was created was to make the code easier to read on the forums in comparison with the normal black forum text.
-
Re: Syntax highlighting in forum code
I agree that it would be better to have the same colours/keywords as the language it is representing - but changing it is clearly a very low priority item (it works as it is), so it is unlikely to occur unless it is very minimal work for JPnyc etc.
You have been given the name of the product, so you should be able to find it and work out what needs to be changed. If you can make the necessary changes to the files, JPnyc may be able to find the time to apply them.
-
Re: Syntax highlighting in forum code
True, if you can make the change to the necessary CSS file, I can get it uploaded.
-
Re: Syntax highlighting in forum code
Quote:
Originally Posted by
NickThissen
...Why have syntax highlighting at all if it doesn't match the colors most people use? I don't see the point then.
Exactly why I personally use ordinary [CODE] tags instead - no highlighting, no aggravation... :)
-
1 Attachment(s)
Re: Syntax highlighting in forum code
I've taken a quick look, and the colors seem to be defined in the 'vb.php' file found in the 'geshi/geshi' folder. I've edited this file so all keywords are blue and the string color matches, and I've added one or two keywords that sprung to mind (Inherits and End), but I've got no idea how to test it...
I've attached the php file. Is it possible for you forum admins to replace the file and test the result?
I doubt it will be a perfect match but, if it works, I'm sure it will be much more accurate than the current colors. If it looks good I could take a look at the csharp file too.
This literally took me 1 minute, 90% of which was taking a screenshot of the VB options window to determine the exact colors, and I know nothing about PHP :p
-
Re: Syntax highlighting in forum code
That's the wrong file. That's for Visual Basic, not VB.net
-
1 Attachment(s)
Re: Syntax highlighting in forum code
D'oh! Didn't notice there was also a vbnet.php file.
Try this one then.
-
Re: Syntax highlighting in forum code
okay, I'll get it uploaded
-
Re: Syntax highlighting in forum code
okay it's up there. Go ahead and test. Thanks
-
Re: Syntax highlighting in forum code
Cool, looks much better already. There's still a few things wrong. If I find some time to fix them (probably tonight) can I PM you the updated file?
-
Re: Syntax highlighting in forum code
If it's absolutely necessary, for the last time though. I have to bother one of the system administrators every time we need something uploaded.
-
Re: Syntax highlighting in forum code
In that case nevermind, it's fine the way it is now :)
Thanks for taking your time to upload it!
-
Re: Syntax highlighting in forum code
Can I just chime in on this one. While VB.Net is fine other languages present issues. If you look at most of the highlighters they simply search for keywords with is really only partial highlighting. I have the regex for both Xaml/XML and C# but I would imagine the burden of creating them in a php equiv would be a large annoyance!
-
Re: Syntax highlighting in forum code
True. I was thinking about having the forum's syntax highlighter use the new VS2010 colors; where types (except the basic types such as String, Integer, etc) are colored in a turquoise ("Teal" I think) color. I quickly remember though that these syntax highlighters don't actually interpret the code at all, they just look for keywords and things like comment characters and quotes. In order for the highlighter to color the types in Teal, it would have to do at least basic parsing to pick up on user-defined types. Furthermore, it would have to have a list of all types (such as the most common ones like Button, TextBox, but all other types in the framework too!). And even worse, the code may be using user-defined types that aren't even in the posted code, so I quickly dropped that idea.
-
Re: Syntax highlighting in forum code
Actually you wouldn't need to have any of that, you simply need to understand the lexical structure of the language you are trying to highlight. I say simple but this in itself is a mammoth task, it is something I have posted code on before.
If you have a look at the Xaml highlighter in the WPF forum (which I made) it highlights with about 98% accuracy and does so without one list. As Xaml is a well defined language its lexical structure was pretty easy to figure out, it highlights custom types too!
VB wouldn't be too hard either since its well formed. C based languages are typically harder due to a very flexible lexical structure but it can be done! When I get the time I intend on releasing a .net lexical analysis engine that will deliver a list of "parts" that can be easily read by a parser, its just not on my top things to get done list :)
-
Re: Syntax highlighting in forum code
Let's see..
vb.net Code:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
If Not m_Updating Then
Dim g As Graphics = e.Graphics
Dim y As Integer = 2
For Each n As TreeListNode In Me.Nodes
DrawRecursive(g, n, y, 0)
Next
If Me.Nodes.Count > 0 Then g.DrawLine(Pens.Black, 0, y, Me.Width, y)
g.DrawRectangle(Pens.Black, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
MyBase.OnPaint(e)
End If
End Sub
Hmmm ... I just copied Nick's code from post #8.
Looks rather similar to his code frag in that post,
as opposed to the image
Am I missing something?
Spoo
-
Re: Syntax highlighting in forum code
Yes, it seems it's been changed back :/ It was working fine as far as I can see, dunno why they took it off again..
-
Re: Syntax highlighting in forum code
It seems that the changes introduced problems, so they were rolled back:
http://www.vbforums.com/showthread.php?t=618059
-
Re: Syntax highlighting in forum code
I see. I never saw the problem (and obviously can't see it anymore now that the syntax highlighting is rolled back), so what was going on? The 'File' keyword there is still a link for me... Or was it supposed to be?
-
Re: Syntax highlighting in forum code
It wasn't showing properly before... I can't quite remember what it was like, but it was blatantly heavily flawed; I think it added several "random" characters, and the link didn't work either.
-
Re: Syntax highlighting in forum code
It was adding this:
3 => 'http://www.google.com/search?q={FNAMEU}+site:msdn.microsoft.com',
-
Re: Syntax highlighting in forum code
Hmf... Strange. Perhaps the current version of the highlighter this forum is using is not the latest version that I downloaded from their site, so they could have changed some stuff... If you could send me the version the forum is using right now I could edit that and send it back... But I understand if you don't want to 'risk' it anymore :p
-
Re: Syntax highlighting in forum code
Man ... seems like I stirred up a hornet's nest.
Sorry .. :)