View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0007859 | mantisbt | feature | public | 2007-03-28 02:11 | 2017-07-12 05:02 |
Reporter | McWizard | Assigned To | |||
Priority | normal | Severity | feature | Reproducibility | always |
Status | new | Resolution | open | ||
Product Version | 1.0.1 | ||||
Summary | 0007859: Patch: Code Highlighting in Mantis | ||||
Description | 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> sectionfunction html_body_begin() { and in bug_view_page.php <?php html_page_top1( bug_format_summary( $f_bug_id, SUMMARY_CAPTION ) ) ?> 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: and in line ~1386: 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! | ||||
Tags | patch, plugins | ||||
related to | 0004318 | acknowledged | Code tag for bugnotes |
I think that highlight must be done by the server with a tag <code=language></code> by example. |
|
The nice thing about googles JavaScript is that it automagically detects the language the code is in, so the bug reporter does not have to provide that information himself! |
|
The google-code-prettify does not cover a lot of languages (and automatic detection could give strange behavior). Maybe GeSHi http://qbnz.com/highlighter/ could be a good PHP class to do that (a lot of language are supported). |
|
I suppose this is not an ivory-tower solution, but a quick fix to add Code highlighting to mantis while it is not in the official releases. If you choose to add a more sophisticated solution to the next Mantis release, feel free. But since we are using a modified version of mantis anyhow, we were glad to have a simple and quick addon. |
|
This feature has been discussed in the Forum. It has been reported here for the next Mantis release and my comments apply to the next release. If you want to add this feature now, yes the google-code-prettify is a good solution (patch is easy to do). |
|
Thanks McWizard for your contribution. I think it is a good solution until we have one integrated into Mantis. GeSHi was the one I had in mind for this feature. It is also used in DokuWiki. Depending on the size of the library (I didn't check that yet) and the license, we can either include it with Mantis or get a path to it and use it. I haven't researched other server side options. I recall that GeSHi was seen to be one of the best in terms of functionality, but not the best for performance. |
|
dp.SyntaxHighlighter is another JavaScript option. I haven't look at it in details, but it seems to require specifying the language. |
|
There is a plugin for 1.2 |
|