oisyn at September 13th, 2005 03:45 — #1
it seems the new interface doesn't have a code syntax highlighter, and it does weird things to the code as well (like converting multiple tabs to "* " or something). I made my own highlighter, it's a PHP module with a function that takes the piece of code, the language and a line number bias as parameters, and colorcodes it accordingly. It can highlight C, C++, Delphi, Java, VB, VB.Net, C# and PHP code. It's written using C, C++ and flex.
You can try it here: http://www.oisyn.nl/tests/hl.php
Don't know how extendable vBulletin is, but maybe you can use it? It's open source btw.
dk2 at September 13th, 2005 10:29 — #2
Actually, there's already a php syntax highlighter that was written for the previous forums. So we'll just have code re-use But thanks for the sharing your syntax highlighter.
oisyn at September 14th, 2005 05:13 — #3
No offense, but I didn't really like the old highlighter also . It does weird thing to multiple tabs (converting two tabs to two spaces, while a single tab remains a single tab, it really fucks up the indenting in your code). And there were more issues I can't remember right now...
dk2 at September 14th, 2005 12:36 — #4
I just took a look at your parser and it looks quite good. The only limitation it has is adding support for new langauges or modifying existing ones would require the modification of the lex files and recompiling. I was hoping for something configurable through a config file or something.
However, for the purposes of this forum, it should be sufficient. I think we can use it, but can you provide me with the generated files from flex so that it doesn't have to be installed on the server? Thanks.
oisyn at September 14th, 2005 16:43 — #5
This zipfile also contains the flex'ed files: http://www.oisyn.nl/SyntaxHighlighter.zip From within PHP, either load the module via dl() or put it in your php.ini, and call the function code_highlight(\\$code, \\$lang, \\$line), where \\$code is the piece of code, \\$lang the language ("c", "c++", "c#", "vb", "vb.net", "delphi", "java" or "php") (case insensitive), and \\$line the line where the counting should start (usually 1). The function returns the string as formatted html. The colorcoded pieces are formatted using html span tags with a class attribute, you can control the actual colors using a stylesheet. I've included an example php and css file in the zip.
Let me know if you have any questions or considerations
darqshadow at September 30th, 2005 11:12 — #6
We just implemented a fullly configurable highlighter that works with C, C++, VB, VB.Net, C#, and Delphi and includes a fully configurable XML file to set everything up. I did the custom integration into phpBB myself, and it works great (and even uses the build-in caching system). I have a few Regex fixes to implement, but other than that it's working great. Here's some shots if it in action:
Dia, if you want to take a look at it, just email me.
oisyn at September 30th, 2005 11:16 — #7
Hmm, luckily it doesn't seem to work with the more complex cases to load a script, but it's flawed nevertheless
darqSHADOWYou should definitely use a monospaced font
system at December 7th, 2005 11:40 — #8
monjardin at December 7th, 2005 11:46 — #9
Since this old thread got bumped, I have a somewhat related question.
.oisyn used flex (the GNU libary I assume?) to write his syntax highlighter. Has anyone here had pleasant experiences with boost::spirit?
darqshadow at December 7th, 2005 13:37 — #10
Geshi is a mess. It's a pain to modify the colors (they don't match the IDE's, which is what most people wanted from my system), and the code was a bit bloated for my needs. On top of that, I ran into quite a number of bugs while trying to implement Geshi into phpBB's bbCode -- where-as my highlighter just dropped right now w/o problems.
.oisyn: Yup mono-spaced font was planned, that screenshot was from an initial test run. It is now using a mono-spaced font and it looks beautiful.
eddie at December 7th, 2005 15:18 — #11
At the risk of being the forking point on this hijack, I've used Spirit. It's quite elegant, and makes a great use of operator overloading to do Kleene stars and the like.
I haven't used it for anything more than just playing with it, but I liked it a lot.
oisyn at December 7th, 2005 18:28 — #12
I've looked at spirit, it's a cool gimmic, but a major downside is that it's imho not very readable. I rather use a tool such as ANTLR, in which you can specify your scanner, parser and even an AST parser, as it also builds the AST for you. Both the grammar specification and the generated code are really clean and OO, much unlike bison (haven't tried bison++ though)