Am Samstag, 21. Oktober 2006 12:47 schrieb Malcolm Tredinnick: > On Sat, 2006-10-21 at 12:04 +0200, Dirk Eschler wrote: > > Hello, > > > > does anyone use a generic syntax highlighter with Django? I want to > > integrate something like GeSHi [1] in a blog-like application and i try > > to find out where to start. > > > > 1. http://qbnz.com/highlighter/ > > Assuming you already know how to convert source text into marked-up text > from the command line (or a program) using your tool of choice, using it > in Django shouldn't be too hard. The most straightforward way would be > to write a template filter to do the markup. This would be very similar > to the tags in django/contrib/markup/ and you could use it as > > {{ source_code|highlight }} > > (assuming your filter is called "highlight"). This would run the markup > highlighting each time you displayed the page, so for a lot of code or > if the markup process was not particularly quick, performance may be an > issue (needs timing, not guesswork, though). Still, it's a place to > start.
The only Python based highlighter that outputs HTML i've found so far is SilverCity. Unfortunately not so well documentated. Are there any good alternatives? The filter you describe is a nice solution if you know where the highlighted code goes in the template (i might need that as well). But what about dynamic content? Say i have a blog entry, where i want to be able to place code snippets into a textarea from within the admin interface, like in this example: =========================================================== Lorem ipsum dolor sit amet, consectetuer adipiscing elit. <code lang="cpp"> int i = 0; [...] </code> Lorem ipsum dolor sit amet, consectetuer adipiscing elit. <code lang="python"> foo = "bar" [...] </code> =========================================================== I thought to overload the save() method of the particular model. Not really Django related anymore: What would be the best way to parse the entry? I would probably try to use a simple XML parser for this task. Get the lang attribute for each code tag, replace the code tag itself with a valid xhtml tag, and let SilverCity create the inner HTML for the particular language. Does that make any sense? :) Thanks, Dirk -- Dirk Eschler <mailto:[EMAIL PROTECTED]> http://www.krusader.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---