Results 1 to 31 of 31

Thread: Syntax highlighting in forum code

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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?

  2. #2
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  3. #3

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Syntax highlighting in forum code

    Quote Originally Posted by JuggaloBrotha View Post
    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!

  4. #4
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    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.

  5. #5

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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?

  6. #6
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    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.

  7. #7
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Syntax highlighting in forum code

    Quote Originally Posted by NickThissen View Post
    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?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  8. #8

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    Re: Syntax highlighting in forum code

    You don't see the difference?
    vb.net Code:
    1. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    2.         If Not m_Updating Then
    3.             Dim g As Graphics = e.Graphics
    4.             Dim y As Integer = 2
    5.             For Each n As TreeListNode In Me.Nodes
    6.                 DrawRecursive(g, n, y, 0)
    7.             Next
    8.             If Me.Nodes.Count > 0 Then g.DrawLine(Pens.Black, 0, y, Me.Width, y)
    9.             g.DrawRectangle(Pens.Black, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
    10.             MyBase.OnPaint(e)
    11.         End If
    12.     End Sub


    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.

  9. #9
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    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.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  11. #11
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Syntax highlighting in forum code

    True, if you can make the change to the necessary CSS file, I can get it uploaded.

  12. #12
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Syntax highlighting in forum code

    Quote Originally Posted by NickThissen View Post
    ...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...

  13. #13

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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
    Attached Files Attached Files

  14. #14
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Syntax highlighting in forum code

    That's the wrong file. That's for Visual Basic, not VB.net

  15. #15

  16. #16
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Syntax highlighting in forum code

    okay, I'll get it uploaded

  17. #17
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Syntax highlighting in forum code

    okay it's up there. Go ahead and test. Thanks

  18. #18

  19. #19
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    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.

  20. #20

  21. #21
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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!

  22. #22

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  23. #23
    Frenzied Member
    Join Date
    Jul 2008
    Location
    Rep of Ireland
    Posts
    1,380

    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

  24. #24
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Syntax highlighting in forum code

    Let's see..

    vb.net Code:
    1. Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    2.         If Not m_Updating Then
    3.             Dim g As Graphics = e.Graphics
    4.             Dim y As Integer = 2
    5.             For Each n As TreeListNode In Me.Nodes
    6.                 DrawRecursive(g, n, y, 0)
    7.             Next
    8.             If Me.Nodes.Count > 0 Then g.DrawLine(Pens.Black, 0, y, Me.Width, y)
    9.             g.DrawRectangle(Pens.Black, New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
    10.             MyBase.OnPaint(e)
    11.         End If
    12.     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

  25. #25

  26. #26
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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

  27. #27

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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?

  28. #28
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    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.

  29. #29
    PowerPoster JPnyc's Avatar
    Join Date
    Oct 2002
    Location
    Manhattan
    Posts
    3,015

    Re: Syntax highlighting in forum code

    It was adding this:

    3 => 'http://www.google.com/search?q={FNAMEU}+site:msdn.microsoft.com',

  30. #30

    Thread Starter
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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

  31. #31
    PowerPoster Spoo's Avatar
    Join Date
    Nov 2008
    Location
    Right Coast
    Posts
    2,656

    Re: Syntax highlighting in forum code

    Man ... seems like I stirred up a hornet's nest.

    Sorry ..

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width