Welcome Guest, Not a member yet? Register   Sign In
How to implement code highlighting features ?
#1

[eluser]mi6crazyheart[/eluser]
Dose any body have any idea, how code highlighting work in this forum editor ? I'm trying to build an environment like this. Every things are working perfect except the code highlighting feature.

Can't understand how to implement it. If any body have any solution plz share with me...
#2

[eluser]WanWizard[/eluser]
I'm using http://qbnz.com/highlighter/ in my forum code...
#3

[eluser]InsiteFX[/eluser]
PHP

PHP highlight_string

InsiteFX
#4

[eluser]mi6crazyheart[/eluser]
[quote author="WanWizard" date="1289789871"]I'm using http://qbnz.com/highlighter/ in my forum code...[/quote]

Hey WanWizard, if i've a text like this(mixture of text & codes as we use in CI forum generally)...
Code:
$text = 'Good morning.<code>echo 'PHP is a great language';</code> Today is a great day';

Then, can GeSHi will able to color codes which present inside "colorTag" & leave rest text as usual as CI forum do.
#5

[eluser]WanWizard[/eluser]
No, geshi is just a highlighter.

You have to create the proper CSS code for geshi to work with, then use some technique ( for example a preg_match() ) to get the code blocks from the text, run the code blocks through gehsi, and reinsert them into the text. Geshi output will contains lots of span's that uses CSS to highlight.

Check the docs on the Gehsi site, they explain everything.
#6

[eluser]mi6crazyheart[/eluser]
@WanWizard
Exactly in this situation(use some technique for example a preg_match() to get the code blocks) i've stuck. I've piece of code for this. But, it's not working properly. Here is that code...
Code:
$parentstring = preg_replace_callback( '#<code>(.*)</code>#', 'mycallback', $parentstring);

function mycallback($matches)
{
   // matches[0] contains the complete pattern: <code>...</code>,
   // matches[1] contains only the contents between the code tags
   // to make sure it goes ok, only highlight the stuff between.
   return '<code>' . highlight_code($matches[1]) . '</code>';
}
#7

[eluser]WanWizard[/eluser]
what's not working properly? your highlight_code() function? The rendering of <code> tags?
#8

[eluser]mi6crazyheart[/eluser]
Actually, it couldn't able to enter to the "mycallback()". May be, some problem with that REGXP...
Code:
#<code>(.*)</code>#
#9

[eluser]WanWizard[/eluser]
I use it to parse BBcode, I use
Code:
$rawmsg = preg_replace_callback('#\[code(=.*?)?\](.*?)([\r\n]*)\[/code\]#si', '_parse_bb_code', $rawmsg);
#10

[eluser]mi6crazyheart[/eluser]
@WanWizard
Wow!!! Man, u'r REGXP just made a magic. Now, every things are working perfect. Thx a lot. It's just make my day...




Theme © iAndrew 2016 - Forum software by © MyBB