About :: Projects :: Articles :: JBlog.getInstance()

MT Colorer

Description

MT Colorer is a Movable Type plugin for source code highlighting. It uses colorer and its perl wrapper to do the actual highlighting. Some examples are available on separate page.

Requirements

MT Colorer was only tested with Movable Type 3.2. It may work with other 3.* versions. It is not compatible with older 2.* versions.

Installation

The first step is to install Syntax::Highlight::Universal perl package. Since that package relies on colorer, which is a C++ library, the installation process involves compilation. If you don't feel comfortable with that, you should ask your hosting provider to install the package for you. I will describe the configuration process in a later article. Also you can download precompiled versions for some OSes.

The second step is to install MT Colorer itself:

  1. Download the latest version, unpack it
  2. Copy mtcolorer directory to MT_DIR/plugins.
  3. Attach css/mtcolorer.css to your blog. This could be done, for example, by copying css/mtcolorer.css to you site's root and inserting the following text into the section of each MT template:
    <link rel="stylesheet" type="text/css" media="all" href="/mtcolorer.css" />

Usage

For syntax highlighting you can use one of the following tags

   <mtc:block lang="[source_code_language]">
       [source_code]
   </mtc:block>
or

   <mtc:inline lang="[source_code_language]">[source_code]</mtc:inline>
You should use <mtc:block> for multiline pieces of code, and <mtc:inline> for code embedded in text. Exaples are available here.

List of supported languages: c, cpp, asm, perl, java, idl, pascal, csharp, jsnet, vbnet, forth, fortran, vbasic, html, css, html-css, svg-css, jsp, php, php-body, xhtml-trans, xhtml-strict, xhtml-frameset, asp.vb, asp.js, asp.ps, svg, coldfusion, jScript, actionscript, vbScript, xml, dtd, xslt, xmlschema, relaxng, xlink, clarion, Clipper, foxpro, sqlj, paradox, sql, mysql, Batch, shell, apache, config, hrc, hrd, delphiform, javacc, javaProperties, lex, yacc, makefile, regedit, resources, TeX, dcl, vrml, rarscript, nsi, iss, isScripts, c1c, ada, abap4, AutoIt, awk, dssp, adsp, Baan, cobol, cache, eiffel, icon, lisp, matlab, modula2, picasm, python, rexx, ruby, sml, ocaml, tcltk, sicstusProlog, turboProlog, verilog, vhdl, z80, asm80, filesbbs, diff, messages, text, default

Currently, if defined language is not supported, movable type will throw an error during rebuild process.

Highlighter customization

Customization of highlight styles could be done by editing mtcolorer.css. MT Colorer plugin itself uses two css classes: .mtc_body and .mtc_inline. That class are used for wrap <mtc:block> <mtc:inline> by
<pre class="mtc_block">

[source_code]
</pre>
and
<span class="mtc_inline">[source_code]</span>
Other css classes are using by Syntax::Highlight::Universal package. Unfortunately there is no good documentation for this part, but Syntax::Highlight::Universal distibutions includes several color schemes, and I hope you can choose one.

Feedback

If you find a bug or have some problems using MT Colorer, please, mail me to klimontovich@gmail.com. I'll try to help.

Appendix: precompiled Syntax::Highlight::Universal

Here you can download compiled versions of Syntax::Highlight::Universal for Linux and FreeBSD. I'm not the specialist in binary compatibility, so I can't give any warranty, that this packages will work under various versions of Linux and FreeBSD.

To install, just unpack archives and place its content into MT_DIR/extlib.

  © Vladimir Klimontovich; modified: Thursday, 13-Dec-2007 06:13:57 PST