• Welcome to Simple Machines Community Forum. Please login or sign up.

C++ syntax highlighting for SMF 2.0.2?

Started by xibalba, May 22, 2012, 06:47:13 PM

Previous topic - Next topic


May 22, 2012, 06:47:13 PM Last Edit: May 23, 2012, 08:53:54 PM by xibalba
http://whalesdev.com/forums/index.php?topic=1227.msg22156#msg22156 [nofollow]

I want like C++ syntax highlighting added to the code BBC tag.  Does such a mod exist?  I read a little bit about this geisha thing, and it looks like you can't add it to a mod due to restrictive licensing on their part, so is there anything else?

SMF version 2.0.2


Well, [code] looks for <?php mixed in with the content, and calls a special function to highlight such sections of the content. [php] apparently just assumes everything is PHP, and calls the same "highlight" function. In order to do C++ (or any other language, for that matter), you'd have to have something like [code=cpp] or just [cpp] and model the code on the [php] processing. How much more complicated it would get for C++, and/or how incomplete it currently is for PHP, I can't tell you. The PHP highlighting function looks very simplistic at first glance. I haven't tried to understand it in detail.

If I were going to attempt this, I would change [code] to act like [code=lang], with a default language of "php". PHP would look for <?php sections and pass them off to the function to process for [php]. While we're at it, how about passing off non-PHP sections to an HTML highlight function? For all other languages, simply pass off the entire block of code to the same function used by the processing function for  [lang]. The [code] routine would know the escapes for all the languages it supports -- should HTML be assumed for anything outside of the escaped sections? Maybe a whole list of languages, each with their own highlighting, could be given: [code=php,html,javascript,css]?

Anyway, implementing a framework for this (and implementing a robust PHP processor) would make a nice project for someone. Hey, maybe we could encourage universities to assign these as student projects/thesis projects and incorporate the results into SMF? Anyone have an "in" with any good CompSci departments?