diogoscf / github-lines

A minimal and non-intrusive multi-platform bot to display lines from GitHub (or GitLab) links
MIT License
60 stars 10 forks source link

Properly map file extensions to language aliases for Discord syntax highlighting #49

Open birdybro opened 8 months ago

birdybro commented 8 months ago

Hello!

We love your bot in the MiSTer FPGA discord. I have noticed a possible issue recently. Case statements in vhdl do not apparently get syntax highlighting

https://github.com/MiSTer-devel/GBA_MiSTer/blob/master/rtl/gba_sound.vhd#L422-L425

https://github.com/MiSTer-devel/GBA_MiSTer/blob/master/rtl/gba_sound_ch1.vhd#L265-L271

It looks like the vhdl markdown tag doesn't get applied for some reason. I made sure to test that it wasn't the linter/parser (which I assumed might be shared between this project and discord).

image

Thank you!

diogoscf commented 8 months ago

Lovely to know you like the bot!

As for the issue, what's happening is that what is passed to discord as the language for formatting is just the file extension (so vhd instead of vhdl in your case), which so far had always worked for all languages I'd tested (e.g. py for Python or cpp for C++) - but apparently not all!

I figured this issue could pop up when I first made the bot a few years ago, but it never did, so I never bothered to do the syntax highlighting properly. Unfortunately nowadays I am completely out of time, so I have no idea when I'll be able to get to this (naturally help is welcome if you can!).

As a starting point for the fix, discord appears to use highlight.js, with a list of available languages and corresponding aliases available here. As for mapping file extensions to the language, the list used for github syntax highlighting could be useful.