Syntax highlightning on the forums

Developed or developing a new product in PureBasic? Tell the world about it.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Syntax highlightning on the forums

Post by Fred »

Hello everyone,

After seeing the greasemonkey script of Stargate, I looked for a native phpbb version and found a plugin to activate syntax highlightning when posting. I activated it and if you like it I will let it on. To use it, instead of using the [ code ][ /code ] tags, use [ code-pb ][ /code-pb ].

Example:

Code: Select all

If OpenWindow(0, 100, 200, 300, 200, "2D Drawing Test")

  ; Create an offscreen image, with a green circle in it.
  ; It will be displayed later
  ;
  If CreateImage(0, 300, 200)
    If StartDrawing(ImageOutput(0))
      Circle(100,100,50,RGB(0,0,255))  ; a nice blue circle...

      Box(150,20,20,20, RGB(0,255,0))  ; and a green box
      
      FrontColor(RGB(255,0,0)) ; Finally, red lines..
      For k=0 To 20
        LineXY(10,10+k*8,200, 0)
      Next
      
      DrawingMode(#PB_2DDrawing_Transparent)
      BackColor(RGB(0,155,155)) ; Change the text back and front colour
      FrontColor(RGB(255,255,255))
      DrawText(10,50,"Hello, this is a test")

      StopDrawing()
    EndIf
  EndIf

  ; Create a gadget to display our nice image
  ;
  ImageGadget(0, 0, 0, 0, 0, ImageID(0))
  
  ;
  ; This is the 'event loop'. All the user actions are processed here.
  ; It's very easy to understand: when an action occurs, the Event
  ; isn't 0 and we just have to see what have happened...
  ;
  
  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow  ; If the user has pressed on the window close button
  
EndIf

End   ; All the opened windows are closed automatically by PureBasic
There is also a 'copy' button to copy the whole code directly to the clipboard
deathmx
User
User
Posts: 27
Joined: Mon Feb 26, 2018 3:14 am

Re: Syntax highlightning on the forums

Post by deathmx »

feels good is this the color style you typically use?
Marc56us
Addict
Addict
Posts: 1477
Joined: Sat Feb 08, 2014 3:26 pm

Re: Syntax highlightning on the forums

Post by Marc56us »

I like it :D

There is a parameter to adjust I think, because when you are connected, the system displays 10 lines of codes and a scroll bar (which is good) but when you are not connected, it displays the whole code, which can take a lot of space.

:wink:
User avatar
STARGÅTE
Addict
Addict
Posts: 2067
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: Syntax highlightning on the forums

Post by STARGÅTE »

I would prefer a client-based highlighting to allow a customization by the user (reader) not a server-based highlighting by the forum or author.
You also generate a lot more traffic, in the style is added on server side.

Edit: Ignore it, I just saw, it is also JS based.

In my case it doesn't matter, I will overwrite this style with my script in any case.
But I like it for guest users here in the forum. However one can discuss about the colors :lol:

But, is it possible to enable/disable this server-based highlighting in the user-preferences?
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: Syntax highlightning on the forums

Post by Keya »

The syntax highlighting looks pretty good to me, but I just wish the code box was longer to show more lines of code!
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Syntax highlightning on the forums

Post by BarryG »

Keya wrote: Fri May 28, 2021 9:46 ami just wish the code box was longer to show more lines of code!
Agreed. I liked the old forum where we could see all the code at once without having to scroll a text box.
Axolotl
Enthusiast
Enthusiast
Posts: 435
Joined: Wed Dec 31, 2008 3:36 pm

Re: Syntax highlightning on the forums

Post by Axolotl »

Regardless of the colors chosen, it looks cool. I like the COPY button (top right).
Mostly running PureBasic <latest stable version and current alpha/beta> (x64) on Windows 11 Home
User_Russian
Addict
Addict
Posts: 1443
Joined: Wed Nov 12, 2008 5:01 pm
Location: Russia

Re: Syntax highlightning on the forums

Post by User_Russian »

Great, but I'm used to default color scheme in the IDE.

Image
User avatar
StarBootics
Addict
Addict
Posts: 984
Joined: Sun Jul 07, 2013 11:35 am
Location: Canada

Re: Syntax highlightning on the forums

Post by StarBootics »

Fred wrote: Fri May 28, 2021 8:49 am There is also a 'copy' button to copy the whole code directly to the clipboard
@Fred : I don't know if you notice this but the copy button and the scroll bar are overlapping each other. Maybe moving the button to the right ?

Beside that I love it.

Best regards
StarBootics
The Stone Age did not end due to a shortage of stones !
User avatar
Tenaja
Addict
Addict
Posts: 1948
Joined: Tue Nov 09, 2010 10:15 pm

Re: Syntax highlightning on the forums

Post by Tenaja »

BarryG wrote: Fri May 28, 2021 10:26 am
Keya wrote: Fri May 28, 2021 9:46 ami just wish the code box was longer to show more lines of code!
Agreed. I liked the old forum where we could see all the code at once without having to scroll a text box.
Funny! We all have our preferences. I'd prefer more lines, but not all lines of long code. I chose my theme to get one that had a shorter code box.
Fred
Administrator
Administrator
Posts: 16619
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: Syntax highlightning on the forums

Post by Fred »

I will try to add an IDE like theme, to see if it fits.
User avatar
skywalk
Addict
Addict
Posts: 3972
Joined: Wed Dec 23, 2009 10:14 pm
Location: Boston, MA

Re: Syntax highlightning on the forums

Post by skywalk »

This is GREAT!
Easy to read without customizing each browser.
Like others said, there is overlap on the buttons.
Please make PB syntax the default.
Plain text should not be default for code blocks.

Code: Select all

UseSQLiteDatabase()
Procedure CheckDatabaseUpdate(Database, Query$)
   Result = DatabaseUpdate(Database, Query$)
   If Result = 0
      Debug DatabaseError()
   EndIf   
   ProcedureReturn Result
EndProcedure
DatabaseFile$ = GetTemporaryDirectory()+"Database.sqlite"
If CreateFile(0, DatabaseFile$)
   CloseFile(0)   
   If OpenDatabase(0, DatabaseFile$, "", "")   
      CheckDatabaseUpdate(0, "CREATE TABLE food (name CHAR(50), weight INT)")
      CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('apple', '10')")
      CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('pear', '5')")
      CheckDatabaseUpdate(0, "INSERT INTO food (name, weight) VALUES ('banana', '20')")      
      If DatabaseQuery(0, "SELECT * FROM food WHERE weight > 7")      
         While NextDatabaseRow(0)
            Debug GetDatabaseString(0, 0)
         Wend      
         FinishDatabaseQuery(0)
      EndIf      
      CloseDatabase(0)
   Else
      Debug "Can't open database !"
   EndIf
Else
   Debug "Can't create the database file !"
EndIf
Last edited by skywalk on Fri Jun 04, 2021 1:21 pm, edited 1 time in total.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Syntax highlightning on the forums

Post by BarryG »

Tenaja wrote: Fri May 28, 2021 1:57 pmWe all have our preferences. I'd prefer more lines, but not all lines of long code.
Very true. I always like to get the big picture, plus it means I can save and print the page with all code showing, which isn't possible when it's inside a text box.
akee
Enthusiast
Enthusiast
Posts: 475
Joined: Wed Aug 18, 2004 9:52 am
Location: Penang, Malaysia

Re: Syntax highlightning on the forums

Post by akee »

Nice!!!
Seymour Clufley
Addict
Addict
Posts: 1233
Joined: Wed Feb 28, 2007 9:13 am
Location: London

Re: Syntax highlightning on the forums

Post by Seymour Clufley »

This is a great idea. But please, please, don't use the default IDE color scheme! LOL
JACK WEBB: "Coding in C is like sculpting a statue using only sandpaper. You can do it, but the result wouldn't be any better. So why bother? Just use the right tools and get the job done."
Post Reply