[Moin-devel] Modification to wiki.py

Nicholas Bastin nbastin at mac.com
Mon May 6 22:20:04 EDT 2002


On Monday, May 6, 2002, at 03:29 PM, Juergen Hermann wrote:

> On Sun, 5 May 2002 15:46:29 -0400, Nicholas Bastin wrote:
>
>> I've made modifications to parser/wiki.py to support arbitrary syntax
>> highlighting (any string after "#!" causes the code to attempt an 
>> import
>> of a module of the same name).  For example, now if you added a c.py to
>> MoinMoin/parser, entering the string #!c after {{{ would cause the c
>> parser to be used.  This allows developers to add new colorizers by 
>> just
>> dropping in a new module, and not having to modify core wiki code.
>
> The use of exec makes the patch a security hole. Also, this is already
> possible via 0.12's "processor" semantics, i.e. you can already 
> say "{{{#!
> Colorize C" (though the "C" is not recognized yet, but the means to 
> plugin
> a colorizer is there).
>

Ok, as I said, I don't have 0.12, so didn't see that.  I tried to avoid 
the use of exec via the use of __import__ and getattr, but to no avail.  
__import__ works fine to replicate the generic 'import ... as ...' 
behaviour, but 'from' seems like it isn't emulated correctly, or at 
least I couldn't figure it out.

> A C colorizer would be great, a general one, i.e. one that works on 
> keyword
> tables or something, even better. If "enscript" were available for 
> Windows,
> that would be a nice option.

I use shlex to turn the keywords into tokens, and colorize based upon an 
array of token,color tuples, much like the current python colorizer.  
It's not an optimal solution, but it works.

--
Nick





More information about the Moin-devel mailing list