Page 1 of 1

Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 12:11 am
by JAB Creations
I'm not exactly sure what the terminology is though how would I go about implementing a code parser for code within a BB code tag similar to how the forums with phpBB here display the code (including various languages such as HTML, CSS, JavaScript, PHP, and MySQL)?

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 5:12 am
by Ollie Saunders
Use a library. Don't write this yourself.

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 6:51 am
by jackpf
I wrote this myself :P

I just use a ton of regex.

My forum uses it for code parsing between

Code: Select all

tags. However, if the user puts

Code: Select all

I just use PHP's native highlight_string() function, since it obviously highlights code better than I can...

However, it doesn't differentiate between languages. It just has a load of common features of most languages, and highlights them. It's mainly based on C style languages.

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 6:53 am
by juma929
Hello,

Just curious as to why you couldnt approach writing this yourself? (Ollie)

:?

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 7:09 am
by Eran
He's not saying you can't, he's saying you shouldn't. It's a waste of time, as it's just a lot of dirty work, and there are plenty of good libraries to take of it. Unless you enjoy those kind of things.

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 11:18 am
by JAB Creations
The first word of the thread's title is existing. :wink: Writing my own BB code to XHTML validator and converter is one thing...styling code markup for five languages is surely quite another! 8O

I did some searching and was unable to figure out how to find any...so that is why I'm asking for some direction as far as finding and comparing existing solutions please?

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 11:24 am
by VladSun

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 11:45 am
by Eran

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 1:21 pm
by Weirdan
Also GeSHi. And our own d11wtq wrote syntax highlighter in JS: Kodify

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 2:34 pm
by Ollie Saunders
pytrin wrote:He's not saying you can't, he's saying you shouldn't. It's a waste of time, as it's just a lot of dirty work, and there are plenty of good libraries to take of it. Unless you enjoy those kind of things.
Yeah, that's right.
The first word of the thread's title is existing.
Didn't see that.

Re: Existing parser for formating code for forums?

Posted: Fri Aug 21, 2009 3:22 pm
by JAB Creations
Thanks a lot guys! I'm checking them out right now! :)

Jack, you wrote your own? Do you have a link available or is it simply implemented in to your site? I'm more liberal with regex in JavaScript then in PHP for obvious reasons.

Speaking of JavaScript I plan on writing my BB code validator in JavaScript too in order to compliment the serverside version and naturally to reduce page requests (just add the function to form validation pretty much). Chris's solution sounds intriguing, I like the idea of highlighted curly brackets on mouseover!

Performance is only one concern...project activity such as addressing bugs and being open to improvements interests me. I might end up going in and adjust some of the code to implement things like bracket highlighting. I'm not really interested in any other languages other then PHP and MySQL (and naturally XHTML, CSS, and JavaScript). Clientside implementation (the BB code tags) is another thing I'll be looking at. In example are people more likely to use {code=html} or {html}? I typically use {html} myself in example. I'm sure for the most part it wouldn't be too difficult to change that in most of these existing solutions.