handmade.network » Forums » Site Feedback » Bad code highlighting
rationalcoder
Blake Martin
31 posts
#17127 Bad code highlighting
8 months, 1 week ago Edited by Blake Martin on Jan. 5, 2019, 2:17 p.m. Reason: Initial post

I'm 90% this is old news, but why are code blocks still highlighted incorrectly? I mean, no highlighting would be better than this: https://4coder.handmade.network/b...n_of_4coders_new_lister_api#15817
[email protected]
Ben Visness
29 posts

HMN technical staff, Handmade Math contributor, web developer, etc.

#17128 Bad code highlighting
8 months, 1 week ago

The highlighting in code blocks is done by a Python library called Pygments. If no language is specified in the code tag, Pygments tries to guess which language it is. Sometimes it guesses incorrectly, which is what's happening in that post.

You can always just specify the language by name like so:

1
[code language=c]


You can specify any language from Pygments' list.

The auto-guessing behavior is what the site has had since the beginning, so we kept it when we rolled out the new BBCode parser about four months ago. I know sites like Github don't auto-guess languages in their code blocks, so maybe someday we could turn that feature off.
rationalcoder
Blake Martin
31 posts
#17137 Bad code highlighting
8 months, 1 week ago Edited by Blake Martin on Jan. 6, 2019, 3:19 p.m.

Oh, okay. Thanks! Maybe there could be some sort of tooltip or something similar that could hint at that when people use the code tag?
ratchetfreak
467 posts
#17138 Bad code highlighting
8 months, 1 week ago

or default by adding the language tag. It's a bit more in your face that way.
[email protected]
Ben Visness
29 posts

HMN technical staff, Handmade Math contributor, web developer, etc.

#17154 Bad code highlighting
8 months, 1 week ago

Yeah, adding the language by default seems reasonable. I'll add it to our list and see what the other staff think.
rationalcoder
Blake Martin
31 posts
#17172 Bad code highlighting
8 months, 1 week ago

That's a better idea.