Use better color scheme for syntax highlighting

Hello!

I wonder how difficult it would be to add a proper syntax highlighting for GDScript on the forum.

For example if I add some code here (shamelessly yonked from this thread):

extends RigidBody2D

@export var _move_speed: float = 620
var player_state

func _ready():
    pass

func _enter_tree():
    set_multiplayer_authority(name.to_int())

func _physics_process(delta):
    _move_speed = 620
    move(delta)
    set_player_state()
    pass

func move(delta: float) -> void:
    var _direction: Vector2 = Vector2(
        Input.get_action_strength("move_right") - Input.get_action_strength("move_left"),
        Input.get_action_strength("move_down") - Input.get_action_strength("move_up")
    )

    if _direction != Vector2.ZERO:
        apply_central_impulse(_direction.normalized() * _move_speed * delta)
        
    if Input.is_action_pressed('ability'):
        player_border.texture = border_spritesheet['ability']
        apply_central_impulse(Vector2(_direction.normalized()) * dash_power)

func set_player_state():
    player_state = {"T": Time.get_unix_time_from_system(), "V": linear_velocity, "P": global_position}
    Server.SendPlayerState(player_state)
    pass

It doesn’t do a very good job at highlighting it at the moment.

At least the underlying parsing should already be correct, we use highlight.js with a GDScript plugin. We should probably look for a different color scheme though. Currently some keywords are only boldened which makes them look like the rest of the code.

Would be nice to have the same color scheme as the default one in the Godot Editor. I’ll add it to the to-do list :slight_smile:

Note that highlight.js wasn’t updated for Godot 4.0’s GDScript syntax to my knowledge, so it has no awareness of annotations and new/removed keywords.

I suppose it should be updated upstream in a manner that keeps it compatible with GDScript from Godot 3.x and 4.x at the same time (likely by keeping the removed keywords in the list of valid keywords).

GitHub issues for reference:

There’s also another alternative to highlight.js, which is PrismJS, I think it looks nice. Screenshot of prismjs in action:

image

Discourse uses Highlightjs, it would be a hassle to integrate a second one. So we only add the GDScript plugin to what Discourse already has.

Last commit was 3 years ago though.

Yes, but we can update it. It’s still less hassle than integrating a completely different highlighter since it is really tightly integrated into Discourse