Better Code Highlighting
Better Code Highlighting
Currently, I've noticed that the only highlighting of code on the forum is that it's put in green text. Could we use some means of syntax-highlighting code inside [code] tags? I understand that it might take a bit of work thanks to different languages - and especially assembly with all its syntax-variants and processor types...
Just a thought.
Cheers
Just a thought.
Cheers
phillid - Newbie-ish operating system developer with a toy OS on the main burner
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: Better Code Highlighting
You'll be getting quite a source of nuisance if you are ever going to try to implement this properly:
(Also, green text? Where? )Forum Rules wrote:6: Please try to write legibly
(...) Usetags when posting code. Use indentation and source comments. Use a spell checker. Don't use colours - not everybody uses the same theme and colouring your text might render it invisible. (...)Code: Select all
Re: Better Code Highlighting
Okay, I see a point there, but that aside, surely highlighted code would be better? Couldn't we put a neutral colour choice like white or black for code block backgrounds and do the highlighting from there?
phillid - Newbie-ish operating system developer with a toy OS on the main burner
Re: Better Code Highlighting
In theory the highlighting colours could be specific to each theme. Not sure what extensions exist and how hard it would be to set up, though.
Re: Better Code Highlighting
I'm not aware of any PHPBB-specific plugins, but a quick Google Search would deal with my ignorance. I've used one or two non-PHPBB-plugins before, and I hear Prettify is supposed to be quite good.
phillid - Newbie-ish operating system developer with a toy OS on the main burner
Re: Better Code Highlighting
You should narrow down the scope and avoid posting long code in the first place.
Code: Select all
If (SLOC() < 10) {
YouDontNeedColor = true;
} else {
TL();DR();
}
- DavidCooper
- Member
- Posts: 1150
- Joined: Wed Oct 27, 2010 4:53 pm
- Location: Scotland
Re: Better Code Highlighting
Combuster wrote:(Also, green text? Where? )
Code: Select all
If (SLOC() < 10) {
YouDontNeedColor = true;
} else {
TL();DR();
}
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
Re: Better Code Highlighting
Correct, but sometimes long-ish code may need to be posted. Plus highlighting would make languages like assembly easier to read for example.bluemoon wrote:You should narrow down the scope and avoid posting long code in the first place.
phillid - Newbie-ish operating system developer with a toy OS on the main burner
-
- Member
- Posts: 2566
- Joined: Sun Jan 14, 2007 9:15 pm
- Libera.chat IRC: miselin
- Location: Sydney, Australia (I come from a land down under!)
- Contact:
Re: Better Code Highlighting
Alas, code in my code tags is white. That is to say, any syntax highlighting solution must integrate nicely with the multiple themes this board supports. But Combuster basically said that already.phillid wrote:Currently, I've noticed that the only highlighting of code on the forum is that it's put in green text.
I also use the theme I do specifically because it's dark, it would be awfully disconcerting to have every code block suddenly became bright white in background (assuming a 'global' scheme was decided upon, irrespective of theme).
Re: Better Code Highlighting
I'm not convinced that syntax highlighting would be useful. It serves a purpose in a code editor, helping to make errors stand out, but that shouldn't be necessary here, assuming the OP has already checked for syntax errors.
Most books don't employ syntax highlighting, and I don't miss it.
Most books don't employ syntax highlighting, and I don't miss it.
Re: Better Code Highlighting
Fair enough. To cater for those who use dark themes, the background colour of a code segment could be dark for a dark theme and light for a light theme. Admittedly, that would cause problems with, say, black parts of code on that dark background of the code segment, but it'd be easy for such text's colour to be changed depending on the theme.pcmattman wrote:it would be awfully disconcerting to have every code block suddenly became bright white in background
Correct, but how does it make errors more apparent? By making it more readable by, for example, making (valid) types of variables stand out better, mathematical operations a different colour from values around the operators, and so on. I believe that it would make the 'consumption' of code much more efficient.iansjack wrote:It serves a purpose in a code editor, helping to make errors stand out...
phillid - Newbie-ish operating system developer with a toy OS on the main burner
- xenos
- Member
- Posts: 1118
- Joined: Thu Aug 11, 2005 11:00 pm
- Libera.chat IRC: xenos1984
- Location: Tartu, Estonia
- Contact:
Re: Better Code Highlighting
I also think that highlighting improves the readability of code, both in an editor and here in the forum or the wiki (where we already have some nice highlighting, and if it works there, why not in the forum as well?). When I read some code in the wiki or elsewhere on the web I'm usually happy when I see immediately what's going on, and the structure becomes clear. Highlighting helps in this scenario.
I'm not 100% familiar with how PHPBB styles work, or how those syntax highlighting plugins work. But if one had a plugin that simply puts some <span class="keyword">...</span> around keywords (and similar for variables, functions, types, asm stuff, strings etc.), and if each style simply comes with a CSS file with all the color definitions, it shouldn't be too hard to come up with, say, one highlighting color scheme for dark styles and one for bright styles, that one could copy into the CSS style definitions.
I'm not 100% familiar with how PHPBB styles work, or how those syntax highlighting plugins work. But if one had a plugin that simply puts some <span class="keyword">...</span> around keywords (and similar for variables, functions, types, asm stuff, strings etc.), and if each style simply comes with a CSS file with all the color definitions, it shouldn't be too hard to come up with, say, one highlighting color scheme for dark styles and one for bright styles, that one could copy into the CSS style definitions.
Re: Better Code Highlighting
Well, it's true that users use different styles, but I think that another special bbcode for code part (as a keyword alone in text or some constant) would be good. It wouldn't be full code highlighting, but it would serve for explaining code. Currently, when somebody adds code to his post and he has some mistake in name of variable or keyword, other refer it using italic text or ``, ' '. On CodeProject, there's special var button for it. I think in administrator control panel of phpBB there are settings for BBcodes.
Re: Better Code Highlighting
That'd be due to the fact that a lot of them are printed primarily in black and white, I guess. Just because they don't use it doesn't mean that it's the best option, especially on a different medium. On the web, it's easier and not at all more expensive (Unless you're going to start talking about a few extra KB of internet usage ) to publish in colour, so why not do it?iansjack wrote:Most books don't employ syntax highlighting
Oh well, you're entitled to your opinion
phillid - Newbie-ish operating system developer with a toy OS on the main burner
Re: Better Code Highlighting
That's very generous of you.phillid wrote:Oh well, you're entitled to your opinion
If such a facility were ever to be implemented then I would hope it would be a user-configurable option. I would find it distracting and I can see it causing all sorts of problem with some browser/display setups. I think here of those nasty versions of xterm that do colour coding and can end up with near-invisible text.