2016-10-04, 06:39 AM
So we took awhile trying to figure out how to get a working syntax highlighter on mybb 1.8.7. There are some that are available, but none provided python syntax and/or worked with 1.8.7.
There was only one syntax highlighter that already have a working python syntax, and that was
https://mods.mybb.com/view/mybb-syntax-highlighter-v1-1
However that mod is using SyntaxHighlighter 3.x which has some problems escaping single quotes properly, and more. So to convert it to 4.x we had to download the latest syntaxhighlighter from their github
https://github.com/syntaxhighlighter/syntaxhighlighter
However there is no mod to just install when you update to the newer version
we then replaced all the previous mod's code with that newer version
Then we added a new BBCode from ACP MyCode wiht reg expression as
We then installed myinsertbuttons mod to allow an easy button on the sceditor to push (optional)
The next problem was that the codebox's were adding <br> tags within the codebox...which took us awhile to figure out a solution for
class_parser.php -> create this new function before class postParser line
then replace this line
Then you will have a syntax highlighted codebox that could in theory do any of the languages provided.
After that youll have this
[attachment=37552]
Its using syntax highlighter version 4.x so there is no problem escaping characters. And its running in mybb 1.8.7. All the original langauges work.
There is still a problem where copying code from it to advanced editor does not work (quick editor does though)...but i think we can fix that, and will update post.
There was only one syntax highlighter that already have a working python syntax, and that was
https://mods.mybb.com/view/mybb-syntax-highlighter-v1-1
However that mod is using SyntaxHighlighter 3.x which has some problems escaping single quotes properly, and more. So to convert it to 4.x we had to download the latest syntaxhighlighter from their github
https://github.com/syntaxhighlighter/syntaxhighlighter
However there is no mod to just install when you update to the newer version
we then replaced all the previous mod's code with that newer version
Then we added a new BBCode from ACP MyCode wiht reg expression as
\[python\](.*?)\[/python\]
and replacement as<pre class="brush: python">$1</pre>
We then installed myinsertbuttons mod to allow an easy button on the sceditor to push (optional)
The next problem was that the codebox's were adding <br> tags within the codebox...which took us awhile to figure out a solution for
class_parser.php -> create this new function before class postParser line
function my2_nl2br($string){
$string = str_replace("\n", "<br />", $string);
if(preg_match_all('/\<pre class="brush: python"\>(.*?)\<\/pre\>/', $string, $match)){
foreach($match as $a){
foreach($a as $b){
$string = str_replace('<pre class="brush: python">'.$b.'</pre>','<pre class="brush: python">'.str_replace("<br />", "\n", $b)."</pre>", $string);
}
}
}
return $string;
}
then replace this line
$message = nl2br($message);
with this line$message = my2_nl2br($message);
within the same file. Then you will have a syntax highlighted codebox that could in theory do any of the languages provided.
After that youll have this
[attachment=37552]
Its using syntax highlighter version 4.x so there is no problem escaping characters. And its running in mybb 1.8.7. All the original langauges work.
There is still a problem where copying code from it to advanced editor does not work (quick editor does though)...but i think we can fix that, and will update post.