Syntax highlighting with Markdown & Pygments in Django

I am trying to get syntax highlighting while working in my simple test Django application (1.1) using Markdown (2.0.1) and Pygments (1.0). The idea is to generate HTML code from user input, which is in markdown format and store both in the database, so I don’t need to markdown to translate html during extraction.

So far I have been working with markdown processing, but I cannot get the syntax highlighting to work. My models.py looks like this:

from django.db import models
from django.contrib import admin
from markdown import markdown

class BlogPost( models.Model ):
    title = models.CharField( max_length = 150 )
    body = models.TextField()
    body_html = models.TextField(editable=False, blank=True, null=True)
    timestamp = models.DateTimeField()

    def save(self):
        self.body_html = markdown(self.body, ['codehilite'])
        super( BlogPost, self).save()

    class Meta:
        ordering = ( '-timestamp', )

class BlogPostAdmin( admin.ModelAdmin ):
    list_display = ( 'title', 'timestamp' )

admin.site.register(BlogPost, BlogPostAdmin)

So far, only markup syntax is being tested, but if I try something like the following, I don't see syntax highlighting in the output or output source:

   :::python
   from foo import bar
   foobar = bar('foo')

I expect to see at least a set of code elements in the source source.

+5
2

! !

, , , , Firefox . Windows, , Mac, d oh!

, , - , .

+3

, , (HTML) . , , .

:

{% load markup %}

.

{{ blog_post.body|markdown}}

css, , .

, .

settings.py INSTALLED_APPS 'django.contrib.markup'

. .

, , , . , . , .

Markdown - , .

JQuery, , , .

+1

All Articles