Code Highlighting for Mantis
Posted: 27 Mar 2007, 10:10
Google released a nice javascript to highlight code in webpages. http://code.google.com/p/google-code-prettify/
I integrated it into mantis.
You only need the following changes:
in core/html_api.php:
Line ~258:
# --------------------
# (8) Begin the <body> section
function html_body_begin() {
echo '<body onload=prettyPrint()>', "\n";
}
and in bug_view_page.php
Line: ~53
<?php html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) ) ?>
<script type="text/javascript" src="pretty/prettify.js"></script>
<?php html_page_top2() ?>
You also need to copy the prettify.js (from the google link above) in a /pretty folder under your mantis installation and you need to add the contents of the prettify.css to your mantis css file (I bet there's a cleaner way to do that, ideas welcome!)
As a last step, I decided to change the .js file so that it highlights all kinds of code and not only those in a code class=prettyprint because you cannot add those tags into mantis.
So check prettify.cs line ~1381 and change this:
if (cs.className && cs.className.indexOf('prettyprint') >= 0) {
into
if (true) {
and in line ~1386:
if ((p.tagName == 'pre' || p.tagName == 'code' ||
p.tagName == 'xmp') &&
p.className && p.className.indexOf('prettyprint') >= 0) {
into
if ((p.tagName == 'pre' || p.tagName == 'code' ||
p.tagName == 'xmp')) {
From now on, whenever you add code to your mantis posts with the <code> tag, it'll highlight them.
If you got any questions, ask away!
I integrated it into mantis.
You only need the following changes:
in core/html_api.php:
Line ~258:
# --------------------
# (8) Begin the <body> section
function html_body_begin() {
echo '<body onload=prettyPrint()>', "\n";
}
and in bug_view_page.php
Line: ~53
<?php html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) ) ?>
<script type="text/javascript" src="pretty/prettify.js"></script>
<?php html_page_top2() ?>
You also need to copy the prettify.js (from the google link above) in a /pretty folder under your mantis installation and you need to add the contents of the prettify.css to your mantis css file (I bet there's a cleaner way to do that, ideas welcome!)
As a last step, I decided to change the .js file so that it highlights all kinds of code and not only those in a code class=prettyprint because you cannot add those tags into mantis.
So check prettify.cs line ~1381 and change this:
if (cs.className && cs.className.indexOf('prettyprint') >= 0) {
into
if (true) {
and in line ~1386:
if ((p.tagName == 'pre' || p.tagName == 'code' ||
p.tagName == 'xmp') &&
p.className && p.className.indexOf('prettyprint') >= 0) {
into
if ((p.tagName == 'pre' || p.tagName == 'code' ||
p.tagName == 'xmp')) {
From now on, whenever you add code to your mantis posts with the <code> tag, it'll highlight them.
If you got any questions, ask away!