Page 1 of 4

Syntax highlightning on the forums

Posted: Fri May 28, 2021 8:49 am
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

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 8:57 am
by deathmx
feels good is this the color style you typically use?

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 9:06 am
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:

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 9:12 am
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?

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 9:46 am
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!

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 10:26 am
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.

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 10:28 am
by Axolotl
Regardless of the colors chosen, it looks cool. I like the COPY button (top right).

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 10:49 am
by User_Russian
Great, but I'm used to default color scheme in the IDE.

Image

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 12:51 pm
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

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 1:57 pm
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.

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 2:01 pm
by Fred
I will try to add an IDE like theme, to see if it fits.

Re: Syntax highlightning on the forums

Posted: Fri May 28, 2021 2:11 pm
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

Re: Syntax highlightning on the forums

Posted: Sat May 29, 2021 1:08 am
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.

Re: Syntax highlightning on the forums

Posted: Sat May 29, 2021 8:40 am
by akee
Nice!!!

Re: Syntax highlightning on the forums

Posted: Wed Jun 02, 2021 12:40 am
by Seymour Clufley
This is a great idea. But please, please, don't use the default IDE color scheme! LOL