"""
    MoinMoin - Processor for Syntax Highlighting using the 
    http://colorer.sf.net
    by
    belugin@mail.ru

    based on
    
    MoinMoin - Processor for Syntax Highlighting using the enscript

    Copyright (c) 2002 by Won-Kyu Park <wkpark@kldp.org>
    All rights reserved, see COPYING for details.

    $Id$

    Usage:
    {{{#!colorer sql
       select * from testTable where a='test string'
    }}}
"""
import os,re,string,sys,popen2

def process(request, formatter, lines):
    type=string.strip(lines[0][9:])
    del lines[0]
    buff=string.join(lines, '\n')+'\n'

    options='-dh -h -t%s' % type
    cmd = 'colorer ' + options

    try:
        fromchild, tochild = popen2.popen4(cmd)
        tochild.write(buff)
        tochild.flush()
        tochild.close()
        fromchild.flush()
        html = fromchild.readlines()
    finally:
        fromchild.close()

    html=html[2:-4]
    html='<PRE>'+string.join(html, '')+'</PRE>'

    request.write(formatter.rawHTML(html))
