News:

SMF 2.1.4 has been released! Take it for a spin! Read more.

Main Menu

Custom Colors For Programming Languages

Started by tgmg, September 10, 2014, 09:18:55 PM

Previous topic - Next topic

tgmg

Hello

I'm starting a programming forum, I want to customize the code shown between the code tags, you know:


/* Example */
for (i = 0; i < 10; i += 1)
   printf("Hello\n");


But I want to show keywords in different colors, something like this:


Any help would be appreciated, thanks!

mashby

This is a nice light gray:
#ccc
I think what you're asking for is what a program like Notepad++ does. If you are doing a programming forum and want to use the code tag to do the coloring that Notepad++ does or even Dreamweaver does, I think you might be overthinking this. Do you expect your users to use your site to write code? I'm hoping you aren't really wanting to do that. That's not really the purpose of a forum.
Always be a little kinder than necessary.
- James M. Barrie

tgmg

Most programming forum has this feature, I would like to implement it for my forum, here you can see a screenshot taken from a programming forum:


mashby

I guess I'm having an issue with "most programming forum has this feature". What is the forum software of most of those sites? Certainly, SMF doesn't do this out of the box. That's not to say it cannot be done, but posting code in a forum using the code function here certainly doesn't so what your screen shot is doing which is also from 5 years ago.
Always be a little kinder than necessary.
- James M. Barrie

tgmg

Quote from: mashby on September 10, 2014, 10:37:00 PM
What is the forum software of most of those sites?

Custom made.

Quote from: mashby on September 10, 2014, 10:37:00 PM
Certainly, SMF doesn't do this out of the box.

I already know this  ::)

Quote from: mashby on September 10, 2014, 10:37:00 PM
That's not to say it cannot be done, but posting code in a forum using the code function here certainly doesn't so what your screen shot is doing which is also from 5 years ago.

5 years ago? the message in the screenshot was posted only two days ago, but please,  let's try to keep on topic.

I just need to know at least which files I have to modify in order to change the colors of the text shown inside the code tags.

mashby

Ah yeah. OK. I saw the October 2009 in the poster area.

Custom made? Are all of these sites that you speak of on this custom made forum software?

I'm not against what you're saying, but to me code is done/edited in code editing software. Forum software isn't that. I personally use Notepad++ for code and sometimes Dreamweaver. I don't go to a forum to see code in what I call code view. I think Sources/Subs.php has some of the parts you are looking for, but it only formats the beginning and the end of code. This is the start in that file:
array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),
// !!! Maybe this can be simplified?
Always be a little kinder than necessary.
- James M. Barrie

tgmg

Thanks! at least now I'm looking at the right place of the code  :)


tgmg

Quote from: Nibogo on September 10, 2014, 11:59:43 PM
Integrating a library like hxxp:craig.is/making/rainbows [nonactive] or hxxp:alexgorbatchev.com/SyntaxHighlighter/manual/installation.html [nonactive] shouldn't be that hard.

That's exactly what I was looking for, thanks!


Nibogo

That mod should be enough; however, I am not sure, but I think I can remember something bad about GeShi, I cannot tell if it's security or performance, but as far as I can remember something was wrong with it, I maybe wrong too.

tgmg


tgmg

Quote from: Nibogo on September 11, 2014, 07:47:37 AM
That mod should be enough; however, I am not sure, but I think I can remember something bad about GeShi, I cannot tell if it's security or performance, but as far as I can remember something was wrong with it, I maybe wrong too.

Installed the mod, it works quite well, but now I'm a little bit worried about your comment, so far everything looks fine.


Deaks

could use the php tag ...


Using the code mashby posted about it would look like this:
	
	
	
array(
	
	
	
	
'tag' => 'code',
	
	
	
	
'type' => 'unparsed_content',
	
	
	
	
'content' => '<div class="codeheader">' $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' ''),
	
	
	
	
// !!! Maybe this can be simplified?

[php] array(
'tag' => 'code',
'type' => 'unparsed_content',
'content' => '<div class="codeheader">' . $txt['code'] . ': <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">' . $txt['code_select'] . '</a></div>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '<pre style="margin: 0; padding: 0;">' : '') . '<code class="bbc_code">$1</code>' . ($context['browser']['is_gecko'] || $context['browser']['is_opera'] ? '</pre>' : ''),
// !!! Maybe this can be simplified?
[/php]
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

tgmg

The code inside the php tags doesn't look really nice, besides, for my forum I need C/C++ and the very rare scripting language GML, all of them already supported by GeShi... man this mod is amazing, it looks so well made, solid as a rock  ;)

Deaks

i just used what mashby posted but php tags dont actually need to show php ive used it to show xml and css :)
~~~~
Former SMF Project Manager
Former SMF Customizer

"For as lang as hunner o us is in life, in nae wey
will we thole the Soothron tae owergang us. In truth it isna for glory, or wealth, or
honours that we fecht, but for freedom alane, that nae honest cheil gies up but wi life
itsel."

Advertisement: