Existing parser for formating code for forums?
Moderator: General Moderators
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Existing parser for formating code for forums?
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)?
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Existing parser for formating code for forums?
Use a library. Don't write this yourself.
Re: Existing parser for formating code for forums?
I wrote this myself 
I just use a ton of regex.
My forum uses it for code parsing between
I just use a ton of regex.
My forum uses it for code parsing between
Code: Select all
tags. However, if the user putsCode: 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?
Hello,
Just curious as to why you couldnt approach writing this yourself? (Ollie)

Just curious as to why you couldnt approach writing this yourself? (Ollie)
Re: Existing parser for formating code for forums?
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.
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Existing parser for formating code for forums?
The first word of the thread's title is existing.
Writing my own BB code to XHTML validator and converter is one thing...styling code markup for five languages is surely quite another!
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?
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?
http://marijn.haverbeke.nl/codemirror/c ... index.html looks very interesting
There are 10 types of people in this world, those who understand binary and those who don't
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Re: Existing parser for formating code for forums?
Yeah, that's right.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.
Didn't see that.The first word of the thread's title is existing.
- JAB Creations
- DevNet Resident
- Posts: 2341
- Joined: Thu Jan 13, 2005 6:44 pm
- Location: Sarasota Florida
- Contact:
Re: Existing parser for formating code for forums?
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.
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.