From IdeA thinKING
Overview
This plugin is a syntax highlighter for source code. It uses GeSHi as fontifier engine. It follows the style of DokuWiki's default one for pre tag.
Requirements
- MediaWiki 1.5 or higher.
- Compatible with all web servers including Apache and IIS.
Download
- Latest version for MediaWiki 1.5 or higher:
Installation
To install the extension:
- Unzip the extension archive to extension directory.
- Add the following line to your LocalSettings.php
- require("extensions/codehighlighter.php");
Usage
- Put the code snippet to code tag.
- Add the lang attribute to the code tag like the following.
- If you want to emphasize some lines, add the em attribute to the code tag.
- <code lang="cpp" em="4,5">
- <code lang="cpp" em="4-10">
- <code lang="cpp" em="4,5,10-13">
- If you do not add lang attribute, the code tag will be handled as a pre tag.
- You can use following languages in lang.
- actionscript, ada, apache, asm, asp, bash, c, c_mac, caddcl, cadlisp, cdfg, cpp, csharp, css, delphi, html4strict, java, javascript, lisp, lua, mpasm, nsis, objc, oobas, oracle8, pascal, perl, php, python, qbasic, sas, smarty, vb, vbnet, visualfoxpro, xml
Screenshots
template <class T>
class MemPool {
public:
static void* operator new(std::size_t size);
static void operator delete(void* p);
...
};
class UserDefined : public MemPool<UserDefined> {
...
};
- <code lang="cpp" em="4,5">
template <class T>
class MemPool {
public:
static void* operator new(std::size_t size);
static void operator delete(void* p);
...
};
class UserDefined : public MemPool<UserDefined> {
...
};
Known issues
- In some case of complex em usage, nested <pre> is created.
- If you want em feature and no nested <pre> bug, uncomment the line 66 of CodeHighlighter.php (or add the following line). But if you do this, your style for pre tag is not applied. Thanks, Mark.
- //$geshi->set_header_type(GESHI_HEADER_DIV);
// no em
struct B
{
virtual ~B() {}
};
struct D : B
{
virtual ~D() {}
};
int main()
{
D* d = new D;
delete d;
delete d;
}
// em="1-3,5-7,10"
struct B
{
virtual ~B() {}
};
struct D : B
{
virtual ~D() {}
};
int main()
{
D* d = new D;
delete d;
delete d;
}
Contact
You may contact me by leaving a comment at my blog.
License
Copyright (C) 2006, 2007 Wongoo Lee
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Version history
- 1.2 Apr 20 2007
- Add the commented DIV option line to be uncommented by user.
- 1.1 Mar 3 2007
- 1.0 May 24 2006
Reference
iwongu 09:08, 20 April 2007 (KST)