I'm using CodeIgniter, alongside the highlight_code("$string");
(More info) function to provide syntax highlighting to a dynamic site. I want the users to be able to submit their own posts written in a BBCode-style format. I'm using NBBC PHP library for this.
My problem is that nomatter how I do it I cannot get NBBC to syntax-highlight only [code][/code]
tags that my users enter. Here's the PHP for [code]:
'code' => Array(
'mode' => BBCODE_MODE_ENHANCED,
'template' => "
<div class=\"bbcode_code\">
<p>Code:</p>
<code><?php $highlight_code(\"?>{\$_content/v}<?php \");?></code>
</div>
",
'class' => 'code',
'allow_in' => Array('listitem', 'block', 'columns'),
'content' => BBCODE_VERBATIM,
'before_tag' => "sns",
'after_tag' => "sn",
'before_endtag' => "sn",
'after_endtag' => "sns",
'plain_start' => "<div id=\"footer\">",
'plain_end' => "</div>",
'simple_start' => '
<div class=\"bbcode_code\">
<p>Code:</p>
<code>',
'simple_end' => '</code>
</div>
',
),
If you see the line which says <?php $highlight_code(\"?>{\$_content/v}<?php \");?>
that I whacked in there, I thought that would highlight the code contained within the tags. I can't quite remember what this outputs (I've tried plenty of different combinations) but the closest I got was it being exported as text from PHP - in my page XHTML source it just appeared as text.
What can I do to make all content within tags on a page be syntax-highlighted, ideally using highlight_code($string); or similar?
I was thinking preg_replace
would be an option but I don't know how to do it to dynamically replace everything between outputted tags (not [code], remember, but HTML which NBBC outputs).